From cbe22ea2fff264e23ca86d3c2985c9f17cacc77f Mon Sep 17 00:00:00 2001 From: Gabe Farrell Date: Sun, 6 Apr 2025 06:55:36 -0400 Subject: [PATCH] update replace nfo --- replace_nfo.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/replace_nfo.py b/replace_nfo.py index 6bfc793..bd3a456 100755 --- a/replace_nfo.py +++ b/replace_nfo.py @@ -14,16 +14,26 @@ def parse_xml(file_path): return None def update_target_file(source_tree, target_tree): - """Update XML properties in the target file only if they exist in the source file.""" + """Update XML properties in the target file only if they exist in the source file, + and add elements from the source file that do not already exist in the target file.""" source_root = source_tree.getroot() target_root = target_tree.getroot() source_elements = {elem.tag: elem for elem in source_root} + # Update existing elements in the target file for target_elem in target_root: if target_elem.tag in source_elements: target_elem.text = source_elements[target_elem.tag].text + # Add missing elements from the source file to the target file + for source_elem in source_elements.values(): + if not any(target_elem.tag == source_elem.tag for target_elem in target_root): + # If the element is not in target, append it + target_root.append(source_elem) + + + def process_files(source_dir, target_dir): """Process all .nfo files in source_dir and update matching files in target_dir.""" source_files = glob.glob(os.path.join(source_dir, "*.nfo"))