Merge pull request 'sonarr-all' (#32) from sonarr-all into dev
Local Docker Build (Dev) / build-dev (push) Successful in 3s
Local Docker Build (Dev) / build-dev (push) Successful in 3s
Reviewed-on: #32
This commit was merged in pull request #32.
This commit is contained in:
+29
-2
@@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user