#!/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()