Skip to content

Commit 5d2aba2

Browse files
committed
update
1 parent 84c34c1 commit 5d2aba2

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

api.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"""
66

77
import requests
8+
import time
9+
import datetime
810
from typing import List, Dict, Any, Optional, Union
911
from utils.logger import logger, debug_log
10-
from config import API_KEY, API_URL, API_TIMEOUT
12+
from config import API_KEY, API_URL, API_TIMEOUT, MONITORED_ONLY, SKIP_FUTURE_RELEASES
1113

1214
# Create a session for reuse
1315
session = requests.Session()
@@ -62,17 +64,52 @@ def get_cutoff_unmet() -> List[Dict]:
6264
def get_missing_movies() -> List[Dict]:
6365
"""
6466
Get a list of movies that are missing files.
65-
Filters based on MONITORED_ONLY setting.
67+
Filters based on MONITORED_ONLY setting and optionally
68+
excludes future releases.
6669
"""
6770
movies = get_movies()
6871

6972
if not movies:
7073
return []
7174

72-
if MONITORED_ONLY:
73-
return [m for m in movies if m.get('monitored') and not m.get('hasFile')]
74-
else:
75-
return [m for m in movies if not m.get('hasFile')]
75+
missing_movies = []
76+
77+
# Get current date in ISO format (YYYY-MM-DD) for date comparison
78+
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
79+
80+
for movie in movies:
81+
# Skip if not missing a file
82+
if movie.get('hasFile'):
83+
continue
84+
85+
# Apply monitored filter if needed
86+
if MONITORED_ONLY and not movie.get('monitored'):
87+
continue
88+
89+
# Skip future releases if enabled
90+
if SKIP_FUTURE_RELEASES:
91+
# Check physical, digital, and cinema release dates
92+
physical_release = movie.get('physicalRelease')
93+
digital_release = movie.get('digitalRelease')
94+
in_cinemas = movie.get('inCinemas')
95+
96+
# Use the earliest available release date for comparison
97+
release_date = None
98+
if physical_release:
99+
release_date = physical_release
100+
elif digital_release:
101+
release_date = digital_release
102+
elif in_cinemas:
103+
release_date = in_cinemas
104+
105+
# Skip if release date exists and is in the future
106+
if release_date and release_date > current_date:
107+
logger.debug(f"Skipping future release '{movie.get('title')}' with date {release_date}")
108+
continue
109+
110+
missing_movies.append(movie)
111+
112+
return missing_movies
76113

77114
def refresh_movie(movie_id: int) -> Optional[Dict]:
78115
"""Refresh a movie by ID"""

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# Selection Settings
5050
RANDOM_SELECTION = os.environ.get("RANDOM_SELECTION", "true").lower() == "true"
5151
MONITORED_ONLY = os.environ.get("MONITORED_ONLY", "true").lower() == "true"
52+
SKIP_FUTURE_RELEASES = os.environ.get("SKIP_FUTURE_RELEASES", "true").lower() == "true"
5253

5354
# Hunt mode: "missing", "upgrade", or "both"
5455
HUNT_MODE = os.environ.get("HUNT_MODE", "both")
@@ -65,5 +66,6 @@ def log_configuration(logger):
6566
logger.info(f"Upgrade Configuration: HUNT_UPGRADE_MOVIES={HUNT_UPGRADE_MOVIES}")
6667
logger.info(f"State Reset Interval: {STATE_RESET_INTERVAL_HOURS} hours")
6768
logger.info(f"MONITORED_ONLY={MONITORED_ONLY}, RANDOM_SELECTION={RANDOM_SELECTION}")
69+
logger.info(f"SKIP_FUTURE_RELEASES={SKIP_FUTURE_RELEASES}")
6870
logger.info(f"HUNT_MODE={HUNT_MODE}, SLEEP_DURATION={SLEEP_DURATION}s")
6971
logger.debug(f"API_KEY={API_KEY}")

0 commit comments

Comments
 (0)