fix: Add automatic episode data lookup to NFO update method
Local Docker Build (Dev) / build-dev (push) Successful in 19s
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:
+16
-1
@@ -947,11 +947,26 @@ 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
|
||||
tree = ET.parse(nfo_path)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user