From a8f8e0a7bd25f52b19b3e1fd7f09e7c2fd0de30c Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Thu, 25 Sep 2025 13:11:23 -0400 Subject: [PATCH] Fix movie webhook processing and organize NFOGuard fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix WebhookBatcher missing nfo_manager attribute that caused movie processing errors - Move NFOGuard comment from top to bottom of episode NFOs with other NFOGuard fields - All NFOGuard additions now grouped together at bottom for better organization 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- core/nfo_manager.py | 16 +++++----------- nfoguard.py | 5 +++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/core/nfo_manager.py b/core/nfo_manager.py index b6f0bd2..6e47cf2 100644 --- a/core/nfo_manager.py +++ b/core/nfo_manager.py @@ -742,22 +742,16 @@ class NFOManager: lockdata = ET.SubElement(episode, "lockdata") lockdata.text = "true" - # Add NFOGuard comment at the beginning - comment_text = f" Created by {self.manager_brand} - Source: {source} " + # Add NFOGuard comment at the bottom with other NFOGuard fields + nfoguard_comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ") + episode.append(nfoguard_comment) # Write file with proper formatting tree = ET.ElementTree(episode) ET.indent(tree, space=" ", level=0) - # Write to string first to add comment - xml_str = ET.tostring(episode, encoding='unicode') - - # Add XML declaration and comment - full_xml = f'\n\n{xml_str}' - - # Write to file - with open(nfo_path, 'w', encoding='utf-8') as f: - f.write(full_xml) + # Write to file normally (ET will handle the comment properly) + tree.write(nfo_path, encoding='utf-8', xml_declaration=True) print(f"✅ Successfully created/updated episode NFO: {nfo_path}") print(f" S{season_num:02d}E{episode_num:02d}, Aired: {aired}, Date Added: {dateadded}") diff --git a/nfoguard.py b/nfoguard.py index 16ad8ec..d255908 100644 --- a/nfoguard.py +++ b/nfoguard.py @@ -1562,12 +1562,13 @@ class MovieProcessor: class WebhookBatcher: """Batches webhook events to avoid processing storms""" - def __init__(self): + def __init__(self, nfo_manager: NFOManager): self.pending: Dict[str, Dict] = {} self.timers: Dict[str, threading.Timer] = {} self.processing: Set[str] = set() self.lock = threading.Lock() self.executor = ThreadPoolExecutor(max_workers=config.max_concurrent) + self.nfo_manager = nfo_manager def add_webhook(self, key: str, webhook_data: Dict, media_type: str): """Add webhook to batch queue""" @@ -1720,7 +1721,7 @@ nfo_manager = NFOManager(config.manager_brand, config.debug) path_mapper = PathMapper(config) # FIXED: Pass config to PathMapper tv_processor = TVProcessor(db, nfo_manager, path_mapper) movie_processor = MovieProcessor(db, nfo_manager, path_mapper) -batcher = WebhookBatcher() +batcher = WebhookBatcher(nfo_manager) # --------------------------- # Webhook Handlers