fix: Move NFOGuard comment to bottom with other fields
Local Docker Build (Dev) / build-dev (push) Successful in 24s

Moved the NFOGuard source comment from the top of the XML file to
just before our field additions at the bottom. This creates a clear
separation showing where NFOGuard's modifications begin.

Expected structure:
[existing rich metadata]
<!-- NFOGuard - Source: tmdb:digital -->
<uniqueid type="imdb" default="true">tt123</uniqueid>
<premiered>2024-08-20</premiered>
<dateadded>2024-08-20T00:00:00+00:00</dateadded>
<lockdata>true</lockdata>
This commit is contained in:
2025-09-24 10:08:10 -04:00
parent fc3c190c1b
commit ed03f23272
+7 -12
View File
@@ -186,6 +186,10 @@ class NFOManager:
# Now append ALL NFOGuard fields at the VERY END of the file # Now append ALL NFOGuard fields at the VERY END of the file
# Create elements and explicitly append them to ensure they're at the bottom # Create elements and explicitly append them to ensure they're at the bottom
# Add NFOGuard comment marker as the first of our additions
nfoguard_comment = ET.Comment(f" NFOGuard - Source: {source} ")
movie.append(nfoguard_comment)
# Add IMDb uniqueid at the end (after all existing content) # Add IMDb uniqueid at the end (after all existing content)
uniqueid = ET.Element("uniqueid", type="imdb", default="true") uniqueid = ET.Element("uniqueid", type="imdb", default="true")
uniqueid.text = imdb_id uniqueid.text = imdb_id
@@ -220,23 +224,14 @@ class NFOManager:
lockdata.text = "true" lockdata.text = "true"
movie.append(lockdata) movie.append(lockdata)
# Add NFOGuard comment at the beginning
comment_text = f" Created by {self.manager_brand} - Source: {source} "
# Write file with proper formatting # 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)
# Write to string first to add comment # Write directly to file (comment is already embedded in XML)
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: with open(nfo_path, 'w', encoding='utf-8') as f:
f.write(full_xml) f.write('<?xml version="1.0" encoding="utf-8"?>\n')
tree.write(f, encoding='unicode', xml_declaration=False)
print(f"✅ Successfully created/updated movie NFO: {nfo_path}") print(f"✅ Successfully created/updated movie NFO: {nfo_path}")
print(f" IMDb ID: {imdb_id}, Date Added: {dateadded}, Source: {source}") print(f" IMDb ID: {imdb_id}, Date Added: {dateadded}, Source: {source}")