imdb updates

This commit is contained in:
2025-09-09 17:13:14 -04:00
parent 8be7452f0e
commit afe93b4a8a
4 changed files with 90 additions and 9 deletions
+47 -1
View File
@@ -249,6 +249,47 @@ class RadarrDbClient:
_log("ERROR", f"Database query error for movie {movie_id}: {e}")
return None, "radarr:db.no_date_found"
def is_first_event_rename_based(self, movie_id: int) -> bool:
"""
Check if the first event in history is rename-based (not a true import)
This helps identify movies where:
- First event: movieFileRenamed (EventType = 7)
- Followed by: downloadFolderImported (EventType = 3) - this is an upgrade
In such cases, we should prefer release dates over the upgrade date
"""
query = """
SELECT h."EventType" as event_type
FROM "History" h
WHERE h."MovieId" = %s
ORDER BY h."Date" ASC
LIMIT 1
"""
if self.db_type == "sqlite":
query = query.replace("%s", "?")
try:
with self._get_connection() as conn:
if self.db_type == "postgresql":
cursor = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
else:
cursor = conn.cursor()
cursor.execute(query, (movie_id,))
row = cursor.fetchone()
if row:
event_type = row['event_type'] if self.db_type == "postgresql" else row[0]
# EventType 7 = movieFileRenamed
return event_type == 7
except Exception as e:
_log("DEBUG", f"Error checking first event type for movie {movie_id}: {e}")
return False
def get_movie_file_date(self, movie_id: int) -> Optional[str]:
"""
@@ -305,11 +346,16 @@ class RadarrDbClient:
Returns:
(date_iso, source_description)
"""
# Try history first
# Try history first - always check for true import dates
date_iso, source = self.get_earliest_import_date(movie_id)
if date_iso:
return date_iso, source
# If no true import found, check if first event is rename-based (upgrade scenario)
if self.is_first_event_rename_based(movie_id):
_log("INFO", f"Movie {movie_id} has rename-first history with no true import - signaling to prefer release dates")
return None, "radarr:db.prefer_release_dates"
# Fallback to file date if requested
if fallback_to_file_date:
file_date = self.get_movie_file_date(movie_id)