update sonarr .nfo flow
This commit is contained in:
+20
-4
@@ -439,17 +439,33 @@ class NFOManager:
|
|||||||
if existing_long_nfo and source_nfo_path == existing_long_nfo:
|
if existing_long_nfo and source_nfo_path == existing_long_nfo:
|
||||||
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}")
|
||||||
|
|
||||||
|
# Show what content fields are being preserved
|
||||||
|
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)}")
|
||||||
|
|
||||||
# Remove existing NFOGuard-managed elements to avoid duplicates
|
# Preserve existing content fields and store NFOGuard-managed fields for re-adding
|
||||||
# These will be re-added at the bottom
|
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]}...")
|
||||||
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user