nfo fix again

This commit is contained in:
2025-09-14 13:44:56 -04:00
parent 49266d651a
commit e7b65cfed6
3 changed files with 36 additions and 42 deletions
+18 -28
View File
@@ -1,37 +1,27 @@
# NFOGuard Development Summary # NFOGuard Development Summary
## Current Status: v1.3.6 - NFO Preservation Fix ## Current Status: v1.3.7 - NFO XML Parsing Fix
### Latest Updates (v1.3.6) ### Latest Updates (v1.3.7)
- **🔧 NFO MANAGER**: Fixed movie.nfo to preserve existing content instead of overwriting - ** FIXED**: XML comment parsing error causing NFO creation to fail
- **✅ PRESERVATION**: Existing movie metadata (title, plot, actors, etc.) now maintained - **🔧 XML HANDLING**: Improved XML comment insertion and file writing
- **🎯 TARGETED**: Only updates NFOGuard-managed fields (dateadded, uniqueid, lockdata) - **✅ PRESERVATION**: Existing movie metadata properly preserved during updates
- **🧹 CLEANUP**: Removes old NFOGuard elements before adding new ones to avoid duplicates - **🎯 ROBUST**: Better error handling for malformed XML files
### NFO Management Behavior (Fixed) ### NFO Update Process (Fixed)
**Before (v1.3.5 and earlier):** ```
```xml 1. ✅ Load existing movie.nfo (if exists)
<!-- Full existing NFO with title, plot, cast, etc. --> 2. ✅ Parse and validate XML structure
↓ NFOGuard processing 3. ✅ Remove old NFOGuard elements to avoid duplicates
<movie> 4. ✅ Preserve all existing content (title, plot, cast, etc.)
<!-- Only NFOGuard fields - ALL EXISTING CONTENT LOST --> 5. ✅ Add/update NFOGuard fields (dateadded, lockdata, uniqueid)
</movie> 6. ✅ Write properly formatted XML with comment
``` ```
**After (v1.3.6):** ### Error Resolution
```xml - **v1.3.6**: XML comment handling caused `'()` error
<!-- Full existing NFO with title, plot, cast, etc. --> - **v1.3.7**: Fixed comment insertion and XML serialization
↓ NFOGuard processing - **Result**: NFO files now update correctly while preserving contentlopment Summary
<movie>
<!-- NFOGuard comment and fields added -->
<!-- ALL EXISTING CONTENT PRESERVED -->
<title>Existing Title</title>
<plot>Existing Plot</plot>
<!-- ... existing content ... -->
<dateadded>2025-09-14T13:37:14-04:00</dateadded>
<lockdata>true</lockdata>
</movie>
```lopment Summary
## Current Status: v1.3.3 - Database Migration & Path Validation Complete ## Current Status: v1.3.3 - Database Migration & Path Validation Complete
+1 -1
View File
@@ -1 +1 @@
1.3.6 1.3.7
+16 -12
View File
@@ -51,12 +51,7 @@ class NFOManager:
if movie.tag != "movie": if movie.tag != "movie":
raise ValueError("Root element is not <movie>") raise ValueError("Root element is not <movie>")
# Remove existing NFOGuard elements to avoid duplicates # Remove existing NFOGuard-managed 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"]: for tag in ["dateadded", "lockdata"]:
existing = movie.find(tag) existing = movie.find(tag)
if existing is not None: if existing is not None:
@@ -73,10 +68,6 @@ class NFOManager:
# Create new NFO structure # Create new NFO structure
movie = ET.Element("movie") movie = ET.Element("movie")
# Add/update NFOGuard comment
comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ")
movie.insert(0, comment)
# Add/update IMDb uniqueid # Add/update IMDb uniqueid
uniqueid = ET.SubElement(movie, "uniqueid", type="imdb", default="true") uniqueid = ET.SubElement(movie, "uniqueid", type="imdb", default="true")
uniqueid.text = imdb_id uniqueid.text = imdb_id
@@ -96,10 +87,23 @@ class NFOManager:
lockdata = ET.SubElement(movie, "lockdata") lockdata = ET.SubElement(movie, "lockdata")
lockdata.text = "true" lockdata.text = "true"
# Write file # Add NFOGuard comment at the beginning
comment_text = f" Created by {self.manager_brand} - Source: {source} "
# Write file with proper formatting
tree = ET.ElementTree(movie) tree = ET.ElementTree(movie)
ET.indent(tree, space=" ", level=0) ET.indent(tree, space=" ", level=0)
tree.write(nfo_path, encoding="utf-8", xml_declaration=True)
# Write to string first to add comment
import xml.etree.ElementTree as ET_temp
xml_str = ET.tostring(movie, encoding='unicode')
# Add XML declaration and comment
full_xml = f'<?xml version="1.0" encoding="utf-8"?>\n<!--{comment_text}-->\n{xml_str}'
# Write to file
with open(nfo_path, 'w', encoding='utf-8') as f:
f.write(full_xml)
except Exception as e: except Exception as e:
print(f"Error creating/updating movie NFO {nfo_path}: {e}") print(f"Error creating/updating movie NFO {nfo_path}: {e}")