mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 19:05:13 +00:00
feat(metadata)!: authoritative id resolver and keyless imdb provider
Supplied IDs resolve directly via a shared resolve_by_ids and never fall back to title search; metadata_providers gains per-kind ordering and a disable_metadata switch stops all automatic lookups while explicit IDs keep working. BREAKING: --tmdb/--imdb/--tvdb are now mutually exclusive and require a usable provider; --enrich also overwrites original language; the imdbapi provider and imdb_api_enabled are replaced by a keyless imdb provider.
This commit is contained in:
@@ -12,13 +12,9 @@ from unshackle.core import binaries
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.providers import (
|
||||
ExternalIds,
|
||||
MetadataResult,
|
||||
enrich_ids,
|
||||
fetch_external_ids,
|
||||
fuzzy_match,
|
||||
get_available_providers,
|
||||
get_provider,
|
||||
search_metadata,
|
||||
resolve_by_ids,
|
||||
)
|
||||
from unshackle.core.titles.episode import Episode
|
||||
from unshackle.core.titles.movie import Movie
|
||||
@@ -118,53 +114,13 @@ def tag_file(
|
||||
|
||||
if config.tag_imdb_tmdb:
|
||||
try:
|
||||
providers = get_available_providers()
|
||||
if not providers and tvdb_id is None:
|
||||
has_ids = tmdb_id is not None or imdb_id is not None or tvdb_id is not None
|
||||
if not get_available_providers() and not has_ids:
|
||||
log.debug("No metadata providers available; skipping tag lookup")
|
||||
apply_tags(path, custom_tags)
|
||||
return
|
||||
|
||||
result: Optional[MetadataResult] = None
|
||||
|
||||
# Direct ID lookup path
|
||||
if imdb_id:
|
||||
imdbapi = get_provider("imdbapi")
|
||||
if imdbapi:
|
||||
result = imdbapi.get_by_id(imdb_id, kind)
|
||||
if not result:
|
||||
# IMDxAPI is off or had no answer; the ID alone still resolves the others
|
||||
result = MetadataResult(title=name, year=year, kind=kind)
|
||||
result.external_ids.imdb_id = imdb_id
|
||||
enrich_ids(result)
|
||||
elif tmdb_id is not None:
|
||||
tmdb = get_provider("tmdb")
|
||||
if tmdb:
|
||||
result = tmdb.get_by_id(tmdb_id, kind)
|
||||
if result:
|
||||
ext = tmdb.get_external_ids(tmdb_id, kind)
|
||||
result.external_ids = ext
|
||||
enrich_ids(result)
|
||||
else:
|
||||
# Search across providers in priority order
|
||||
result = search_metadata(name, year, kind)
|
||||
|
||||
# If we got a TMDB ID from search but not the other IDs, fetch them
|
||||
if (
|
||||
result
|
||||
and result.external_ids.tmdb_id
|
||||
and not (result.external_ids.imdb_id and result.external_ids.tvdb_id)
|
||||
):
|
||||
ext = fetch_external_ids(result.external_ids.tmdb_id, kind)
|
||||
if ext.imdb_id and not result.external_ids.imdb_id:
|
||||
result.external_ids.imdb_id = ext.imdb_id
|
||||
if ext.tvdb_id and not result.external_ids.tvdb_id:
|
||||
result.external_ids.tvdb_id = ext.tvdb_id
|
||||
enrich_ids(result)
|
||||
|
||||
if tvdb_id is not None:
|
||||
if result is None:
|
||||
result = MetadataResult(kind=kind)
|
||||
result.external_ids.tvdb_id = tvdb_id
|
||||
result = resolve_by_ids(tmdb_id, imdb_id, tvdb_id, title=name, year=year, kind=kind)
|
||||
|
||||
if result and result.external_ids:
|
||||
standard_tags = _build_tags_from_ids(result.external_ids, kind)
|
||||
|
||||
Reference in New Issue
Block a user