Unify movies and series list, add TMDb-sourced tags and detail panel
This commit is contained in:
@@ -826,6 +826,47 @@ class FileManager:
|
||||
self.on_files_changed(self.filelist)
|
||||
return file_obj
|
||||
|
||||
def refresh_tags_from_tmdb(
|
||||
self, files: list[File] | None = None,
|
||||
on_progress: Callable[[int, int, File], None] | None = None,
|
||||
should_cancel: Callable[[], bool] | None = None,
|
||||
) -> dict:
|
||||
"""(Re)derive each movie's tags from **TMDb** (by the tmdbid in its name).
|
||||
|
||||
Fetches genres / year / country / rating from TMDb per the tag schema and
|
||||
regenerates the auto tags (`File.apply_nfo`, which is source-agnostic);
|
||||
user-added tags are kept. Movies with no tmdbid in the filename are skipped.
|
||||
|
||||
Returns ``{ok, updated, without_id, errors}``.
|
||||
"""
|
||||
from . import tmdb
|
||||
if not tmdb.api_available():
|
||||
return {"ok": False, "error": "TMDB_API_KEY není nastaven (.env).",
|
||||
"updated": 0, "without_id": 0, "errors": []}
|
||||
targets = files if files is not None else self.filelist
|
||||
schema = self.tag_schema
|
||||
updated, without_id = 0, 0
|
||||
errors: list[str] = []
|
||||
total = len(targets)
|
||||
for i, f in enumerate(targets, 1):
|
||||
if should_cancel is not None and should_cancel():
|
||||
break
|
||||
tmdb_id = parse_tmdb_id(f.file_path.stem)
|
||||
if tmdb_id is None:
|
||||
without_id += 1
|
||||
else:
|
||||
try:
|
||||
f.apply_nfo(tmdb.movie_details(tmdb_id), schema)
|
||||
updated += 1
|
||||
except tmdb.TmdbError as exc:
|
||||
errors.append(f"{f.filename}: {exc}")
|
||||
if on_progress is not None:
|
||||
on_progress(i, total, f)
|
||||
if updated and self.on_files_changed:
|
||||
self.on_files_changed(self.filelist)
|
||||
return {"ok": True, "updated": updated, "without_id": without_id,
|
||||
"errors": errors}
|
||||
|
||||
def match_pool_to_tmdb(
|
||||
self, files: list[File] | None = None,
|
||||
on_progress: Callable[[int, int, File], None] | None = None,
|
||||
|
||||
Reference in New Issue
Block a user