From 49266d651ace069b430fb74a0fb7fda8ffbe4f3a Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Sun, 14 Sep 2025 13:40:22 -0400 Subject: [PATCH] fix nfo --- SUMMARY.md | 46 ++++++++++++++++++++++++---------------- VERSION | 2 +- core/nfo_manager.py | 51 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 70 insertions(+), 29 deletions(-) diff --git a/SUMMARY.md b/SUMMARY.md index 939d02f..2d01f9d 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -1,27 +1,37 @@ # NFOGuard Development Summary -## Current Status: v1.3.4 - Complete Database Migration Fix +## Current Status: v1.3.6 - NFO Preservation Fix -### Latest Updates (v1.3.4) -- **๐Ÿ”ง DATABASE**: Fixed comprehensive schema migration for all missing columns -- **โœ… MIGRATION**: Added automatic detection and addition of `path`, `has_video_file`, `last_updated` columns -- **๐ŸŽฏ ROBUST**: Schema introspection ensures all required columns exist -- **๐Ÿ” VALIDATION**: Comprehensive column checking for both movies and episodes tables +### Latest Updates (v1.3.6) +- **๐Ÿ”ง NFO MANAGER**: Fixed movie.nfo to preserve existing content instead of overwriting +- **โœ… PRESERVATION**: Existing movie metadata (title, plot, actors, etc.) now maintained +- **๐ŸŽฏ TARGETED**: Only updates NFOGuard-managed fields (dateadded, uniqueid, lockdata) +- **๐Ÿงน CLEANUP**: Removes old NFOGuard elements before adding new ones to avoid duplicates -### Database Migration Strategy -``` -โœ… Check existing schema with PRAGMA table_info() -โœ… Add missing columns: path, has_video_file, last_updated -โœ… Update existing records with default values -โœ… Handle both movies and episodes tables -โœ… Graceful migration without data loss +### NFO Management Behavior (Fixed) +**Before (v1.3.5 and earlier):** +```xml + +โ†“ NFOGuard processing + + + ``` -### Path Mapping Success (v1.3.2-v1.3.4) -- **๐Ÿ› CRITICAL**: Fixed substring matching bug (movies/movies6, tv/tv6) -- **๐ŸŽฏ ALGORITHM**: Longest-path-first matching prevents incorrect mappings -- **๐Ÿ“ DEBUG**: Comprehensive debug logging for troubleshooting -- **โœ… TESTED**: Annabelle webhook processes correctly through all stageslopment Summary +**After (v1.3.6):** +```xml + +โ†“ NFOGuard processing + + + + Existing Title + Existing Plot + + 2025-09-14T13:37:14-04:00 + true + +```lopment Summary ## Current Status: v1.3.3 - Database Migration & Path Validation Complete diff --git a/VERSION b/VERSION index d0149fe..95b25ae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.4 +1.3.6 diff --git a/core/nfo_manager.py b/core/nfo_manager.py index 167cd0c..f3c258a 100644 --- a/core/nfo_manager.py +++ b/core/nfo_manager.py @@ -37,29 +37,60 @@ class NFOManager: def create_movie_nfo(self, movie_dir: Path, imdb_id: str, dateadded: str, released: Optional[str] = None, source: str = "unknown", lock_metadata: bool = True) -> None: - """Create movie.nfo file with proper metadata""" + """Create or update movie.nfo file preserving existing content""" nfo_path = movie_dir / "movie.nfo" try: - movie = ET.Element("movie") + # Try to load existing NFO file + if nfo_path.exists(): + try: + tree = ET.parse(nfo_path) + movie = tree.getroot() + + # Ensure root element is + if movie.tag != "movie": + raise ValueError("Root element is not ") + + # Remove existing NFOGuard elements to avoid duplicates + for elem in movie.findall(".//comment()"): + if elem is not None and "NFOGuard" in str(elem): + movie.remove(elem) + + # Remove existing NFOGuard-managed elements + for tag in ["dateadded", "lockdata"]: + existing = movie.find(tag) + if existing is not None: + movie.remove(existing) + + # Remove any existing uniqueid with type="imdb" + for uniqueid in movie.findall("uniqueid[@type='imdb']"): + movie.remove(uniqueid) + + except (ET.ParseError, ValueError) as e: + print(f"Warning: Could not parse existing NFO {nfo_path}, creating new: {e}") + movie = ET.Element("movie") + else: + # Create new NFO structure + movie = ET.Element("movie") - # Add unique ID + # Add/update NFOGuard comment + comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ") + movie.insert(0, comment) + + # Add/update IMDb uniqueid uniqueid = ET.SubElement(movie, "uniqueid", type="imdb", default="true") uniqueid.text = imdb_id - # Add dates + # Add dateadded if dateadded: dateadded_elem = ET.SubElement(movie, "dateadded") dateadded_elem.text = dateadded - if released: + # Add premiered if we have release date (only if not already present) + if released and movie.find("premiered") is None: premiered_elem = ET.SubElement(movie, "premiered") premiered_elem.text = released[:10] if len(released) >= 10 else released - # Add source comment - comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ") - movie.insert(0, comment) - # Add lockdata if requested if lock_metadata: lockdata = ET.SubElement(movie, "lockdata") @@ -71,7 +102,7 @@ class NFOManager: tree.write(nfo_path, encoding="utf-8", xml_declaration=True) except Exception as e: - print(f"Error creating movie NFO {nfo_path}: {e}") + print(f"Error creating/updating movie NFO {nfo_path}: {e}") def create_tvshow_nfo(self, series_dir: Path, imdb_id: str, tvdb_id: Optional[str] = None) -> None: """Create tvshow.nfo file"""