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
+1 -1
View File
@@ -1 +1 @@
0.0.11 0.0.12
+30 -11
View File
@@ -690,7 +690,7 @@ def _pick_earliest(cands: List[Tuple[str, str]]) -> Optional[Tuple[str, str]]:
return cands[0] return cands[0]
def _pick_digital_closest_to_cinema(cands: List[Tuple[str, str]], cinema_date: Optional[str]) -> Optional[Tuple[str, str]]: 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: if not cands:
return None return None
if not cinema_date: if not cinema_date:
@@ -699,23 +699,37 @@ def _pick_digital_closest_to_cinema(cands: List[Tuple[str, str]], cinema_date: O
try: try:
cinema_dt = datetime.fromisoformat(cinema_date.replace("Z", "+00:00")) cinema_dt = datetime.fromisoformat(cinema_date.replace("Z", "+00:00"))
# Sort candidates by how close they are to cinema date, preferring earlier dates # Source preference: TMDB > Jellyseerr > OMDb > Radarr
def distance_key(candidate): 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: try:
cand_dt = datetime.fromisoformat(candidate[0].replace("Z", "+00:00")) 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 # Primary sort: distance from cinema (within 5 years preferred)
if abs(days_diff) <= 1825: # 5 years * 365 days if days_diff <= 1825: # 5 years * 365 days
return abs(days_diff) distance_score = days_diff
else: else:
# For dates far from cinema release, heavily penalize them # Heavily penalize dates far from cinema release
return abs(days_diff) + 10000 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: 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] selected = sorted_cands[0]
# Log the decision for debugging # 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")) selected_dt = datetime.fromisoformat(selected[0].replace("Z", "+00:00"))
days_diff = (selected_dt - cinema_dt).days 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}") _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: except Exception:
pass pass