From 5cc237461c6686c2198c6076203aea3fdcc8951b Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Mon, 8 Sep 2025 10:21:38 -0400 Subject: [PATCH] updates for debug scan --- README.md | 37 +++++++++++++++++++++--- VERSION | 2 +- nfoguard.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3410348..302bd3d 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,13 @@ POST /webhook/sonarr – Sonarr events POST /webhook/radarr – Radarr events -POST /manual/scan – Manual scan (TV + Movies) +POST /manual/scan?scan_type=both – Manual scan (TV + Movies) [DEFAULT] -POST /manual/scan/tv – Manual scan TV only +POST /manual/scan?scan_type=tv – Manual scan TV only -POST /manual/scan/movies – Manual scan Movies only +POST /manual/scan?scan_type=movies – Manual scan Movies only + +POST /manual/scan?path=/media/movies – Manual scan specific path GET /health – Health check @@ -89,6 +91,8 @@ GET /stats – Database stats GET /batch/status – Current batch queue +GET /debug/movie/{imdb_id} – Debug movie import date detection + 📖 Example Workflow You add The Blacklist in Sonarr. @@ -100,7 +104,32 @@ NFOGuard updates the .nfo and mtime, but keeps the original import date. Emby/Jellyfin/Plex see the file as unchanged in chronology. -Result: no more “old shows” showing up in “Recently Added.” +Result: no more "old shows" showing up in "Recently Added." + +🔍 Logging & Debugging +# Enable verbose logging +DEBUG=true + +# Check container logs +docker logs sonarr-nfo-cache + +# Debug specific movie import detection +curl http://localhost:8080/debug/movie/tt1674782 + +# Manual scan with verbose output +curl -X POST "http://localhost:8080/manual/scan?scan_type=movies" + +# File logs (inside container) +/app/data/logs/nfoguard.log + +⚙️ Environment Variables (v0.2.1+) +Variable Default Description +RADARR_ROOT_FOLDERS (required) What Radarr sees: /mnt/unionfs/Media/Movies/movies +SONARR_ROOT_FOLDERS (required) What Sonarr sees: /mnt/unionfs/Media/TV/tv +DOWNLOAD_PATH_INDICATORS (see example) Paths that indicate downloads vs existing files +MOVIE_PRIORITY import_then_digital Strategy: import_then_digital or digital_then_import +MOVIE_POLL_MODE always When to query APIs: always, if_missing, never +MOVIE_DATE_UPDATE_MODE backfill_only Update behavior: backfill_only or overwrite 📜 License MIT License – do what you want, just don’t blame us if your timestamps go timey-wimey. \ No newline at end of file diff --git a/VERSION b/VERSION index 0c62199..ee1372d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.1 +0.2.2 diff --git a/nfoguard.py b/nfoguard.py index 179487a..c851ff2 100644 --- a/nfoguard.py +++ b/nfoguard.py @@ -798,6 +798,84 @@ async def batch_status(): """Get batch queue status""" return batcher.get_status() +@app.get("/debug/movie/{imdb_id}") +async def debug_movie_import_date(imdb_id: str): + """Debug endpoint to analyze movie import date detection""" + try: + if not imdb_id.startswith("tt"): + imdb_id = f"tt{imdb_id}" + + _log("INFO", f"=== DEBUG MOVIE IMPORT DATE: {imdb_id} ===") + + if not (os.environ.get("RADARR_URL") and os.environ.get("RADARR_API_KEY")): + return { + "error": "Radarr not configured", + "imdb_id": imdb_id, + "radarr_configured": False + } + + # Create Radarr client + from clients.radarr_client import RadarrClient + radarr_client = RadarrClient( + os.environ.get("RADARR_URL"), + os.environ.get("RADARR_API_KEY") + ) + + # Look up movie + movie_obj = radarr_client.movie_by_imdb(imdb_id) + if not movie_obj: + return { + "error": f"Movie not found in Radarr for IMDb ID {imdb_id}", + "imdb_id": imdb_id, + "radarr_configured": True, + "movie_found": False + } + + movie_id = movie_obj.get("id") + movie_title = movie_obj.get("title") + + _log("INFO", f"Found movie: {movie_title} (Radarr ID: {movie_id})") + + # Get import date with detailed logging + import_date, source = radarr_client.get_movie_import_date(movie_id) + + # Get movie files + movie_files = radarr_client.movie_files(movie_id) + file_info = [] + for f in movie_files: + file_info.append({ + "id": f.get("id"), + "relativePath": f.get("relativePath"), + "dateAdded": f.get("dateAdded"), + "quality": f.get("quality", {}).get("quality", {}).get("name", "Unknown") + }) + + return { + "imdb_id": imdb_id, + "radarr_configured": True, + "movie_found": True, + "movie_title": movie_title, + "movie_id": movie_id, + "detected_import_date": import_date, + "import_source": source, + "movie_files": file_info, + "debug_info": { + "radarr_url": os.environ.get("RADARR_URL"), + "movie_digital_release": movie_obj.get("digitalRelease"), + "movie_in_cinemas": movie_obj.get("inCinemas"), + "movie_physical_release": movie_obj.get("physicalRelease"), + "movie_folder_path": movie_obj.get("folderPath") + } + } + + except Exception as e: + _log("ERROR", f"Debug endpoint error for {imdb_id}: {e}") + return { + "error": str(e), + "imdb_id": imdb_id, + "success": False + } + @app.post("/manual/scan") async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = None, scan_type: str = "both"): """Manual scan endpoint""" @@ -827,12 +905,17 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N _log("ERROR", f"Failed processing TV series {item}: {e}") if scan_type in ["both", "movies"] and scan_path in config.movie_paths: + _log("INFO", f"Scanning movies in: {scan_path}") + movie_count = 0 for item in scan_path.iterdir(): if item.is_dir() and nfo_manager.parse_imdb_from_path(item): + movie_count += 1 + _log("INFO", f"Processing movie: {item.name}") try: movie_processor.process_movie(item) except Exception as e: _log("ERROR", f"Failed processing movie {item}: {e}") + _log("INFO", f"Completed movie scan: {movie_count} movies processed in {scan_path}") background_tasks.add_task(run_scan) return {"status": "started", "message": f"Manual {scan_type} scan started"}