From 2811d30352ab05d3d22a1e0cd37c0a599bef72e0 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Sat, 25 Oct 2025 12:27:52 -0400 Subject: [PATCH] fix: not using airdate when rename is first event in sonarr --- clients/sonarr_client.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clients/sonarr_client.py b/clients/sonarr_client.py index 0985662..7805383 100644 --- a/clients/sonarr_client.py +++ b/clients/sonarr_client.py @@ -222,7 +222,7 @@ class SonarrClient: import_date = earliest_import["date"] _log("INFO", f"Found import date: {import_date} for episode {episode_id}") - # Check if this looks like an upgrade by comparing to renames + # Check if this import is likely a recent re-download/upgrade if rename_events: earliest_rename = min(rename_events, key=lambda x: x["date"]) rename_date = earliest_rename["date"] @@ -232,10 +232,12 @@ class SonarrClient: rename_dt = datetime.fromisoformat(rename_date.replace("Z", "+00:00")) days_diff = (import_dt - rename_dt).days - # If import is significantly after rename, prefer rename date + # If import is significantly after rename, this is likely a re-download + # The original import likely happened much earlier (possibly lost from history) + # Return None to trigger aired date fallback instead of using rename date if days_diff > 30: - _log("WARNING", f"Import {import_date} is {days_diff} days after rename {rename_date} - using rename date") - return rename_date + _log("WARNING", f"Import {import_date} is {days_diff} days after rename {rename_date} - this looks like a re-download, using aired date fallback") + return None # Trigger aired date fallback except Exception as e: _log("DEBUG", f"Error comparing dates: {e}")