mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-05-17 06:09:29 +00:00
fix(tags): prevent metadata lookup failures from skipping group tag
Wrapped metadata provider lookup in try/except so custom tags (Group) are always applied even when IMDB/TMDB lookups fail. Also log mkvpropedit errors instead of silently discarding them.
This commit is contained in:
@@ -33,13 +33,16 @@ def apply_tags(path: Path, tags: dict[str, str]) -> None:
|
|||||||
f.write("\n".join(xml_lines))
|
f.write("\n".join(xml_lines))
|
||||||
tmp_path = Path(f.name)
|
tmp_path = Path(f.name)
|
||||||
try:
|
try:
|
||||||
subprocess.run(
|
result = subprocess.run(
|
||||||
[str(binaries.Mkvpropedit), str(path), "--tags", f"global:{tmp_path}"],
|
[str(binaries.Mkvpropedit), str(path), "--tags", f"global:{tmp_path}"],
|
||||||
check=False,
|
check=False,
|
||||||
stdout=subprocess.DEVNULL,
|
capture_output=True,
|
||||||
stderr=subprocess.DEVNULL,
|
text=True,
|
||||||
)
|
)
|
||||||
log.debug("Tags applied via mkvpropedit")
|
if result.returncode != 0:
|
||||||
|
log.warning("mkvpropedit failed (exit %d): %s", result.returncode, result.stderr.strip())
|
||||||
|
else:
|
||||||
|
log.debug("Tags applied via mkvpropedit")
|
||||||
finally:
|
finally:
|
||||||
tmp_path.unlink(missing_ok=True)
|
tmp_path.unlink(missing_ok=True)
|
||||||
|
|
||||||
@@ -92,43 +95,46 @@ def tag_file(
|
|||||||
standard_tags: dict[str, str] = {}
|
standard_tags: dict[str, str] = {}
|
||||||
|
|
||||||
if config.tag_imdb_tmdb:
|
if config.tag_imdb_tmdb:
|
||||||
providers = get_available_providers()
|
try:
|
||||||
if not providers:
|
providers = get_available_providers()
|
||||||
log.debug("No metadata providers available; skipping tag lookup")
|
if not providers:
|
||||||
apply_tags(path, custom_tags)
|
log.debug("No metadata providers available; skipping tag lookup")
|
||||||
return
|
apply_tags(path, custom_tags)
|
||||||
|
return
|
||||||
|
|
||||||
result: Optional[MetadataResult] = None
|
result: Optional[MetadataResult] = None
|
||||||
|
|
||||||
# Direct ID lookup path
|
# Direct ID lookup path
|
||||||
if imdb_id:
|
if imdb_id:
|
||||||
imdbapi = get_provider("imdbapi")
|
imdbapi = get_provider("imdbapi")
|
||||||
if imdbapi:
|
if imdbapi:
|
||||||
result = imdbapi.get_by_id(imdb_id, kind)
|
result = imdbapi.get_by_id(imdb_id, kind)
|
||||||
if result:
|
if result:
|
||||||
result.external_ids.imdb_id = imdb_id
|
result.external_ids.imdb_id = imdb_id
|
||||||
enrich_ids(result)
|
enrich_ids(result)
|
||||||
elif tmdb_id is not None:
|
elif tmdb_id is not None:
|
||||||
tmdb = get_provider("tmdb")
|
tmdb = get_provider("tmdb")
|
||||||
if tmdb:
|
if tmdb:
|
||||||
result = tmdb.get_by_id(tmdb_id, kind)
|
result = tmdb.get_by_id(tmdb_id, kind)
|
||||||
if result:
|
if result:
|
||||||
ext = tmdb.get_external_ids(tmdb_id, kind)
|
ext = tmdb.get_external_ids(tmdb_id, kind)
|
||||||
result.external_ids = ext
|
result.external_ids = ext
|
||||||
else:
|
else:
|
||||||
# Search across providers in priority order
|
# Search across providers in priority order
|
||||||
result = search_metadata(name, year, kind)
|
result = search_metadata(name, year, kind)
|
||||||
|
|
||||||
# If we got a TMDB ID from search but no full external IDs, fetch them
|
# If we got a TMDB ID from search but no full external IDs, fetch them
|
||||||
if result and result.external_ids.tmdb_id and not result.external_ids.imdb_id:
|
if result and result.external_ids.tmdb_id and not result.external_ids.imdb_id:
|
||||||
ext = fetch_external_ids(result.external_ids.tmdb_id, kind)
|
ext = fetch_external_ids(result.external_ids.tmdb_id, kind)
|
||||||
if ext.imdb_id:
|
if ext.imdb_id:
|
||||||
result.external_ids.imdb_id = ext.imdb_id
|
result.external_ids.imdb_id = ext.imdb_id
|
||||||
if ext.tvdb_id:
|
if ext.tvdb_id:
|
||||||
result.external_ids.tvdb_id = ext.tvdb_id
|
result.external_ids.tvdb_id = ext.tvdb_id
|
||||||
|
|
||||||
if result and result.external_ids:
|
if result and result.external_ids:
|
||||||
standard_tags = _build_tags_from_ids(result.external_ids, kind)
|
standard_tags = _build_tags_from_ids(result.external_ids, kind)
|
||||||
|
except Exception as e:
|
||||||
|
log.warning("Metadata lookup failed, applying custom tags only: %s", e)
|
||||||
|
|
||||||
apply_tags(path, {**custom_tags, **standard_tags})
|
apply_tags(path, {**custom_tags, **standard_tags})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user