fix: isolate movie and TV webhook processing to prevent cross-contamination

- Add prefixed batch keys (movie:imdbid, tv:imdbid) to prevent IMDb ID collisions
- Add path existence validation for Radarr webhooks to reject invalid mappings early
- Remove duplicate Radarr webhook handler code
- Add debug scripts for troubleshooting webhook and path mapping issues
- Create corrected .env template with fixed TV_PATHS and SONARR_ROOT_FOLDERS

This fixes the issue where TV path mapping failures caused movie webhooks
to process wrong movies due to shared batch queue corruption.
This commit is contained in:
2025-09-14 12:43:07 -04:00
parent 91881262ce
commit e741e4b046
7 changed files with 384 additions and 43 deletions
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/env python3
"""
Debug script for webhook processing issue
Helps identify why wrong movies are being processed
"""
import requests
import json
import time
from datetime import datetime
def check_batch_status():
"""Check the current batch queue status"""
try:
response = requests.get("http://localhost:8080/batch/status")
if response.status_code == 200:
data = response.json()
print(f"[{datetime.now().isoformat()}] Batch Status:")
print(f" Pending batches: {data.get('pending_batches', [])}")
print(f" Active timers: {data.get('active_timers', [])}")
if 'batch_details' in data:
print(" Batch details:")
for key, details in data['batch_details'].items():
print(f" {key}: {details['movie_title']} (IMDb: {details['imdb_id']})")
print()
else:
print(f"Failed to get batch status: {response.status_code}")
except Exception as e:
print(f"Error checking batch status: {e}")
def simulate_radarr_webhook(imdb_id, title, movie_path):
"""Simulate a Radarr webhook"""
webhook_payload = {
"eventType": "Download",
"movie": {
"id": 1,
"title": title,
"imdbId": imdb_id,
"path": movie_path
},
"movieFile": {
"id": 1,
"path": f"{movie_path}/movie.mkv"
}
}
try:
print(f"[{datetime.now().isoformat()}] Sending webhook for {title} ({imdb_id})")
response = requests.post(
"http://localhost:8080/webhook/radarr",
json=webhook_payload,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
print(f" ✅ Webhook accepted: {result}")
else:
print(f" ❌ Webhook failed: {response.status_code} - {response.text}")
except Exception as e:
print(f" ❌ Error sending webhook: {e}")
def main():
print("🔍 NFOGuard Webhook Debugging Tool")
print("=" * 50)
# Check initial batch status
print("1. Initial batch queue status:")
check_batch_status()
# Send test webhook for Annabelle Comes Home
print("2. Sending test webhook for Annabelle Comes Home:")
simulate_radarr_webhook(
"tt8350360",
"Annabelle Comes Home",
"/mnt/unionfs/Media/Movies/movies6/Annabelle Comes Home (2019) [tt8350360]"
)
# Check batch status immediately after
print("3. Batch status immediately after webhook:")
check_batch_status()
# Wait for processing
print("4. Waiting 6 seconds for processing...")
time.sleep(6)
# Check final batch status
print("5. Final batch status:")
check_batch_status()
print("\n🔍 Check the NFOGuard logs to see which movie was actually processed!")
print("Expected: Annabelle Comes Home (2019) [tt8350360]")
print("If you see a different movie, there's a batching bug.")
if __name__ == "__main__":
main()