diff --git a/VERSION b/VERSION index 0a69206..280a1e3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.10 +2.0.12 diff --git a/api/routes.py b/api/routes.py index ad7e582..cd126b3 100644 --- a/api/routes.py +++ b/api/routes.py @@ -72,14 +72,41 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de print(f"ERROR: Could not find series directory: {series_title} ({imdb_id})") return {"status": "error", "reason": "Series directory not found"} + # 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 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") + episode_num = episode_file.get("episodeNumber") + if season_num and episode_num: + # Create episode data structure that matches what process_webhook_episodes expects + episodes_data = [{ + "seasonNumber": season_num, + "episodeNumber": episode_num, + "id": episode_file.get("id"), + "title": episode_file.get("title") + }] + 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}" webhook_dict = { 'path': str(series_path), 'series_info': series_info, 'event_type': webhook.eventType, - 'episodes': webhook.episodes or [], # Include episode data for targeted processing - 'processing_mode': config.tv_webhook_processing_mode + 'episodes': episodes_data, # Include enhanced episode data for targeted processing + 'processing_mode': processing_mode # Use forced targeted mode when appropriate } batcher.add_webhook(tv_batch_key, webhook_dict, 'tv')