chore:fix radarr date issue

This commit is contained in:
2025-09-07 12:13:30 -04:00
committed by sbcrumb
parent 4680448b89
commit 5866713e1b
2 changed files with 34 additions and 7 deletions
+1 -1
View File
@@ -1 +1 @@
0.0.4
0.0.5
+33 -6
View File
@@ -277,12 +277,22 @@ class RadarrClient:
def movie_by_imdb(self, imdb_id: str) -> Optional[Dict[str, Any]]:
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 first
res = self._get("/api/v3/movie", {"imdbId": imdb_id})
if isinstance(res, list) and res:
return res[0]
movie = res[0]
_log("DEBUG", f"Radarr API: Found movie via direct search: {movie.get('title')} (ID: {movie.get('id')})")
return movie
# Try lookup endpoint
res = self._get("/api/v3/movie/lookup/imdb", {"imdbId": imdb_id})
if isinstance(res, dict) and res.get("id"):
_log("DEBUG", f"Radarr API: Found movie via lookup: {res.get('title')} (ID: {res.get('id')})")
return res
_log("DEBUG", f"Radarr API: No movie found for IMDb ID: {imdb_id}")
return None
def movie_files(self, movie_id: int) -> List[Dict[str, Any]]:
@@ -672,10 +682,13 @@ def _decide_movie_date(imdb_id: str, movie_dir: Path, poll_external: bool) -> Tu
Returns: (dateadded_iso, source_detail, released_iso)
"""
# Initialize fresh variables for each movie
released_iso: Optional[str] = None
movie_obj: Optional[Dict[str, Any]] = None
movie_id: Optional[int] = None
_log("DEBUG", f"Starting date selection for {imdb_id} - fresh state initialized")
def from_file_mtime() -> Tuple[Optional[str], str]:
video_exts = (".mkv", ".mp4", ".avi", ".mov", ".m4v")
newest = None
@@ -698,27 +711,39 @@ def _decide_movie_date(imdb_id: str, movie_dir: Path, poll_external: bool) -> Tu
def ensure_movie():
nonlocal movie_obj, movie_id, released_iso
if movie_obj is None and poll_external and config.radarr_url and config.radarr_api_key:
_log("DEBUG", f"Looking up Radarr movie for IMDb ID: {imdb_id}")
movie_obj = _radarr_movie_by_imdb(imdb_id)
if movie_obj:
movie_id = movie_obj.get("id")
movie_title = movie_obj.get("title", "Unknown")
movie_imdb = movie_obj.get("imdbId", "Unknown")
_log("INFO", f"Found Radarr movie: {movie_title} (ID: {movie_id}, IMDb: {movie_imdb}) for requested {imdb_id}")
released_iso = _parse_date_to_iso(movie_obj.get("inCinemas") or movie_obj.get("theatricalRelease"))
else:
movie_id = None # Explicitly set to None when movie not found
movie_obj = None
_log("WARNING", f"No Radarr movie found for IMDb ID: {imdb_id} - will skip import history")
def from_import_history() -> Tuple[Optional[str], str]:
ensure_movie()
if not (poll_external and movie_id):
_log("DEBUG", f"Skipping import history: poll_external={poll_external}, movie_id={movie_id}")
if not poll_external:
_log("DEBUG", f"Skipping import history: poll_external={poll_external}")
return None, "radarr:history.skipped"
if not movie_id:
_log("DEBUG", f"Skipping import history: movie not found in Radarr for {imdb_id}")
return None, "radarr:movie.not_found"
# Try import history events first (most reliable)
iso = _radarr_earliest_import_history_iso(movie_id)
if iso:
_log("INFO", f"Using Radarr import history date: {iso}")
_log("INFO", f"Using Radarr import history date: {iso} for movie_id {movie_id} (IMDb: {imdb_id})")
return iso, "radarr:history.import"
# Fallback to moviefile dateAdded
iso2 = _radarr_earliest_file_dateadded_iso(movie_id)
if iso2:
_log("INFO", f"Using Radarr moviefile dateAdded: {iso2}")
_log("INFO", f"Using Radarr moviefile dateAdded: {iso2} for movie_id {movie_id}")
return iso2, "radarr:moviefile.dateAdded"
_log("WARNING", f"No import dates found for movie_id {movie_id}")
@@ -843,7 +868,9 @@ def _decide_movie_date(imdb_id: str, movie_dir: Path, poll_external: bool) -> Tu
def parse_imdb_from_movie_path(p: Path) -> Optional[str]:
m = re.search(r'\[imdb-(tt\d+)\]', p.name, re.IGNORECASE)
return m.group(1).lower() if m else None
imdb_id = m.group(1).lower() if m else None
_log("DEBUG", f"Parsed IMDb ID from path '{p.name}': {imdb_id}")
return imdb_id
def is_movie_dir(p: Path) -> bool:
return p.is_dir() and parse_imdb_from_movie_path(p) is not None