From e3a119efd7c2cf18eae72bc28a91d1cc7602207d Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Fri, 26 Sep 2025 09:31:19 -0400 Subject: [PATCH] fix: Add automatic episode data lookup to NFO update method 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. --- VERSION | 2 +- core/nfo_manager.py | 17 ++++++++++++++++- processors/tv_processor.py | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 66beabb..6ae756c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.9.8 +1.9.9 diff --git a/core/nfo_manager.py b/core/nfo_manager.py index 3882359..a582540 100644 --- a/core/nfo_manager.py +++ b/core/nfo_manager.py @@ -947,10 +947,25 @@ class NFOManager: return processed_count 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""" if not nfo_path.exists(): 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: # Parse the existing NFO file diff --git a/processors/tv_processor.py b/processors/tv_processor.py index 2772a7f..ee3a08c 100644 --- a/processors/tv_processor.py +++ b/processors/tv_processor.py @@ -98,7 +98,8 @@ class TVProcessor: if existing_nfo: # Update existing NFO while preserving its filename 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: # Fallback to standard creation if NFO not found