update sonarr .nfo flow

This commit is contained in:
2025-09-22 09:25:03 -04:00
parent 93cee77ce0
commit f563c67405
+20 -4
View File
@@ -440,17 +440,33 @@ class NFOManager:
old_nfo_to_delete = existing_long_nfo old_nfo_to_delete = existing_long_nfo
print(f"📦 Migrating episode NFO: {existing_long_nfo.name} -> {episode_filename}") print(f"📦 Migrating episode NFO: {existing_long_nfo.name} -> {episode_filename}")
# Remove existing NFOGuard-managed elements to avoid duplicates # Show what content fields are being preserved
# These will be re-added at the bottom content_fields = ["title", "plot", "runtime", "premiered"]
preserved_content = []
for field in content_fields:
elem = episode.find(field)
if elem is not None and elem.text:
preserved_content.append(field)
if preserved_content:
print(f" 📄 Preserving content: {', '.join(preserved_content)}")
# Preserve existing content fields and store NFOGuard-managed fields for re-adding
preserved_values = {}
# Extract and preserve NFOGuard-managed fields (we'll re-add these at the bottom)
nfoguard_fields = ["aired", "dateadded", "lockdata", "season", "episode"] nfoguard_fields = ["aired", "dateadded", "lockdata", "season", "episode"]
for tag in nfoguard_fields: for tag in nfoguard_fields:
existing = episode.find(tag) existing = episode.find(tag)
if existing is not None: if existing is not None:
# Store the aired value before removing # Store the value before removing
if tag == "aired" and not aired: if tag == "aired" and not aired:
aired = existing.text # Preserve existing aired date aired = existing.text # Preserve existing aired date
preserved_values[tag] = existing.text
episode.remove(existing) episode.remove(existing)
# Important: DO NOT remove content fields like title, plot, runtime, premiered, etc.
# These should be preserved from the long-named NFO files
except (ET.ParseError, ValueError) as e: except (ET.ParseError, ValueError) as e:
print(f"⚠️ Corrupted episode NFO detected: {nfo_path} - {str(e)[:100]}...") print(f"⚠️ Corrupted episode NFO detected: {nfo_path} - {str(e)[:100]}...")
print(f" Creating new clean episode NFO file to replace corrupted one") print(f" Creating new clean episode NFO file to replace corrupted one")
@@ -459,7 +475,7 @@ class NFOManager:
# Create new NFO structure # Create new NFO structure
episode = ET.Element("episodedetails") episode = ET.Element("episodedetails")
# Enhanced metadata should be preserved - only add if not already present # Add enhanced metadata only if not already present (preserve existing from long-named NFO)
if enhanced_metadata: if enhanced_metadata:
if enhanced_metadata.get("title") and not episode.find("title"): if enhanced_metadata.get("title") and not episode.find("title"):
title_elem = ET.SubElement(episode, "title") title_elem = ET.SubElement(episode, "title")