diff --git a/core/video/enrichment/clients.py b/core/video/enrichment/clients.py index 2500d7f0..31e94bdd 100644 --- a/core/video/enrichment/clients.py +++ b/core/video/enrichment/clients.py @@ -97,6 +97,12 @@ class TMDBClient: if kind == "movie": meta["release_date"] = dr.get("release_date") meta["runtime_minutes"] = dr.get("runtime") + # Franchise/collection (belongs_to_collection is a standard movie-detail + # field) — persisted so "complete your collections" gaps can diff it (#discover). + bc = dr.get("belongs_to_collection") + if bc and bc.get("id"): + meta["tmdb_collection_id"] = bc.get("id") + meta["tmdb_collection_name"] = bc.get("name") else: meta["first_air_date"] = dr.get("first_air_date") meta["last_air_date"] = dr.get("last_air_date") @@ -837,7 +843,7 @@ class OMDBClient: err = "" try: err = ((r.json() or {}).get("Error") or "").strip() - except Exception: + except Exception: # noqa: S110 - best-effort error-body parse; we raise OMDbAuthError below regardless pass raise OMDbAuthError(err or "OMDb rejected the API key (HTTP 401)") r.raise_for_status() diff --git a/database/video_database.py b/database/video_database.py index faf31b5a..fca65da1 100644 --- a/database/video_database.py +++ b/database/video_database.py @@ -31,7 +31,7 @@ logger = get_logger("video_database") # Bump when video_schema.sql changes in a way worth recording. Stored in # PRAGMA user_version as a backstop indicator (nothing gates on it yet). -SCHEMA_VERSION = 17 +SCHEMA_VERSION = 18 _DEFAULT_DB_PATH = "database/video_library.db" _SCHEMA_FILE = Path(__file__).resolve().parent / "video_schema.sql" @@ -66,6 +66,7 @@ _ENRICH = { _ENRICH_META_COLS = { "movies": {"overview", "backdrop_url", "logo_url", "release_date", "status", "content_rating", "runtime_minutes", "studio", "tagline", "rating", "rating_critic", + "tmdb_collection_id", "tmdb_collection_name", "imdb_id", "tmdb_id"}, "shows": {"overview", "backdrop_url", "logo_url", "status", "network", "content_rating", "tagline", "rating", "first_air_date", "last_air_date", "airs_time", @@ -139,6 +140,8 @@ _COLUMN_MIGRATIONS = [ ("movies", "tagline", "TEXT"), ("movies", "rating", "REAL"), ("movies", "rating_critic", "REAL"), + ("movies", "tmdb_collection_id", "INTEGER"), + ("movies", "tmdb_collection_name", "TEXT"), ("shows", "tagline", "TEXT"), ("shows", "rating", "REAL"), ("shows", "first_air_date", "TEXT"), diff --git a/database/video_schema.sql b/database/video_schema.sql index 328413a5..ef6c9c03 100644 --- a/database/video_schema.sql +++ b/database/video_schema.sql @@ -78,6 +78,8 @@ CREATE TABLE IF NOT EXISTS movies ( studio TEXT, content_rating TEXT, -- e.g. PG-13 tagline TEXT, + tmdb_collection_id INTEGER, -- TMDB belongs_to_collection id (franchise); for "complete your collections" gaps + tmdb_collection_name TEXT, -- collection display name (e.g. "The Matrix Collection") rating REAL, -- TMDB audience score (0-10) rating_critic REAL, -- critic score (0-100) when offered imdb_rating REAL, -- IMDb (0-10, via OMDb) @@ -96,6 +98,7 @@ CREATE TABLE IF NOT EXISTS movies ( updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_movies_tmdb ON movies(tmdb_id); +CREATE INDEX IF NOT EXISTS idx_movies_collection ON movies(tmdb_collection_id); CREATE INDEX IF NOT EXISTS idx_movies_monitored ON movies(monitored, has_file); CREATE INDEX IF NOT EXISTS idx_movies_release ON movies(release_date); -- Upsert/stale-removal key: the server's native id. Multiple NULLs are allowed