This commit is contained in:
+55
-2
@@ -842,19 +842,44 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
||||
# Check Sonarr for import dates
|
||||
if tv_processor.sonarr and tv_processor.sonarr.enabled:
|
||||
try:
|
||||
print(f"🔍 DEBUG: Attempting Sonarr lookup for {imdb_id}")
|
||||
# Look up the series and episode in Sonarr
|
||||
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:
|
||||
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:
|
||||
# Get episodes for the series
|
||||
print(f"🔍 DEBUG: Getting 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:
|
||||
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')
|
||||
ep_title = ep.get('title', 'Unknown')
|
||||
print(f"🔍 DEBUG: Found target episode '{ep_title}' with ID {episode_id}")
|
||||
|
||||
if episode_id:
|
||||
# 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)
|
||||
print(f"🔍 DEBUG: Import date found: {import_date}")
|
||||
|
||||
if import_date:
|
||||
# Check if this is different from current date
|
||||
current_dateadded = episode_data.get('dateadded', '')
|
||||
@@ -866,23 +891,43 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
||||
"source": "sonarr:import_history",
|
||||
"description": f"Import date from Sonarr: {import_date[:10]}"
|
||||
})
|
||||
print(f"✅ Added Sonarr import option: {import_date[:10]}")
|
||||
break
|
||||
else:
|
||||
print(f"❌ No series found in Sonarr for {imdb_id}")
|
||||
except Exception as 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
|
||||
if external_clients.tmdb.enabled:
|
||||
try:
|
||||
print(f"🔍 DEBUG: Attempting TMDB lookup for {imdb_id}")
|
||||
# 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"})
|
||||
print(f"🔍 DEBUG: TMDB find result: {tv_find_result is not None}")
|
||||
|
||||
if tv_find_result and tv_find_result.get("tv_results"):
|
||||
tv_show = tv_find_result["tv_results"][0]
|
||||
tv_results = tv_find_result.get("tv_results", [])
|
||||
print(f"🔍 DEBUG: Found {len(tv_results)} TV results")
|
||||
|
||||
if tv_results:
|
||||
tv_show = tv_results[0]
|
||||
tmdb_id = tv_show.get("id")
|
||||
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', '')
|
||||
@@ -894,6 +939,7 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
||||
"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:
|
||||
@@ -904,8 +950,15 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
||||
"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:
|
||||
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)
|
||||
if hasattr(external_clients, 'get_episode_air_date'):
|
||||
|
||||
Reference in New Issue
Block a user