From 282717314a7af4c2b0505f7b1afd6e2f1fc0df99 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Mon, 8 Sep 2025 10:55:03 -0400 Subject: [PATCH] api updates --- VERSION | 2 +- clients/radarr_client.py | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 7179039..abd4105 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.3 +0.2.4 diff --git a/clients/radarr_client.py b/clients/radarr_client.py index 62e7bd2..fd2ae1f 100644 --- a/clients/radarr_client.py +++ b/clients/radarr_client.py @@ -125,10 +125,14 @@ class RadarrClient: _log("ERROR", f"No movie found for IMDb ID: {imdb_id}") return None - def _analyze_event_for_import(self, event: Dict[str, Any]) -> Tuple[bool, str, Optional[str]]: + def _analyze_event_for_import(self, event: Dict[str, Any], movie_info: Dict[str, Any] = None) -> Tuple[bool, str, Optional[str]]: """ Analyze a history event to determine if it's a real import. + Args: + event: The history event to analyze + movie_info: Optional movie information to validate paths against + Returns: (is_real_import, reason, date_iso) """ @@ -179,6 +183,11 @@ class RadarrClient: """ _log("INFO", f"Finding earliest import for movie_id {movie_id}") + # Get movie info for path validation + movie_info = self._get("/api/v3/movie", {"movieId": movie_id}) + if isinstance(movie_info, list) and movie_info: + movie_info = movie_info[0] + earliest_real_import = None first_grab = None page = 1 @@ -217,11 +226,17 @@ class RadarrClient: pass # Analyze for real import - is_real, reason, date_iso = self._analyze_event_for_import(event) + is_real, reason, date_iso = self._analyze_event_for_import(event, movie_info) if is_real and date_iso: - _log("INFO", f"✅ FOUND REAL IMPORT: {event_type} at {date_iso} - {reason}") - earliest_real_import = date_iso + source_path = (event.get("data", {}).get("sourcePath") or "").lower() + source_title = (event.get("data", {}).get("sourceTitle") or "").lower() + + if movie_info and (movie_info.get("imdbId") or "").lower() in (source_path + source_title): + _log("INFO", f"✅ FOUND REAL IMPORT: {event_type} at {date_iso} - {reason} (path validated)") + earliest_real_import = date_iso + else: + _log("DEBUG", f"⚠️ Skipping import - path validation failed") # We found a real import - we can stop here since events are chronologically ordered break elif event_type in self.REAL_IMPORT_EVENTS: