Improve library identification and track inspection
This commit is contained in:
@@ -266,7 +266,28 @@ def build_collections(config: dict, items: list[dict], enrich: bool = False) ->
|
||||
}
|
||||
|
||||
|
||||
def library_snapshot(config: dict) -> dict:
|
||||
def preserve_metadata(collections: dict, previous_library: dict | None) -> dict:
|
||||
previous = (previous_library or {}).get("collections") or {}
|
||||
previous_by_key = {
|
||||
item.get("key"): item
|
||||
for group in ("movies", "series")
|
||||
for item in previous.get(group, [])
|
||||
if item.get("key")
|
||||
}
|
||||
for group in ("movies", "series"):
|
||||
for item in collections.get(group, []):
|
||||
old = previous_by_key.get(item.get("key"))
|
||||
old_meta = (old or {}).get("metadata") or {}
|
||||
if old_meta.get("source") == "tmdb":
|
||||
item["metadata"] = old_meta
|
||||
if old_meta.get("manual"):
|
||||
item["title"] = old_meta.get("title") or item.get("title")
|
||||
if item.get("library") == "movie" and old_meta.get("release_date"):
|
||||
item["year"] = int(old_meta["release_date"][:4])
|
||||
return collections
|
||||
|
||||
|
||||
def library_snapshot(config: dict, previous_library: dict | None = None) -> dict:
|
||||
items = []
|
||||
extensions = Counter()
|
||||
ignored_dirs = {"$RECYCLE.BIN", "System Volume Information", ".Trash-1000"}
|
||||
@@ -320,12 +341,27 @@ def library_snapshot(config: dict) -> dict:
|
||||
})
|
||||
enrich_limit = int(app.get("library_metadata_enrich_max_items", 500))
|
||||
should_enrich = bool(config.get("metadata", {}).get("tmdb_enabled", True)) and len(items) <= enrich_limit
|
||||
collections = build_collections(config, items, enrich=should_enrich)
|
||||
if not should_enrich:
|
||||
collections = preserve_metadata(collections, previous_library)
|
||||
return normalize_library({
|
||||
"drives": drive_stats(config),
|
||||
"items": sorted(items, key=lambda item: item["modified"], reverse=True),
|
||||
"collections": build_collections(config, items, enrich=should_enrich),
|
||||
"collections": collections,
|
||||
"extensions": dict(extensions.most_common()),
|
||||
"scanned_files": scanned,
|
||||
"truncated": truncated,
|
||||
"metadata_enriched": should_enrich,
|
||||
"identifications": (previous_library or {}).get("identifications", {}),
|
||||
})
|
||||
|
||||
|
||||
def enrich_library_metadata(config: dict, library: dict) -> dict:
|
||||
items = library.get("items") or []
|
||||
enriched = {
|
||||
**library,
|
||||
"collections": build_collections(config, items, enrich=True),
|
||||
"metadata_enriched": True,
|
||||
"metadata_refreshed_at": time.time(),
|
||||
}
|
||||
return normalize_library(enriched)
|
||||
|
||||
Reference in New Issue
Block a user