This commit is contained in:
+49
-13
@@ -814,7 +814,7 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
"description": f"Currently using: {episode_data.get('source', 'Unknown')}"
|
"description": f"Currently using: {episode_data.get('source', 'Unknown')}"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Option 2: Aired date
|
# Option 2: Aired date (if exists in database)
|
||||||
if episode_data.get('aired'):
|
if episode_data.get('aired'):
|
||||||
options.append({
|
options.append({
|
||||||
"type": "airdate",
|
"type": "airdate",
|
||||||
@@ -828,8 +828,16 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
try:
|
try:
|
||||||
# Get TV processor and clients from dependencies
|
# Get TV processor and clients from dependencies
|
||||||
tv_processor = dependencies.get("tv_processor")
|
tv_processor = dependencies.get("tv_processor")
|
||||||
|
print(f"🔍 DEBUG: tv_processor available: {tv_processor is not None}")
|
||||||
|
if tv_processor:
|
||||||
|
print(f"🔍 DEBUG: tv_processor has external_clients: {hasattr(tv_processor, 'external_clients')}")
|
||||||
|
print(f"🔍 DEBUG: tv_processor has sonarr: {hasattr(tv_processor, 'sonarr')}")
|
||||||
|
|
||||||
if tv_processor and hasattr(tv_processor, 'external_clients'):
|
if tv_processor and hasattr(tv_processor, 'external_clients'):
|
||||||
external_clients = tv_processor.external_clients
|
external_clients = tv_processor.external_clients
|
||||||
|
print(f"🔍 DEBUG: external_clients available: {external_clients is not None}")
|
||||||
|
if external_clients:
|
||||||
|
print(f"🔍 DEBUG: TMDB enabled: {external_clients.tmdb.enabled if hasattr(external_clients, 'tmdb') else 'No TMDB client'}")
|
||||||
|
|
||||||
# Check Sonarr for import dates
|
# Check Sonarr for import dates
|
||||||
if tv_processor.sonarr and tv_processor.sonarr.enabled:
|
if tv_processor.sonarr and tv_processor.sonarr.enabled:
|
||||||
@@ -840,7 +848,7 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
series_id = series_data.get('id')
|
series_id = series_data.get('id')
|
||||||
if series_id:
|
if series_id:
|
||||||
# Get episodes for the series
|
# Get episodes for the series
|
||||||
episodes = tv_processor.sonarr.get_episodes(series_id)
|
episodes = tv_processor.sonarr.episodes_for_series(series_id)
|
||||||
for ep in episodes:
|
for ep in episodes:
|
||||||
if ep.get('seasonNumber') == season and ep.get('episodeNumber') == episode:
|
if ep.get('seasonNumber') == season and ep.get('episodeNumber') == episode:
|
||||||
episode_id = ep.get('id')
|
episode_id = ep.get('id')
|
||||||
@@ -865,10 +873,11 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
# Check TMDB for episode air dates
|
# Check TMDB for episode air dates
|
||||||
if external_clients.tmdb.enabled:
|
if external_clients.tmdb.enabled:
|
||||||
try:
|
try:
|
||||||
# Get TMDB TV series ID from IMDb ID
|
# Get TMDB TV series ID from IMDb ID using find endpoint
|
||||||
tv_info = external_clients.tmdb.find_tv_by_imdb(imdb_id)
|
tv_find_result = external_clients.tmdb._get(f"/find/{imdb_id}", {"external_source": "imdb_id"})
|
||||||
if tv_info:
|
if tv_find_result and tv_find_result.get("tv_results"):
|
||||||
tmdb_id = tv_info.get('id')
|
tv_show = tv_find_result["tv_results"][0]
|
||||||
|
tmdb_id = tv_show.get("id")
|
||||||
if tmdb_id:
|
if tmdb_id:
|
||||||
# Get episode air date from TMDB
|
# Get episode air date from TMDB
|
||||||
episodes = external_clients.tmdb.get_tv_season_episodes(tmdb_id, season)
|
episodes = external_clients.tmdb.get_tv_season_episodes(tmdb_id, season)
|
||||||
@@ -885,6 +894,16 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
"source": "tmdb:airdate",
|
"source": "tmdb:airdate",
|
||||||
"description": f"Air date from TMDB: {air_date}"
|
"description": f"Air date from TMDB: {air_date}"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# If no aired date in database, also add this as "Use Air Date" option
|
||||||
|
if not current_aired:
|
||||||
|
options.insert(1, { # Insert after current option
|
||||||
|
"type": "airdate_tmdb",
|
||||||
|
"label": "Use Air Date (TMDB)",
|
||||||
|
"date": f"{air_date}T20:00:00",
|
||||||
|
"source": "airdate",
|
||||||
|
"description": f"Use air date from TMDB: {air_date}"
|
||||||
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Failed to get TMDB air date for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
print(f"⚠️ Failed to get TMDB air date for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
||||||
|
|
||||||
@@ -903,6 +922,16 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
"source": "external:airdate",
|
"source": "external:airdate",
|
||||||
"description": f"Air date from external sources: {air_date}"
|
"description": f"Air date from external sources: {air_date}"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# If no aired date in database and not already added from TMDB, add this as "Use Air Date" option
|
||||||
|
if not current_aired and not any(opt.get('type') == 'airdate_tmdb' for opt in options):
|
||||||
|
options.insert(1, { # Insert after current option
|
||||||
|
"type": "airdate_external",
|
||||||
|
"label": "Use Air Date (External)",
|
||||||
|
"date": f"{air_date}T20:00:00",
|
||||||
|
"source": "airdate",
|
||||||
|
"description": f"Use air date from external sources: {air_date}"
|
||||||
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Failed to get external air date for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
print(f"⚠️ Failed to get external air date for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
||||||
|
|
||||||
@@ -922,10 +951,17 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
for i, option in enumerate(options):
|
for i, option in enumerate(options):
|
||||||
print(f" Option {i}: {option}")
|
print(f" Option {i}: {option}")
|
||||||
|
|
||||||
return {
|
# Ensure we always return valid JSON
|
||||||
"imdb_id": imdb_id,
|
try:
|
||||||
"season": season,
|
result = {
|
||||||
"episode": episode,
|
"imdb_id": imdb_id,
|
||||||
"current_data": episode_data,
|
"season": season,
|
||||||
"options": options
|
"episode": episode,
|
||||||
}
|
"current_data": episode_data,
|
||||||
|
"options": options
|
||||||
|
}
|
||||||
|
print(f"🔍 DEBUG: Returning result with {len(result['options'])} options")
|
||||||
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ ERROR: Failed to create response: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=f"Failed to generate episode options: {str(e)}")
|
||||||
Reference in New Issue
Block a user