diff --git a/VERSION b/VERSION index d3961c9..3243298 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.9.2-imdb-key-fix +2.9.3-movie-titles-files diff --git a/clients/radarr_db_client.py b/clients/radarr_db_client.py index 4815140..5048406 100644 --- a/clients/radarr_db_client.py +++ b/clients/radarr_db_client.py @@ -167,7 +167,7 @@ class RadarrDbClient: def get_all_movies(self) -> List[Dict[str, Any]]: """ - Get all movies from Radarr database + Get all movies from Radarr database (only movies with files) Returns: List of dictionaries with movie info @@ -182,9 +182,11 @@ class RadarrDbClient: mm."Year" as year, mm."DigitalRelease" as digital_release, mm."PhysicalRelease" as physical_release, - mm."InCinemas" as in_cinemas + mm."InCinemas" as in_cinemas, + (SELECT COUNT(*) FROM "MovieFiles" mf WHERE mf."MovieId" = m."Id") as file_count FROM "Movies" m JOIN "MovieMetadata" mm ON m."MovieMetadataId" = mm."Id" + WHERE (SELECT COUNT(*) FROM "MovieFiles" mf WHERE mf."MovieId" = m."Id") > 0 ORDER BY mm."Title" """ diff --git a/core/database.py b/core/database.py index 932f06b..a7efb8d 100644 --- a/core/database.py +++ b/core/database.py @@ -108,6 +108,8 @@ class NFOGuardDatabase: cursor.execute(""" CREATE TABLE IF NOT EXISTS movies ( imdb_id VARCHAR(20) PRIMARY KEY, + title TEXT, + year INTEGER, path TEXT NOT NULL, released DATE, dateadded TIMESTAMP, @@ -116,6 +118,21 @@ class NFOGuardDatabase: has_video_file BOOLEAN DEFAULT FALSE ) """) + + # Add title and year columns if they don't exist (migration for existing databases) + cursor.execute(""" + DO $$ + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.columns + WHERE table_name='movies' AND column_name='title') THEN + ALTER TABLE movies ADD COLUMN title TEXT; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.columns + WHERE table_name='movies' AND column_name='year') THEN + ALTER TABLE movies ADD COLUMN year INTEGER; + END IF; + END $$; + """) # Processing history table cursor.execute(""" @@ -254,26 +271,29 @@ class NFOGuardDatabase: last_updated = EXCLUDED.last_updated """, (imdb_id, path, timestamp)) - def upsert_movie_dates(self, imdb_id: str, released: Optional[str], - dateadded: Optional[str], source: str, has_video_file: bool = False): + def upsert_movie_dates(self, imdb_id: str, released: Optional[str], + dateadded: Optional[str], source: str, has_video_file: bool = False, + title: Optional[str] = None, year: Optional[int] = None): """Insert or update movie date record""" import os if os.environ.get("DEBUG", "false").lower() == "true": - print(f"🔍 DATABASE UPSERT: imdb_id={imdb_id}, dateadded={dateadded}, source={source}") + print(f"🔍 DATABASE UPSERT: imdb_id={imdb_id}, title={title}, dateadded={dateadded}, source={source}") with self.get_connection() as conn: cursor = conn.cursor() timestamp = datetime.utcnow() - + cursor.execute(""" - INSERT INTO movies (imdb_id, path, released, dateadded, source, has_video_file, last_updated) - VALUES (%s, COALESCE((SELECT path FROM movies WHERE imdb_id = %s), 'unknown'), %s, %s, %s, %s, %s) + INSERT INTO movies (imdb_id, title, year, path, released, dateadded, source, has_video_file, last_updated) + VALUES (%s, %s, %s, COALESCE((SELECT path FROM movies WHERE imdb_id = %s), 'unknown'), %s, %s, %s, %s, %s) ON CONFLICT (imdb_id) DO UPDATE SET + title = EXCLUDED.title, + year = EXCLUDED.year, released = EXCLUDED.released, dateadded = EXCLUDED.dateadded, source = EXCLUDED.source, has_video_file = EXCLUDED.has_video_file, last_updated = EXCLUDED.last_updated - """, (imdb_id, imdb_id, released, dateadded, source, has_video_file, timestamp)) + """, (imdb_id, title, year, imdb_id, released, dateadded, source, has_video_file, timestamp)) # Debug: Check what was actually saved cursor.execute("SELECT dateadded, source FROM movies WHERE imdb_id = %s", (imdb_id,)) diff --git a/core/database_populator.py b/core/database_populator.py index b2eec48..e270aaa 100644 --- a/core/database_populator.py +++ b/core/database_populator.py @@ -131,10 +131,15 @@ class DatabasePopulator: stats['skipped'] += 1 continue - # Insert into database - self.db.upsert_movie_dates(imdb_id, released, dateadded, source, has_video_file=True) + # Insert into database with title and year + title = movie.get('title') + year = movie.get('year') + self.db.upsert_movie_dates( + imdb_id, released, dateadded, source, + has_video_file=True, title=title, year=year + ) stats['added'] += 1 - _log("DEBUG", f"Added movie {imdb_id}: {movie.get('title')} (source: {source})") + _log("DEBUG", f"Added movie {imdb_id}: {title} ({year}) (source: {source})") except Exception as e: _log("ERROR", f"Error processing movie {movie.get('title', 'unknown')}: {e}")