This commit is contained in:
+78
-35
@@ -860,7 +860,33 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
||||
for ls in lincoln_series:
|
||||
print(f" - Title: '{ls.get('title')}', IMDb: '{ls.get('imdbId')}', ID: {ls.get('id')}")
|
||||
|
||||
# Try direct lookup first
|
||||
series_data = tv_processor.sonarr.series_by_imdb_direct(imdb_id)
|
||||
|
||||
# If still no match but we found Lincoln Lawyer series, try fuzzy matching
|
||||
if not series_data and lincoln_series:
|
||||
target_imdb_num = imdb_id.replace('tt', '').lower()
|
||||
print(f"🔍 DEBUG: Trying fuzzy match for IMDb number: {target_imdb_num}")
|
||||
|
||||
for ls in lincoln_series:
|
||||
ls_imdb = ls.get('imdbId', '')
|
||||
ls_imdb_num = ls_imdb.replace('tt', '').lower()
|
||||
print(f" - Comparing {target_imdb_num} vs {ls_imdb_num}")
|
||||
|
||||
# Check if IMDb numbers are close (within 10 digits)
|
||||
if ls_imdb_num and target_imdb_num:
|
||||
try:
|
||||
target_num = int(target_imdb_num)
|
||||
ls_num = int(ls_imdb_num)
|
||||
diff = abs(target_num - ls_num)
|
||||
print(f" - Numeric difference: {diff}")
|
||||
|
||||
if diff <= 10: # Allow small IMDb ID differences
|
||||
print(f"✅ Found close IMDb match: {ls_imdb} vs {imdb_id} (diff: {diff})")
|
||||
series_data = ls
|
||||
break
|
||||
except ValueError:
|
||||
continue
|
||||
except Exception as e:
|
||||
print(f"⚠️ Direct series lookup also failed: {e}")
|
||||
import traceback
|
||||
@@ -921,6 +947,10 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
||||
print(f"🔍 DEBUG: TMDB find result: {tv_find_result is not None}")
|
||||
print(f"🔍 DEBUG: TMDB raw response: {tv_find_result}")
|
||||
|
||||
# Check both tv_results and tv_episode_results
|
||||
tmdb_id = None
|
||||
tv_title = "Unknown"
|
||||
|
||||
if tv_find_result and tv_find_result.get("tv_results"):
|
||||
tv_results = tv_find_result.get("tv_results", [])
|
||||
print(f"🔍 DEBUG: Found {len(tv_results)} TV results")
|
||||
@@ -930,44 +960,57 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
||||
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}")
|
||||
|
||||
# Fallback: Check tv_episode_results for show_id
|
||||
elif tv_find_result and tv_find_result.get("tv_episode_results"):
|
||||
episode_results = tv_find_result.get("tv_episode_results", [])
|
||||
print(f"🔍 DEBUG: Found {len(episode_results)} TV episode results")
|
||||
|
||||
if episode_results:
|
||||
episode = episode_results[0]
|
||||
tmdb_id = episode.get("show_id")
|
||||
episode_name = episode.get("name", "Unknown")
|
||||
print(f"🔍 DEBUG: Found TMDB series via episode '{episode_name}' with show_id {tmdb_id}")
|
||||
|
||||
if tmdb_id:
|
||||
print(f"🔍 DEBUG: Using TMDB ID {tmdb_id} for series lookup")
|
||||
|
||||
# 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 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 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 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")
|
||||
# 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}")
|
||||
print(f"❌ No TV series ID 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
|
||||
|
||||
Reference in New Issue
Block a user