fix: prever TMDB over radarr for release date fallbacks

This commit is contained in:
2025-09-07 13:17:16 -04:00
parent 92dc1c24de
commit 87e05a363d
2 changed files with 31 additions and 12 deletions
+30 -11
View File
@@ -690,7 +690,7 @@ def _pick_earliest(cands: List[Tuple[str, str]]) -> Optional[Tuple[str, str]]:
return cands[0]
def _pick_digital_closest_to_cinema(cands: List[Tuple[str, str]], cinema_date: Optional[str]) -> Optional[Tuple[str, str]]:
"""Pick digital release date closest to cinema date, preferring earlier over later dates"""
"""Pick digital release date closest to cinema date, with TMDB preferred over Radarr as tiebreaker"""
if not cands:
return None
if not cinema_date:
@@ -699,23 +699,37 @@ def _pick_digital_closest_to_cinema(cands: List[Tuple[str, str]], cinema_date: O
try:
cinema_dt = datetime.fromisoformat(cinema_date.replace("Z", "+00:00"))
# Sort candidates by how close they are to cinema date, preferring earlier dates
def distance_key(candidate):
# Source preference: TMDB > Jellyseerr > OMDb > Radarr
source_priority = {
"tmdb:digital": 0,
"jellyseerr:digital": 1,
"omdb:dvd": 2,
"radarr:digitalRelease": 3
}
# Sort candidates by cinema proximity first, then by source preference
def sort_key(candidate):
try:
cand_dt = datetime.fromisoformat(candidate[0].replace("Z", "+00:00"))
days_diff = (cand_dt - cinema_dt).days
days_diff = abs((cand_dt - cinema_dt).days)
# Strongly prefer dates within 5 years of cinema release
if abs(days_diff) <= 1825: # 5 years * 365 days
return abs(days_diff)
# Primary sort: distance from cinema (within 5 years preferred)
if days_diff <= 1825: # 5 years * 365 days
distance_score = days_diff
else:
# For dates far from cinema release, heavily penalize them
return abs(days_diff) + 10000
# Heavily penalize dates far from cinema release
distance_score = days_diff + 10000
# Secondary sort: source preference (lower number = higher preference)
source_score = source_priority.get(candidate[1], 99)
# Return tuple for sorting: (distance, source_priority)
return (distance_score, source_score)
except Exception:
return 999999 # Invalid dates go to the end
return (999999, 99) # Invalid dates/sources go to the end
sorted_cands = sorted(cands, key=distance_key)
sorted_cands = sorted(cands, key=sort_key)
selected = sorted_cands[0]
# Log the decision for debugging
@@ -723,6 +737,11 @@ def _pick_digital_closest_to_cinema(cands: List[Tuple[str, str]], cinema_date: O
selected_dt = datetime.fromisoformat(selected[0].replace("Z", "+00:00"))
days_diff = (selected_dt - cinema_dt).days
_log("DEBUG", f"Selected digital date {selected[0]} ({selected[1]}) - {days_diff} days from cinema date {cinema_date}")
# Show other candidates if multiple exist
if len(cands) > 1:
other_cands = [f"{c[1]}={c[0]}" for c in sorted_cands[1:3]] # Show top 2 alternatives
_log("DEBUG", f"Other candidates considered: {other_cands}")
except Exception:
pass