refactor enrichment to tmdb-only and fix review findings

This commit is contained in:
windyboy
2026-02-10 08:29:31 +08:00
parent 53aaeeaedf
commit f0c951ad7f
8 changed files with 187 additions and 127 deletions
+21 -16
View File
@@ -12,7 +12,7 @@ from urllib.request import urlopen, Request
from vlm.cache import EnrichmentCache
from vlm.config import Config
from vlm.providers import ProviderResult, TMDBProvider, DoubanProvider
from vlm.providers import ProviderResult, TMDBProvider
from vlm.parser import normalize_title
RefreshMode = str
@@ -156,6 +156,7 @@ def _emit_progress(stats: dict[str, int | list[dict[str, str]]], progress_callba
def _build_providers(config: Config, *, request_timeout: int, retries: int) -> list:
providers = []
unsupported: list[str] = []
for name in config.enrichment_providers:
key = name.lower()
if key == "tmdb":
@@ -167,16 +168,14 @@ def _build_providers(config: Config, *, request_timeout: int, retries: int) -> l
min_interval_seconds=0.25,
)
)
elif key == "douban":
providers.append(
DoubanProvider(
config.douban_api_key,
endpoint=config.douban_api_endpoint,
timeout_seconds=request_timeout,
retries=retries,
min_interval_seconds=0.4,
)
)
else:
unsupported.append(name)
if unsupported:
raise ValueError(
f"Unsupported enrichment providers: {unsupported}. Supported providers: ['tmdb']"
)
return providers
@@ -390,7 +389,7 @@ def _apply_payload(record: dict, payload: dict) -> None:
"provider_metadata",
"display_title",
):
if key in payload and payload[key] is not None:
if key in payload:
record[key] = payload[key]
if "needs_review" in payload:
@@ -422,10 +421,16 @@ def _fallback_title_from_filename(filename: Optional[str]) -> Optional[str]:
def _build_display_title(record: dict, payload: dict, config: Config) -> str:
title_zh = payload.get("title_zh") or record.get("title")
title_en = payload.get("title_en") or record.get("title")
fallback_title = record.get("title")
title_zh = payload.get("title_zh") or fallback_title
title_en = payload.get("title_en") or fallback_title
if title_zh and title_en and title_zh == title_en:
title_en = ""
try:
formatted = config.naming_title_format.format(title_zh=title_zh, title_en=title_en).strip()
formatted = config.naming_title_format.format(
title_zh=title_zh or "",
title_en=title_en or "",
).strip()
except Exception:
formatted = f"{title_zh} {title_en}".strip()
formatted = f"{title_zh or ''} {title_en or ''}".strip()
return " ".join(formatted.split())