fix: Add automatic episode data lookup to NFO update method
Local Docker Build (Dev) / build-dev (push) Successful in 19s

Root cause identified: update_episode_nfo_preserving_name() was receiving
None values for aired/dateadded and just updating NFO with basic fields.

Fixed by:
- Adding automatic data fetching when missing episode data detected
- Passing imdb_id and tv_processor to enable API calls
- Added fallback logic to fetch from database/Sonarr when data missing
- Will show clear debug output when fetching missing data

Now when NFO files are updated, they will automatically get proper
dateadded and aired fields from the NFOGuard database or Sonarr API.

This should resolve the missing NFOGuard metadata in episode NFO files.
This commit is contained in:
2025-09-26 09:31:19 -04:00
parent 79aa49cbf1
commit e3a119efd7
3 changed files with 19 additions and 3 deletions
+1 -1
View File
@@ -1 +1 @@
1.9.8 1.9.9
+16 -1
View File
@@ -947,10 +947,25 @@ class NFOManager:
return processed_count return processed_count
def update_episode_nfo_preserving_name(self, nfo_path: Path, season_num: int, episode_num: int, def update_episode_nfo_preserving_name(self, nfo_path: Path, season_num: int, episode_num: int,
aired: Optional[str], dateadded: Optional[str], source: str) -> bool: aired: Optional[str], dateadded: Optional[str], source: str,
imdb_id: Optional[str] = None, tv_processor=None) -> bool:
"""Update existing TV episode NFO file while preserving its original filename""" """Update existing TV episode NFO file while preserving its original filename"""
if not nfo_path.exists(): if not nfo_path.exists():
return False return False
# If no episode data provided and we have IMDb ID, try to fetch it
if (not aired or not dateadded) and imdb_id and tv_processor:
print(f"⚠️ Missing episode data for S{season_num:02d}E{episode_num:02d}, attempting to fetch from APIs")
try:
fetched_aired, fetched_dateadded = tv_processor._get_episode_dates_from_apis(imdb_id, season_num, episode_num)
if fetched_aired and not aired:
aired = fetched_aired
print(f"✅ Fetched aired date: {aired}")
if fetched_dateadded and not dateadded:
dateadded = fetched_dateadded
print(f"✅ Fetched dateadded: {dateadded}")
except Exception as e:
print(f"⚠️ Failed to fetch episode data: {e}")
try: try:
# Parse the existing NFO file # Parse the existing NFO file
+2 -1
View File
@@ -98,7 +98,8 @@ class TVProcessor:
if existing_nfo: if existing_nfo:
# Update existing NFO while preserving its filename # Update existing NFO while preserving its filename
self.nfo_manager.update_episode_nfo_preserving_name( self.nfo_manager.update_episode_nfo_preserving_name(
existing_nfo, season, episode, aired, dateadded, "file_update" existing_nfo, season, episode, aired, dateadded, "file_update",
imdb_id, self
) )
else: else:
# Fallback to standard creation if NFO not found # Fallback to standard creation if NFO not found