diff --git a/VERSION b/VERSION index 32786aa..44517d5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.18 +0.0.19 diff --git a/webhook_server.py b/webhook_server.py index 18dd0e9..17129ca 100644 --- a/webhook_server.py +++ b/webhook_server.py @@ -348,28 +348,39 @@ class RadarrClient: imdb_id = imdb_id if imdb_id.startswith("tt") else f"tt{imdb_id}" _log("DEBUG", f"Radarr API: Looking up movie by IMDb ID: {imdb_id}") - # Try direct movie search with IMDb filter (even if unreliable) + # Try getting ALL movies first, then filter by IMDb ID (more reliable) + all_movies = self._get("/api/v3/movie") + if isinstance(all_movies, list): + _log("DEBUG", f"Radarr API: Got {len(all_movies)} total movies, filtering by IMDb ID") + for movie in all_movies: + movie_imdb = movie.get("imdbId", "").lower() + if movie_imdb == imdb_id.lower(): + _log("INFO", f"Radarr API: Found exact match: {movie.get('title')} (ID: {movie.get('id')}, IMDb: {movie_imdb})") + return movie + + _log("WARNING", f"Radarr API: Movie not found in library for IMDb ID: {imdb_id}") + + # Fallback: Try direct movie search with IMDb filter res = self._get("/api/v3/movie", {"imdbId": imdb_id}) if isinstance(res, list) and len(res) > 0: # CRITICAL: Validate that returned movie actually matches requested IMDb ID for movie in res: movie_imdb = movie.get("imdbId", "").lower() if movie_imdb == imdb_id.lower(): - _log("DEBUG", f"Radarr API: Found exact match: {movie.get('title')} (ID: {movie.get('id')})") + _log("DEBUG", f"Radarr API: Found via search: {movie.get('title')} (ID: {movie.get('id')})") return movie # Log the mismatch for debugging returned_ids = [m.get("imdbId", "None") for m in res[:3]] # Show first 3 _log("ERROR", f"Radarr API returned WRONG movies for {imdb_id}! Got: {returned_ids}") - _log("DEBUG", f"Will reject mismatched results and try lookup endpoint") - # Fallback: Try lookup endpoint which might be more reliable + # Final fallback: Try lookup endpoint res = self._get("/api/v3/movie/lookup/imdb", {"imdbId": imdb_id}) if isinstance(res, dict) and res.get("imdbId", "").lower() == imdb_id.lower(): _log("DEBUG", f"Radarr API: Found movie via lookup: {res.get('title')} (ID: {res.get('id')})") return res - _log("WARNING", f"Radarr API: No valid movie found for IMDb ID: {imdb_id}") + _log("ERROR", f"Radarr API: No valid movie found for IMDb ID: {imdb_id}") return None def movie_files(self, movie_id: int) -> List[Dict[str, Any]]: @@ -460,7 +471,13 @@ class RadarrClient: if ev in import_events: # Check if this is a real import (from downloads) vs existing file rename event_data = it.get('data', {}) - source_path = event_data.get('sourcePath', '') or event_data.get('path', '') or event_data.get('sourceTitle', '') + # Prioritize droppedPath which contains the actual source directory + source_path = ( + event_data.get('droppedPath', '') or + event_data.get('sourcePath', '') or + event_data.get('path', '') or + event_data.get('sourceTitle', '') + ) _log("INFO", f"Analyzing import event '{ev}' with source: '{source_path}'") @@ -1764,8 +1781,9 @@ async def debug_movie_import_date(imdb_id: str): date_str = record.get("date", "") event_data = record.get("data", {}) - # Try multiple ways to get source path info + # Try multiple ways to get source path info - prioritize droppedPath source_path = ( + event_data.get('droppedPath', '') or # This contains the real download path! event_data.get('sourcePath', '') or event_data.get('path', '') or event_data.get('sourceTitle', '') or @@ -1777,7 +1795,7 @@ async def debug_movie_import_date(imdb_id: str): is_import_type = any(word in event_type.lower() for word in ['import', 'download']) is_from_downloads = any(indicator in source_path.lower() for indicator in [ '/downloads/', '/download/', '/completed/', '/nzbs/', '/torrents/', - 'nzbget', 'sabnzbd', 'radarr', 'completed' + 'nzbget', 'sabnzbd', 'radarr', 'completed/' ]) # Check for July 7 events specifically