From 852c45bbb56689b5661d03a9156eb85f8de05678 Mon Sep 17 00:00:00 2001 From: sbcrumb Date: Sat, 18 Oct 2025 14:28:10 -0400 Subject: [PATCH] db: updates for TV shows in interface --- VERSION | 2 +- api/web_routes.py | 82 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 8e8299d..35cee72 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.4.2 +2.4.3 diff --git a/api/web_routes.py b/api/web_routes.py index 01a256e..d4fb73e 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -11,6 +11,54 @@ from pathlib import Path from api.models import * +def map_source_to_description(source: str) -> str: + """Map technical source codes to user-friendly descriptions""" + if not source or source == "no_valid_date_source": + return "Unknown" + + # Handle different source patterns + source_lower = source.lower() + + # TMDB sources + if "tmdb:theatrical" in source_lower: + return "TMDB Theatrical" + elif "tmdb:digital" in source_lower: + return "TMDB Digital" + elif "tmdb:physical" in source_lower: + return "TMDB Physical/DVD" + elif "tmdb:" in source_lower: + return "TMDB Release" + + # Radarr sources + elif "radarr:db.history.import" in source_lower: + return "Radarr Import History" + elif "radarr:db.file.dateadded" in source_lower: + return "Radarr File Date" + elif "radarr:nfo.premiered" in source_lower: + return "Radarr NFO" + elif "radarr:" in source_lower: + return "Radarr" + + # OMDb sources + elif "omdb:dvd" in source_lower: + return "OMDb DVD" + elif "omdb:" in source_lower: + return "OMDb Release" + + # Manual and other sources + elif "manual" in source_lower: + return "Manual Entry" + elif "digital_release" in source_lower: + return "Digital Release" + elif "nfo:" in source_lower: + return "NFO File" + elif "webhook:" in source_lower: + return "Webhook/API" + + # Fallback for unknown patterns + return source.title() + + # --------------------------- # Database Query Endpoints # --------------------------- @@ -84,6 +132,8 @@ async def get_movies_list(dependencies: dict, movie['title'] = Path(movie['path']).name if movie['path'] else movie['imdb_id'] except: movie['title'] = movie['imdb_id'] + # Map source to user-friendly description + movie['source_description'] = map_source_to_description(movie.get('source')) movies.append(movie) return { @@ -305,7 +355,10 @@ async def get_series_episodes(dependencies: dict, imdb_id: str): cursor = conn.cursor() # Get series info - cursor.execute("SELECT * FROM series WHERE imdb_id = ?", (imdb_id,)) + if db.db_type == "postgresql": + cursor.execute("SELECT * FROM series WHERE imdb_id = %s", (imdb_id,)) + else: + cursor.execute("SELECT * FROM series WHERE imdb_id = ?", (imdb_id,)) series_row = cursor.fetchone() if not series_row: raise HTTPException(status_code=404, detail="Series not found") @@ -317,14 +370,27 @@ async def get_series_episodes(dependencies: dict, imdb_id: str): series_info['title'] = imdb_id # Get episodes - cursor.execute(""" - SELECT season, episode, aired, dateadded, source, has_video_file, last_updated - FROM episodes - WHERE imdb_id = ? - ORDER BY season, episode - """, (imdb_id,)) + if db.db_type == "postgresql": + cursor.execute(""" + SELECT season, episode, aired, dateadded, source, has_video_file, last_updated + FROM episodes + WHERE imdb_id = %s + ORDER BY season, episode + """, (imdb_id,)) + else: + cursor.execute(""" + SELECT season, episode, aired, dateadded, source, has_video_file, last_updated + FROM episodes + WHERE imdb_id = ? + ORDER BY season, episode + """, (imdb_id,)) - episodes = [dict(row) for row in cursor.fetchall()] + episodes = [] + for row in cursor.fetchall(): + episode = dict(row) + # Map source to user-friendly description + episode['source_description'] = map_source_to_description(episode.get('source')) + episodes.append(episode) return { "series": series_info,