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
+17 -13
View File
@@ -50,19 +50,14 @@ class NFOManager:
# Ensure root element is <movie>
if movie.tag != "movie":
raise ValueError("Root element is not <movie>")
# 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
# Remove existing NFOGuard-managed elements to avoid duplicates
for tag in ["dateadded", "lockdata"]:
existing = movie.find(tag)
if existing is not None:
movie.remove(existing)
# Remove any existing uniqueid with type="imdb"
# Remove any existing uniqueid with type="imdb"
for uniqueid in movie.findall("uniqueid[@type='imdb']"):
movie.remove(uniqueid)
@@ -73,10 +68,6 @@ class NFOManager:
# Create new NFO structure
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
uniqueid = ET.SubElement(movie, "uniqueid", type="imdb", default="true")
uniqueid.text = imdb_id
@@ -96,10 +87,23 @@ class NFOManager:
lockdata = ET.SubElement(movie, "lockdata")
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)
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:
print(f"Error creating/updating movie NFO {nfo_path}: {e}")