From 27cc2f878e7de270c149d089c7d5eaa94afd337a Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Sun, 14 Sep 2025 12:56:47 -0400 Subject: [PATCH] update movie paths --- commit_webhook_path_fix.sh | 55 ++++++++++++++++++++++++++++++++++++++ nfoguard.py | 36 ++++++++++++++----------- 2 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 commit_webhook_path_fix.sh diff --git a/commit_webhook_path_fix.sh b/commit_webhook_path_fix.sh new file mode 100644 index 0000000..b71bce7 --- /dev/null +++ b/commit_webhook_path_fix.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Git commit script for webhook path resolution fixes + +echo "🔧 Adding files to git..." +git add nfoguard.py +git add SUMMARY.md +git add VERSION +git add debug_webhook_isolation.py +git add .env.fixed + +echo "📝 Committing changes..." +git commit -m "fix: resolve Radarr webhook path variable bug and enhance validation + +## Critical Bug Fix +- Fixed 'container_path' undefined variable error in Radarr webhook handler +- Webhook now properly handles both 'folderPath' and 'path' fields +- Added mandatory path validation before processing + +## Enhanced Webhook Validation +- Verify mapped paths exist before batch processing +- Add IMDb ID validation in batch processor to prevent wrong movie processing +- Improved error logging with specific failure reasons + +## Path Mapping Improvements +- Support both folderPath (new Radarr format) and path (legacy) fields +- Early rejection of webhooks with invalid path mappings +- Better error messages for debugging path issues + +## Version & Documentation Updates +- Bump version to v1.3.1 with comprehensive changelog +- Updated SUMMARY.md with detailed webhook isolation analysis +- Added debug script for testing webhook processing + +## Fixes Issue +The webhook was failing with 'cannot access local variable container_path' +because folderPath wasn't being handled, causing the validation block to +reference an undefined variable. + +## Test Results +✅ Webhook accepts valid paths and processes correct movies +✅ Webhook rejects invalid paths early to prevent wrong processing +✅ Batch validation ensures IMDb ID matches path before processing +✅ No more Annabelle → Harry Potter cross-processing bugs" + +echo "✅ Commit completed!" +echo "" +echo "📋 Files committed:" +echo " • nfoguard.py (webhook path bug fix + validation)" +echo " • SUMMARY.md (comprehensive analysis + v1.3.1 details)" +echo " • VERSION (bumped to 1.3.1)" +echo " • debug_webhook_isolation.py (testing tool)" +echo " • .env.fixed (corrected configuration template)" +echo "" +echo "🚀 Ready to push! Run:" +echo " git push origin main" \ No newline at end of file diff --git a/nfoguard.py b/nfoguard.py index 46f2575..96fd535 100644 --- a/nfoguard.py +++ b/nfoguard.py @@ -1474,22 +1474,26 @@ async def radarr_webhook(request: Request, background_tasks: BackgroundTasks): _log("WARNING", "No IMDb ID in Radarr webhook movie data") return {"status": "error", "message": "No IMDb ID"} - # Get movie path for verification - movie_path = movie_data.get("path", "") - if movie_path: - container_path = path_mapper.radarr_path_to_container_path(movie_path) - _log("DEBUG", f"Mapped Radarr path {movie_path} -> {container_path}") - - # CRITICAL: Verify the mapped path actually exists - from pathlib import Path - if not Path(container_path).exists(): - _log("ERROR", f"RADARR WEBHOOK REJECTED: Mapped path does not exist: {container_path}") - _log("ERROR", f"This prevents processing wrong movies due to path mapping issues") - return {"status": "error", "message": f"Mapped movie path does not exist: {container_path}"} - - # Verify the path contains the expected IMDb ID - if imdb_id not in container_path.lower(): - _log("WARNING", f"IMDb ID {imdb_id} not found in container path {container_path}") + # Get movie path and map it + movie_path = movie_data.get("folderPath") or movie_data.get("path", "") + if not movie_path: + _log("ERROR", "No movie path in Radarr webhook") + return {"status": "error", "message": "No movie path provided"} + + # Map the path to container path + container_path = path_mapper.radarr_path_to_container_path(movie_path) + _log("DEBUG", f"Mapped Radarr path {movie_path} -> {container_path}") + + # CRITICAL: Verify the mapped path actually exists + from pathlib import Path + if not Path(container_path).exists(): + _log("ERROR", f"RADARR WEBHOOK REJECTED: Mapped path does not exist: {container_path}") + _log("ERROR", f"This prevents processing wrong movies due to path mapping issues") + return {"status": "error", "message": f"Mapped movie path does not exist: {container_path}"} + + # Verify the path contains the expected IMDb ID + if imdb_id not in container_path.lower(): + _log("WARNING", f"IMDb ID {imdb_id} not found in container path {container_path}") # Create movie-specific webhook data with proper path validation movie_webhook_data = {