diff --git a/VERSION b/VERSION index 619f92e..fc5237e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.8.4-populate-fix4 +2.8.6-sql-fix diff --git a/api/web_routes.py b/api/web_routes.py index 10f9457..8c55fa8 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -199,10 +199,13 @@ async def get_tv_series_list(dependencies: dict, where_clause = " AND ".join(where_conditions) if where_conditions else "1=1" having_clause = " AND ".join(having_conditions) if having_conditions else "" - + + # Check if where_clause references episodes table (e.source, e.dateadded, etc.) + needs_episode_join = any(cond.startswith("e.") for cond in where_conditions) + # Get total count with same filtering logic as main query - if having_clause: - # When using HAVING clause, need to count filtered results + if having_clause or needs_episode_join: + # When using HAVING clause or filtering by episode fields, need to count filtered results with JOIN count_query = f""" SELECT COUNT(*) FROM ( SELECT s.imdb_id @@ -210,12 +213,12 @@ async def get_tv_series_list(dependencies: dict, LEFT JOIN episodes e ON s.imdb_id = e.imdb_id WHERE {where_clause} GROUP BY s.imdb_id - HAVING {having_clause} + {('HAVING ' + having_clause) if having_clause else ''} ) filtered_series """ cursor.execute(count_query, params) else: - # Simple count when no HAVING clause + # Simple count when no HAVING clause and no episode filtering count_query = f"SELECT COUNT(*) FROM series s WHERE {where_clause}" cursor.execute(count_query, params) total_count = db._get_first_value(cursor.fetchone()) diff --git a/clients/radarr_db_client.py b/clients/radarr_db_client.py index bf32419..4815140 100644 --- a/clients/radarr_db_client.py +++ b/clients/radarr_db_client.py @@ -164,7 +164,52 @@ class RadarrDbClient: _log("ERROR", f"Database query error for IMDb {imdb_id}: {e}") return None - + + def get_all_movies(self) -> List[Dict[str, Any]]: + """ + Get all movies from Radarr database + + Returns: + List of dictionaries with movie info + """ + query = """ + SELECT + m."Id" as id, + m."Path" as path, + m."Added" as added, + mm."ImdbId" as imdb_id, + mm."Title" as title, + mm."Year" as year, + mm."DigitalRelease" as digital_release, + mm."PhysicalRelease" as physical_release, + mm."InCinemas" as in_cinemas + FROM "Movies" m + JOIN "MovieMetadata" mm ON m."MovieMetadataId" = mm."Id" + ORDER BY mm."Title" + """ + + if self.db_type == "sqlite": + # SQLite uses ? placeholders but this query has none + pass + + try: + with self._get_connection() as conn: + if self.db_type == "postgresql": + cursor = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + else: + cursor = conn.cursor() + + cursor.execute(query) + rows = cursor.fetchall() + + if rows: + return [dict(row) if self.db_type == "sqlite" else row for row in rows] + return [] + + except Exception as e: + _log("ERROR", f"Database query error getting all movies: {e}") + return [] + def get_earliest_import_date(self, movie_id: int) -> Tuple[Optional[str], str]: """ Get earliest import date from History table, accounting for upgrade scenarios diff --git a/core/database_populator.py b/core/database_populator.py index a053d8b..4ccad35 100644 --- a/core/database_populator.py +++ b/core/database_populator.py @@ -49,10 +49,15 @@ class DatabasePopulator: } try: - # Get all movies from Radarr - movies = self.radarr.get_all_movies() + # Get all movies from Radarr database + if not hasattr(self.radarr, 'db_client') or not self.radarr.db_client: + _log("ERROR", "Radarr database client not available - cannot populate movies") + stats['errors'] += 1 + return stats + + movies = self.radarr.db_client.get_all_movies() if not movies: - _log("WARNING", "No movies found in Radarr") + _log("WARNING", "No movies found in Radarr database") return stats stats['total'] = len(movies) diff --git a/nfoguard-web/main_web.py b/nfoguard-web/main_web.py index 820c811..02af1fc 100644 --- a/nfoguard-web/main_web.py +++ b/nfoguard-web/main_web.py @@ -33,7 +33,7 @@ def create_web_app() -> FastAPI: app = FastAPI( title="NFOGuard Web Interface", description="Web interface for NFOGuard media database management", - version="2.8.1-populate-fix", + version="2.8.6-sql-fix", docs_url="/docs" if web_config.web_debug else None, redoc_url="/redoc" if web_config.web_debug else None ) diff --git a/start_web.py b/start_web.py index 21ad9f0..47ff620 100644 --- a/start_web.py +++ b/start_web.py @@ -29,7 +29,7 @@ def create_web_app() -> FastAPI: app = FastAPI( title="NFOGuard Web Interface", description="Web interface for NFOGuard media database management", - version="2.8.3-populate-fix3", + version="2.8.6-sql-fix", docs_url=None, # Disable docs in production redoc_url=None ) @@ -94,7 +94,7 @@ def setup_static_files(app: FastAPI) -> None: "status": "healthy", "service": "nfoguard-web", "timestamp": time.time(), - "version": "2.8.3-populate-fix3" + "version": "2.8.6-sql-fix" } except Exception as e: from fastapi import HTTPException