diff --git a/VERSION b/VERSION index 1c09c74..42045ac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.3 +0.3.4 diff --git a/clients/radarr_client.py b/clients/radarr_client.py index 3dd7a2d..ba83def 100644 --- a/clients/radarr_client.py +++ b/clients/radarr_client.py @@ -274,42 +274,53 @@ class RadarrClient: except Exception: pass - # For moviefileimported events, handle specially + # For import/download events, handle specially + imported_path = None + # Try different sources for the path if event_type == "moviefileimported": imported_path = (event.get("data", {}).get("importedPath", "") or - event.get("data", {}).get("path", "") or - event.get("importedPath", "") or - event.get("sourcePath", "")).lower() - - if imported_path: - _log("DEBUG", f"Found moviefileimported event with path: {imported_path}") - movie_imdb = (movie_info.get("imdbId", "") or "").lower() - movie_title = (movie_info.get("title", "") or "").lower() - movie_year = str(movie_info.get("year", "")) + event.get("data", {}).get("path", "") or + event.get("importedPath", "") or + event.get("sourcePath", "")).lower() + elif event_type == "downloadFolderImported": + imported_path = (event.get("data", {}).get("path", "") or + event.get("sourcePath", "") or + event.get("downloadPath", "")).lower() + + if imported_path: + _log("DEBUG", f"Found potential import event ({event_type}) with path: {imported_path}") + movie_imdb = (movie_info.get("imdbId", "") or "").lower() + movie_title = (movie_info.get("title", "") or "").lower() + movie_year = str(movie_info.get("year", "")) + + # First try IMDb ID match + if movie_imdb and ( + f"[imdb-{movie_imdb}]" in imported_path or + f"[{movie_imdb}]" in imported_path or + movie_imdb in imported_path + ): + date_iso = datetime.fromisoformat(event["date"].replace("Z", "+00:00")).astimezone(timezone.utc).isoformat(timespec="seconds") + _log("INFO", f"✅ FOUND IMPORT: exact IMDb match at {date_iso}") + earliest_real_import = date_iso + break + + # Then try title/year match with fuzzy path cleaning + if movie_title and movie_year: + # Clean strings for comparison by replacing common separators + clean_title = movie_title.replace(" ", ".").replace(":", ".").replace("-", ".").replace("_", ".").lower() + clean_path = imported_path.replace(" ", ".").replace("-", ".").replace("_", ".").replace("[", "").replace("]", "").lower() - # First try IMDb ID match - if movie_imdb and ( - f"[imdb-{movie_imdb}]" in imported_path or - f"[{movie_imdb}]" in imported_path or - movie_imdb in imported_path - ): + # Remove common words for better matching + for word in ["the", "a", "an"]: + clean_title = clean_title.replace(f".{word}.", ".").replace(f"{word}.", "").replace(f".{word}", "") + clean_path = clean_path.replace(f".{word}.", ".").replace(f"{word}.", "").replace(f".{word}", "") + + # Look for both title and year + if clean_title in clean_path and movie_year in clean_path: date_iso = datetime.fromisoformat(event["date"].replace("Z", "+00:00")).astimezone(timezone.utc).isoformat(timespec="seconds") - _log("INFO", f"✅ FOUND IMPORT: exact IMDb match at {date_iso}") + _log("INFO", f"✅ FOUND IMPORT: title/year match at {date_iso}") earliest_real_import = date_iso break - - # Then try title/year match - if movie_title and movie_year: - # Clean strings for comparison - clean_title = movie_title.replace(" ", ".").replace(":", ".").lower() - clean_path = imported_path.replace(" ", ".").replace("-", ".").replace("_", ".").lower() - - # Look for both title and year - if clean_title in clean_path and movie_year in clean_path: - date_iso = datetime.fromisoformat(event["date"].replace("Z", "+00:00")).astimezone(timezone.utc).isoformat(timespec="seconds") - _log("INFO", f"✅ FOUND IMPORT: title/year match at {date_iso}") - earliest_real_import = date_iso - break # Fallback to normal import analysis is_real, reason, date_iso = self._analyze_event_for_import(event, movie_info)