👌 Make finding best_match_title more robust

This commit is contained in:
s-weigand
2025-08-17 12:34:25 +02:00
parent ed81f37ae4
commit cc69dc35f6
4 changed files with 46 additions and 23 deletions

View File

@@ -6,7 +6,7 @@ from ...state import InternalDirective, State
@session.menu
def download_episodes(ctx: Context, state: State) -> State | InternalDirective:
"""Menu to select and download episodes synchronously."""
from .....core.utils.fuzzy import fuzz
from viu_cli.cli.utils.search import find_best_match_title
from .....core.utils.normalizer import normalize_title
from ....service.download.service import DownloadService
@@ -40,12 +40,8 @@ def download_episodes(ctx: Context, state: State) -> State | InternalDirective:
return InternalDirective.BACK
provider_results_map = {res.title: res for res in provider_search_results.results}
best_match_title = max(
provider_results_map.keys(),
key=lambda p_title: fuzz.ratio(
normalize_title(p_title, config.general.provider.value).lower(),
media_title.lower(),
),
best_match_title = find_best_match_title(
provider_results_map, config.general.provider, media_item
)
selected_provider_anime_ref = provider_results_map[best_match_title]

View File

@@ -6,7 +6,7 @@ from ...state import InternalDirective, MenuName, ProviderState, State
@session.menu
def provider_search(ctx: Context, state: State) -> State | InternalDirective:
from .....core.utils.fuzzy import fuzz
from viu_cli.cli.utils.search import find_best_match_title
from .....core.utils.normalizer import normalize_title, update_user_normalizer_json
feedback = ctx.feedback
@@ -51,12 +51,8 @@ def provider_search(ctx: Context, state: State) -> State | InternalDirective:
# --- Auto-Select or Prompt ---
if config.general.auto_select_anime_result:
# Use fuzzy matching to find the best title
best_match_title = max(
provider_results_map.keys(),
key=lambda p_title: fuzz.ratio(
normalize_title(p_title, config.general.provider.value).lower(),
media_title.lower(),
),
best_match_title = find_best_match_title(
provider_results_map, config.general.provider, media_item
)
feedback.info(f"Auto-selecting best match: {best_match_title}")
selected_provider_anime = provider_results_map[best_match_title]