refactor: try sub and dub modes in allanime resolution, drop fallback
This commit is contained in:
@@ -221,7 +221,13 @@ func (c *AllAnimeProvider) GetEpisodeAvailability(ctx context.Context, animeID i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *AllAnimeProvider) ResolveEpisodeProviderID(ctx context.Context, animeID int, titleCandidates []string) (string, error) {
|
func (c *AllAnimeProvider) ResolveEpisodeProviderID(ctx context.Context, animeID int, titleCandidates []string) (string, error) {
|
||||||
return c.resolveShowIDStrict(ctx, animeID, titleCandidates, "sub")
|
for _, mode := range []string{"sub", "dub"} {
|
||||||
|
showID, err := c.resolveShowIDStrict(ctx, animeID, titleCandidates, mode)
|
||||||
|
if err == nil {
|
||||||
|
return showID, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("allanime: no exact mal id match for %d", animeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AllAnimeProvider) GetEpisodeAvailabilityByProviderID(ctx context.Context, showID string) (domain.EpisodeAvailability, error) {
|
func (c *AllAnimeProvider) GetEpisodeAvailabilityByProviderID(ctx context.Context, showID string) (domain.EpisodeAvailability, error) {
|
||||||
@@ -237,7 +243,6 @@ func (c *AllAnimeProvider) GetEpisodeAvailabilityByProviderID(ctx context.Contex
|
|||||||
|
|
||||||
func (c *AllAnimeProvider) resolveShowIDStrict(ctx context.Context, animeID int, titleCandidates []string, mode string) (string, error) {
|
func (c *AllAnimeProvider) resolveShowIDStrict(ctx context.Context, animeID int, titleCandidates []string, mode string) (string, error) {
|
||||||
targetMalIDStr := strconv.Itoa(animeID)
|
targetMalIDStr := strconv.Itoa(animeID)
|
||||||
var firstAvailableShowID string
|
|
||||||
for _, title := range titleCandidates {
|
for _, title := range titleCandidates {
|
||||||
searchResults, err := c.Search(ctx, title, mode)
|
searchResults, err := c.Search(ctx, title, mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -247,15 +252,9 @@ func (c *AllAnimeProvider) resolveShowIDStrict(ctx context.Context, animeID int,
|
|||||||
if res.MalID == targetMalIDStr {
|
if res.MalID == targetMalIDStr {
|
||||||
return res.ID, nil
|
return res.ID, nil
|
||||||
}
|
}
|
||||||
if firstAvailableShowID == "" {
|
|
||||||
firstAvailableShowID = res.ID
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if firstAvailableShowID != "" {
|
return "", fmt.Errorf("allanime: no exact mal id match for %d in %s search", animeID, mode)
|
||||||
return firstAvailableShowID, nil
|
|
||||||
}
|
|
||||||
return "", fmt.Errorf("allanime: no strict mal id match for %d", animeID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEpisodeNumbers(raw []string) []int {
|
func parseEpisodeNumbers(raw []string) []int {
|
||||||
|
|||||||
Reference in New Issue
Block a user