Fix TV rename webhooks: Implement targeted episode processing
- Extract episode info from episodeFile when webhook.episodes is empty for rename events - Create proper episode data structure for process_webhook_episodes method - Prevents full series processing (177 episodes) for single episode renames - Dramatically improves performance for rename operations - Version bump to 2.0.11 Resolves issue where rename webhooks were falling back to full series processing instead of targeted mode.
This commit is contained in:
+20
-1
@@ -72,13 +72,32 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de
|
|||||||
print(f"ERROR: Could not find series directory: {series_title} ({imdb_id})")
|
print(f"ERROR: Could not find series directory: {series_title} ({imdb_id})")
|
||||||
return {"status": "error", "reason": "Series directory not found"}
|
return {"status": "error", "reason": "Series directory not found"}
|
||||||
|
|
||||||
|
# Extract episode data for targeted processing
|
||||||
|
episodes_data = webhook.episodes or []
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
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 rename: S{season_num:02d}E{episode_num:02d}")
|
||||||
|
|
||||||
# Add to batch queue with TV-prefixed key to avoid movie conflicts
|
# Add to batch queue with TV-prefixed key to avoid movie conflicts
|
||||||
tv_batch_key = f"tv:{imdb_id}"
|
tv_batch_key = f"tv:{imdb_id}"
|
||||||
webhook_dict = {
|
webhook_dict = {
|
||||||
'path': str(series_path),
|
'path': str(series_path),
|
||||||
'series_info': series_info,
|
'series_info': series_info,
|
||||||
'event_type': webhook.eventType,
|
'event_type': webhook.eventType,
|
||||||
'episodes': webhook.episodes or [], # Include episode data for targeted processing
|
'episodes': episodes_data, # Include enhanced episode data for targeted processing
|
||||||
'processing_mode': config.tv_webhook_processing_mode
|
'processing_mode': config.tv_webhook_processing_mode
|
||||||
}
|
}
|
||||||
batcher.add_webhook(tv_batch_key, webhook_dict, 'tv')
|
batcher.add_webhook(tv_batch_key, webhook_dict, 'tv')
|
||||||
|
|||||||
Reference in New Issue
Block a user