diff --git a/VERSION b/VERSION index e75da3e..00355e2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.6 +2.3.7 diff --git a/api/web_routes.py b/api/web_routes.py index d622473..a81000f 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -55,7 +55,7 @@ async def get_movies_list(dependencies: dict, # Get total count count_query = f"SELECT COUNT(*) FROM movies WHERE {where_clause}" cursor.execute(count_query, params) - total_count = cursor.fetchone()[0] + total_count = db._get_first_value(cursor.fetchone()) # Get paginated results query = f""" @@ -150,7 +150,7 @@ async def get_tv_series_list(dependencies: dict, # Simple count when no HAVING clause count_query = f"SELECT COUNT(*) FROM series s WHERE {where_clause}" cursor.execute(count_query, params) - total_count = cursor.fetchone()[0] + total_count = db._get_first_value(cursor.fetchone()) # Get series with episode statistics having_part = f" HAVING {having_clause}" if having_clause else "" @@ -313,13 +313,21 @@ async def get_missing_dates_report(dependencies: dict): with db.get_connection() as conn: cursor = conn.cursor() - # Movies without dates - cursor.execute(""" - SELECT imdb_id, path, released, source, last_updated - FROM movies - WHERE dateadded IS NULL OR dateadded = '' OR source = 'no_valid_date_source' - ORDER BY last_updated DESC - """) + # Movies without dates - PostgreSQL compatible + if db.db_type == "postgresql": + cursor.execute(""" + SELECT imdb_id, path, released, source, last_updated + FROM movies + WHERE dateadded IS NULL OR source = 'no_valid_date_source' + ORDER BY last_updated DESC + """) + else: + cursor.execute(""" + SELECT imdb_id, path, released, source, last_updated + FROM movies + WHERE dateadded IS NULL OR dateadded = '' OR source = 'no_valid_date_source' + ORDER BY last_updated DESC + """) movies_missing = [] for row in cursor.fetchall(): movie = dict(row) @@ -329,14 +337,23 @@ async def get_missing_dates_report(dependencies: dict): movie['title'] = movie['imdb_id'] movies_missing.append(movie) - # Episodes without dates - cursor.execute(""" - SELECT e.imdb_id, e.season, e.episode, e.aired, e.source, e.last_updated, s.path - FROM episodes e - JOIN series s ON e.imdb_id = s.imdb_id - WHERE e.dateadded IS NULL OR e.dateadded = '' OR e.source = 'no_valid_date_source' - ORDER BY e.last_updated DESC - """) + # Episodes without dates - PostgreSQL compatible + if db.db_type == "postgresql": + cursor.execute(""" + SELECT e.imdb_id, e.season, e.episode, e.aired, e.source, e.last_updated, s.path + FROM episodes e + JOIN series s ON e.imdb_id = s.imdb_id + WHERE e.dateadded IS NULL OR e.source = 'no_valid_date_source' + ORDER BY e.last_updated DESC + """) + else: + cursor.execute(""" + SELECT e.imdb_id, e.season, e.episode, e.aired, e.source, e.last_updated, s.path + FROM episodes e + JOIN series s ON e.imdb_id = s.imdb_id + WHERE e.dateadded IS NULL OR e.dateadded = '' OR e.source = 'no_valid_date_source' + ORDER BY e.last_updated DESC + """) episodes_missing = [] for row in cursor.fetchall(): episode = dict(row) @@ -346,15 +363,25 @@ async def get_missing_dates_report(dependencies: dict): episode['series_title'] = episode['imdb_id'] episodes_missing.append(episode) - # Summary statistics - cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NOT NULL AND dateadded != ''") - movies_with_dates = cursor.fetchone()[0] - - cursor.execute("SELECT COUNT(*) FROM movies") - total_movies = cursor.fetchone()[0] - - cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NOT NULL AND dateadded != ''") - episodes_with_dates = cursor.fetchone()[0] + # Summary statistics - PostgreSQL compatible + if db.db_type == "postgresql": + cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NOT NULL") + movies_with_dates = db._get_first_value(cursor.fetchone()) + + cursor.execute("SELECT COUNT(*) FROM movies") + total_movies = db._get_first_value(cursor.fetchone()) + + cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NOT NULL") + episodes_with_dates = db._get_first_value(cursor.fetchone()) + else: + cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NOT NULL AND dateadded != ''") + movies_with_dates = cursor.fetchone()[0] + + cursor.execute("SELECT COUNT(*) FROM movies") + total_movies = cursor.fetchone()[0] + + cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NOT NULL AND dateadded != ''") + episodes_with_dates = cursor.fetchone()[0] cursor.execute("SELECT COUNT(*) FROM episodes") total_episodes = cursor.fetchone()[0] @@ -383,24 +410,37 @@ async def get_dashboard_stats(dependencies: dict): with db.get_connection() as conn: cursor = conn.cursor() - # Enhanced statistics - cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NOT NULL AND dateadded != ''") - movies_with_dates = cursor.fetchone()[0] - - cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NULL OR dateadded = '' OR source = 'no_valid_date_source'") - movies_without_dates = cursor.fetchone()[0] - - cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NOT NULL AND dateadded != ''") - episodes_with_dates = cursor.fetchone()[0] - - cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NULL OR dateadded = '' OR source = 'no_valid_date_source'") - episodes_without_dates = cursor.fetchone()[0] + # Enhanced statistics - PostgreSQL compatible + if db.db_type == "postgresql": + cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NOT NULL") + movies_with_dates = db._get_first_value(cursor.fetchone()) + + cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NULL OR source = 'no_valid_date_source'") + movies_without_dates = db._get_first_value(cursor.fetchone()) + + cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NOT NULL") + episodes_with_dates = db._get_first_value(cursor.fetchone()) + + cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NULL OR source = 'no_valid_date_source'") + episodes_without_dates = db._get_first_value(cursor.fetchone()) + else: + cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NOT NULL AND dateadded != ''") + movies_with_dates = cursor.fetchone()[0] + + cursor.execute("SELECT COUNT(*) FROM movies WHERE dateadded IS NULL OR dateadded = '' OR source = 'no_valid_date_source'") + movies_without_dates = cursor.fetchone()[0] + + cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NOT NULL AND dateadded != ''") + episodes_with_dates = cursor.fetchone()[0] + + cursor.execute("SELECT COUNT(*) FROM episodes WHERE dateadded IS NULL OR dateadded = '' OR source = 'no_valid_date_source'") + episodes_without_dates = cursor.fetchone()[0] cursor.execute("SELECT COUNT(*) FROM movies WHERE source = 'no_valid_date_source'") - movies_no_valid_source = cursor.fetchone()[0] + movies_no_valid_source = db._get_first_value(cursor.fetchone()) cursor.execute("SELECT COUNT(*) FROM episodes WHERE source = 'no_valid_date_source'") - episodes_no_valid_source = cursor.fetchone()[0] + episodes_no_valid_source = db._get_first_value(cursor.fetchone()) # Recent activity (last 7 days) cursor.execute("""