From 3787ca2d230f7914f2c37567be0b465779272cbd Mon Sep 17 00:00:00 2001 From: sbcrumb Date: Thu, 9 Oct 2025 18:11:47 -0400 Subject: [PATCH] Fix all Sonarr webhooks: Force targeted processing for single episodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extend episodeFile extraction to ALL webhook types (Download, Rename, Upgrade) - Force targeted mode when episodes_data has ≤3 episodes to prevent full series processing - Add debug logging to track episode extraction and processing mode decisions - Prevents processing 177 episodes when only 1-3 episodes are involved - Applies to imports, renames, and upgrades - not just renames - Version bump to 2.0.12 This ensures that single episode operations (most common) only process the specific episode(s) involved instead of scanning the entire series. --- VERSION | 2 +- api/routes.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 6cbacdc..280a1e3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.11 +2.0.12 diff --git a/api/routes.py b/api/routes.py index a7df1db..cd126b3 100644 --- a/api/routes.py +++ b/api/routes.py @@ -74,9 +74,11 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de # Extract episode data for targeted processing episodes_data = webhook.episodes or [] + print(f"DEBUG: Initial episodes_data from webhook.episodes: {len(episodes_data)} episodes") - # For rename events, if no episodes in webhook.episodes, try to extract from episodeFile - if webhook.eventType == "Rename" and not episodes_data and webhook.episodeFile: + # For all webhook events, if no episodes in webhook.episodes, try to extract from episodeFile + # This ensures targeted processing for single episode operations (Download, Rename, Upgrade) + if not episodes_data and webhook.episodeFile: episode_file = webhook.episodeFile # Extract season and episode from episodeFile if available season_num = episode_file.get("seasonNumber") @@ -89,7 +91,13 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de "id": episode_file.get("id"), "title": episode_file.get("title") }] - print(f"INFO: Extracted episode info from episodeFile for rename: S{season_num:02d}E{episode_num:02d}") + print(f"INFO: Extracted episode info from episodeFile for {webhook.eventType}: S{season_num:02d}E{episode_num:02d}") + + # Force targeted mode for single-episode webhooks to prevent full series processing + processing_mode = config.tv_webhook_processing_mode + if episodes_data and len(episodes_data) <= 3: # Single episode or small batch + processing_mode = "targeted" + print(f"INFO: Forcing targeted mode for {len(episodes_data)} episode(s)") # Add to batch queue with TV-prefixed key to avoid movie conflicts tv_batch_key = f"tv:{imdb_id}" @@ -98,7 +106,7 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de 'series_info': series_info, 'event_type': webhook.eventType, 'episodes': episodes_data, # Include enhanced episode data for targeted processing - 'processing_mode': config.tv_webhook_processing_mode + 'processing_mode': processing_mode # Use forced targeted mode when appropriate } batcher.add_webhook(tv_batch_key, webhook_dict, 'tv')