This commit is contained in:
+38
-2
@@ -906,11 +906,19 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
|
|
||||||
for ep in episodes:
|
for ep in episodes:
|
||||||
ep_season = ep.get('seasonNumber')
|
ep_season = ep.get('seasonNumber')
|
||||||
ep_episode = ep.get('episodeNumber')
|
ep_episode = ep.get('episodeNumber')
|
||||||
|
# Convert to int for proper comparison (handle both string and int from Sonarr)
|
||||||
|
try:
|
||||||
|
ep_season = int(ep_season) if ep_season is not None else None
|
||||||
|
ep_episode = int(ep_episode) if ep_episode is not None else None
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
continue # Skip episodes with invalid season/episode numbers
|
||||||
|
|
||||||
if ep_season == season and ep_episode == episode:
|
if ep_season == season and ep_episode == episode:
|
||||||
episode_id = ep.get('id')
|
episode_id = ep.get('id')
|
||||||
ep_title = ep.get('title', 'Unknown')
|
ep_title = ep.get('title', 'Unknown')
|
||||||
print(f"🔍 DEBUG: Found target episode '{ep_title}' with ID {episode_id}")
|
ep_air_date = ep.get('airDate') # Get air date from Sonarr
|
||||||
|
print(f"🔍 DEBUG: Found target episode '{ep_title}' with ID {episode_id}, airDate: {ep_air_date}")
|
||||||
|
|
||||||
if episode_id:
|
if episode_id:
|
||||||
# Get import history for this specific episode
|
# Get import history for this specific episode
|
||||||
@@ -930,6 +938,34 @@ async def get_episode_date_options(dependencies: dict, imdb_id: str, season: int
|
|||||||
"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]}")
|
print(f"✅ Added Sonarr import option: {import_date[:10]}")
|
||||||
|
|
||||||
|
# If no import date but we have air date from Sonarr, add as air date option
|
||||||
|
if not import_date and ep_air_date:
|
||||||
|
current_aired = episode_data.get('aired', '')
|
||||||
|
current_dateadded = episode_data.get('dateadded', '')
|
||||||
|
|
||||||
|
# Add air date option if different from current or missing
|
||||||
|
if not current_aired or current_aired != ep_air_date:
|
||||||
|
options.append({
|
||||||
|
"type": "sonarr_air",
|
||||||
|
"label": "Sonarr Air Date",
|
||||||
|
"date": f"{ep_air_date}T20:00:00",
|
||||||
|
"source": "sonarr:airdate",
|
||||||
|
"description": f"Air date from Sonarr: {ep_air_date}"
|
||||||
|
})
|
||||||
|
print(f"✅ Added Sonarr air date option: {ep_air_date}")
|
||||||
|
|
||||||
|
# If no dateadded, suggest using air date as import date fallback
|
||||||
|
if not current_dateadded:
|
||||||
|
options.append({
|
||||||
|
"type": "sonarr_air_fallback",
|
||||||
|
"label": "Use Air Date as Import Date",
|
||||||
|
"date": f"{ep_air_date}T20:00:00",
|
||||||
|
"source": "sonarr:aired_fallback",
|
||||||
|
"description": f"Use Sonarr air date as import date: {ep_air_date}"
|
||||||
|
})
|
||||||
|
print(f"✅ Added Sonarr air date fallback option: {ep_air_date}")
|
||||||
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(f"❌ No series found in Sonarr for {imdb_id}")
|
print(f"❌ No series found in Sonarr for {imdb_id}")
|
||||||
|
|||||||
@@ -229,14 +229,25 @@ class TVProcessor:
|
|||||||
_log("WARNING", f"S{season:02d}E{episode:02d}: No aired date found from external APIs for {imdb_id}")
|
_log("WARNING", f"S{season:02d}E{episode:02d}: No aired date found from external APIs for {imdb_id}")
|
||||||
|
|
||||||
# Use air date as fallback for dateadded if no import date found
|
# Use air date as fallback for dateadded if no import date found
|
||||||
if not dateadded and aired and source != "sonarr:history.import":
|
if not dateadded and aired:
|
||||||
|
# Always use air date as fallback when no import date is available
|
||||||
dateadded = aired
|
dateadded = aired
|
||||||
if source == "sonarr:no_import_date":
|
if source == "sonarr:no_import_date":
|
||||||
source = "sonarr:aired_fallback"
|
source = "sonarr:aired_fallback"
|
||||||
|
elif source == "sonarr:history.import":
|
||||||
|
# This shouldn't happen but handle it gracefully
|
||||||
|
source = "sonarr:aired_fallback"
|
||||||
else:
|
else:
|
||||||
source = f"{source}_fallback" if source != "unknown" else "aired_fallback"
|
source = f"{source}_fallback" if source != "unknown" else "aired_fallback"
|
||||||
_log("DEBUG", f"S{season:02d}E{episode:02d}: Using aired date as fallback: {dateadded} (source: {source})")
|
_log("DEBUG", f"S{season:02d}E{episode:02d}: Using aired date as fallback: {dateadded} (source: {source})")
|
||||||
|
|
||||||
|
# Ensure air date is saved to database even if used as dateadded fallback
|
||||||
|
if aired and not dateadded:
|
||||||
|
# This is a fallback for cases where we have air date but absolutely no dateadded
|
||||||
|
dateadded = aired
|
||||||
|
source = "aired_only_fallback"
|
||||||
|
_log("INFO", f"S{season:02d}E{episode:02d}: No import date found, using air date as both aired and dateadded: {dateadded}")
|
||||||
|
|
||||||
episode_dates[(season, episode)] = (aired, dateadded, source)
|
episode_dates[(season, episode)] = (aired, dateadded, source)
|
||||||
|
|
||||||
return episode_dates
|
return episode_dates
|
||||||
|
|||||||
Reference in New Issue
Block a user