This commit is contained in:
+82
-29
@@ -842,19 +842,44 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
# 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:
|
||||||
try:
|
try:
|
||||||
|
print(f"🔍 DEBUG: Attempting Sonarr lookup for {imdb_id}")
|
||||||
# Look up the series and episode in Sonarr
|
# Look up the series and episode in Sonarr
|
||||||
series_data = tv_processor.sonarr.series_by_imdb(imdb_id)
|
series_data = tv_processor.sonarr.series_by_imdb(imdb_id)
|
||||||
|
|
||||||
|
# If IMDb lookup fails, try direct series lookup as fallback
|
||||||
|
if not series_data:
|
||||||
|
print(f"🔍 DEBUG: IMDb lookup failed, trying direct series lookup")
|
||||||
|
try:
|
||||||
|
series_data = tv_processor.sonarr.series_by_imdb_direct(imdb_id)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Direct series lookup also failed: {e}")
|
||||||
|
|
||||||
|
print(f"🔍 DEBUG: Series data found: {series_data is not None}")
|
||||||
if series_data:
|
if series_data:
|
||||||
series_id = series_data.get('id')
|
series_id = series_data.get('id')
|
||||||
|
series_title = series_data.get('title', 'Unknown')
|
||||||
|
print(f"🔍 DEBUG: Found series '{series_title}' with ID {series_id}")
|
||||||
|
|
||||||
if series_id:
|
if series_id:
|
||||||
# Get episodes for the series
|
# Get episodes for the series
|
||||||
|
print(f"🔍 DEBUG: Getting episodes for series {series_id}")
|
||||||
episodes = tv_processor.sonarr.episodes_for_series(series_id)
|
episodes = tv_processor.sonarr.episodes_for_series(series_id)
|
||||||
|
print(f"🔍 DEBUG: Found {len(episodes)} episodes")
|
||||||
|
|
||||||
for ep in episodes:
|
for ep in episodes:
|
||||||
if ep.get('seasonNumber') == season and ep.get('episodeNumber') == episode:
|
ep_season = ep.get('seasonNumber')
|
||||||
|
ep_episode = ep.get('episodeNumber')
|
||||||
|
if ep_season == season and ep_episode == episode:
|
||||||
episode_id = ep.get('id')
|
episode_id = ep.get('id')
|
||||||
|
ep_title = ep.get('title', 'Unknown')
|
||||||
|
print(f"🔍 DEBUG: Found target episode '{ep_title}' with ID {episode_id}")
|
||||||
|
|
||||||
if episode_id:
|
if episode_id:
|
||||||
# Get import history for this specific episode
|
# Get import history for this specific episode
|
||||||
|
print(f"🔍 DEBUG: Getting import history for episode {episode_id}")
|
||||||
import_date = tv_processor.sonarr.get_episode_import_history(episode_id)
|
import_date = tv_processor.sonarr.get_episode_import_history(episode_id)
|
||||||
|
print(f"🔍 DEBUG: Import date found: {import_date}")
|
||||||
|
|
||||||
if import_date:
|
if import_date:
|
||||||
# Check if this is different from current date
|
# Check if this is different from current date
|
||||||
current_dateadded = episode_data.get('dateadded', '')
|
current_dateadded = episode_data.get('dateadded', '')
|
||||||
@@ -866,46 +891,74 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
"source": "sonarr:import_history",
|
"source": "sonarr:import_history",
|
||||||
"description": f"Import date from Sonarr: {import_date[:10]}"
|
"description": f"Import date from Sonarr: {import_date[:10]}"
|
||||||
})
|
})
|
||||||
|
print(f"✅ Added Sonarr import option: {import_date[:10]}")
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
print(f"❌ No series found in Sonarr for {imdb_id}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Failed to get Sonarr import date for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
print(f"⚠️ Failed to get Sonarr import date for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
||||||
|
import traceback
|
||||||
|
print(f" Traceback: {traceback.format_exc()}")
|
||||||
|
|
||||||
# Check TMDB for episode air dates
|
# Check TMDB for episode air dates
|
||||||
if external_clients.tmdb.enabled:
|
if external_clients.tmdb.enabled:
|
||||||
try:
|
try:
|
||||||
|
print(f"🔍 DEBUG: Attempting TMDB lookup for {imdb_id}")
|
||||||
# Get TMDB TV series ID from IMDb ID using find endpoint
|
# Get TMDB TV series ID from IMDb ID using find endpoint
|
||||||
tv_find_result = external_clients.tmdb._get(f"/find/{imdb_id}", {"external_source": "imdb_id"})
|
tv_find_result = external_clients.tmdb._get(f"/find/{imdb_id}", {"external_source": "imdb_id"})
|
||||||
if tv_find_result and tv_find_result.get("tv_results"):
|
print(f"🔍 DEBUG: TMDB find result: {tv_find_result is not None}")
|
||||||
tv_show = tv_find_result["tv_results"][0]
|
|
||||||
tmdb_id = tv_show.get("id")
|
|
||||||
if tmdb_id:
|
|
||||||
# Get episode air date from TMDB
|
|
||||||
episodes = external_clients.tmdb.get_tv_season_episodes(tmdb_id, season)
|
|
||||||
if episode in episodes:
|
|
||||||
air_date = episodes[episode]
|
|
||||||
if air_date:
|
|
||||||
# Check if this is different from current aired date
|
|
||||||
current_aired = episode_data.get('aired', '')
|
|
||||||
if not current_aired or current_aired != air_date:
|
|
||||||
options.append({
|
|
||||||
"type": "tmdb_air",
|
|
||||||
"label": "TMDB Air Date",
|
|
||||||
"date": f"{air_date}T20:00:00", # Default to 8 PM
|
|
||||||
"source": "tmdb:airdate",
|
|
||||||
"description": f"Air date from TMDB: {air_date}"
|
|
||||||
})
|
|
||||||
|
|
||||||
# If no aired date in database, also add this as "Use Air Date" option
|
if tv_find_result and tv_find_result.get("tv_results"):
|
||||||
if not current_aired:
|
tv_results = tv_find_result.get("tv_results", [])
|
||||||
options.insert(1, { # Insert after current option
|
print(f"🔍 DEBUG: Found {len(tv_results)} TV results")
|
||||||
"type": "airdate_tmdb",
|
|
||||||
"label": "Use Air Date (TMDB)",
|
if tv_results:
|
||||||
"date": f"{air_date}T20:00:00",
|
tv_show = tv_results[0]
|
||||||
"source": "airdate",
|
tmdb_id = tv_show.get("id")
|
||||||
"description": f"Use air date from TMDB: {air_date}"
|
tv_title = tv_show.get("name", "Unknown")
|
||||||
})
|
print(f"🔍 DEBUG: Found TMDB series '{tv_title}' with ID {tmdb_id}")
|
||||||
|
|
||||||
|
if tmdb_id:
|
||||||
|
# Get episode air date from TMDB
|
||||||
|
print(f"🔍 DEBUG: Getting TMDB season {season} episodes for series {tmdb_id}")
|
||||||
|
episodes = external_clients.tmdb.get_tv_season_episodes(tmdb_id, season)
|
||||||
|
print(f"🔍 DEBUG: TMDB episodes found: {episodes}")
|
||||||
|
|
||||||
|
if episode in episodes:
|
||||||
|
air_date = episodes[episode]
|
||||||
|
print(f"🔍 DEBUG: TMDB air date for S{season:02d}E{episode:02d}: {air_date}")
|
||||||
|
|
||||||
|
if air_date:
|
||||||
|
# Check if this is different from current aired date
|
||||||
|
current_aired = episode_data.get('aired', '')
|
||||||
|
if not current_aired or current_aired != air_date:
|
||||||
|
options.append({
|
||||||
|
"type": "tmdb_air",
|
||||||
|
"label": "TMDB Air Date",
|
||||||
|
"date": f"{air_date}T20:00:00", # Default to 8 PM
|
||||||
|
"source": "tmdb:airdate",
|
||||||
|
"description": f"Air date from TMDB: {air_date}"
|
||||||
|
})
|
||||||
|
print(f"✅ Added TMDB air date option: {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}"
|
||||||
|
})
|
||||||
|
print(f"✅ Added 'Use Air Date' option from TMDB: {air_date}")
|
||||||
|
else:
|
||||||
|
print(f"❌ Episode {episode} not found in TMDB season {season} data")
|
||||||
|
else:
|
||||||
|
print(f"❌ No TV results found in TMDB for {imdb_id}")
|
||||||
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}")
|
||||||
|
import traceback
|
||||||
|
print(f" Traceback: {traceback.format_exc()}")
|
||||||
|
|
||||||
# Check external clients for episode air dates (TVDB, OMDb)
|
# Check external clients for episode air dates (TVDB, OMDb)
|
||||||
if hasattr(external_clients, 'get_episode_air_date'):
|
if hasattr(external_clients, 'get_episode_air_date'):
|
||||||
|
|||||||
Reference in New Issue
Block a user