Skip to content

Commit 2ab1fe1

Browse files
committed
skip search attempt if media has not been released
1 parent 25ca2d5 commit 2ab1fe1

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/nefarious/processors.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
class WatchProcessorBase:
21-
watch_media = None
21+
watch_media: WatchMovie | WatchTVEpisode | WatchTVSeason = None
2222
nefarious_settings: NefariousSettings = None
2323
_reprocess_without_possessive_apostrophes = False
2424
_possessive_apostrophes_regex = regex.compile(r"(?!\w)'s\b", regex.I)
@@ -36,6 +36,13 @@ def __init__(self, watch_media_id: int):
3636

3737
def fetch(self):
3838
logger_background.info('Processing request to watch {}'.format(self._sanitize_title(str(self.watch_media))))
39+
40+
# skip attempt if media hasn't been released yet
41+
if self.watch_media.release_date and self.watch_media.release_date > datetime.now().date():
42+
logger_background.warning('skipping search for "{}" since it has not been released yet ({})'.format(
43+
self.watch_media, self.watch_media.release_date))
44+
return
45+
3946
valid_search_results = []
4047
search = self._get_search_results()
4148

@@ -299,7 +306,7 @@ def _get_tmdb_media(self):
299306

300307
def _get_search_results(self):
301308
# query the show name AND the season/episode name separately
302-
# i.e search for "Atlanta" and "Atlanta s01e05" individually for best results
309+
# i.e. search for "Atlanta" and "Atlanta s01e05" individually for best results
303310
watch_episode = self.watch_media # type: WatchTVEpisode
304311
show_result = self.tmdb_client.TV(watch_episode.watch_tv_show.tmdb_show_id)
305312
params = {

src/nefarious/tasks.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ def log_exception(**kwargs):
6868
@app.task(base=QueueOnce, once={'graceful': True})
6969
def watch_tv_show_season_task(watch_tv_season_id: int):
7070
processor = WatchTVSeasonProcessor(watch_media_id=watch_tv_season_id)
71-
success = processor.fetch()
72-
7371
watch_tv_season = get_object_or_404(WatchTVSeason, pk=watch_tv_season_id)
7472

73+
# skip attempt if media hasn't been released yet
74+
if watch_tv_season.release_date and watch_tv_season.release_date > datetime.now().date():
75+
logger_background.warning('skipping search for tv season "{}" since it has not been released yet ({})'.format(
76+
watch_tv_season, watch_tv_season.release_date))
77+
return
78+
79+
# make attempt
80+
success = processor.fetch()
81+
7582
# success so update the season request instance as "collected"
7683
if success:
7784
season_request = WatchTVSeasonRequest.objects.filter(
@@ -294,7 +301,7 @@ def wanted_media_task():
294301

295302
for media_type, data in wanted_media_data.items():
296303
for media in data['query']:
297-
# media has been released (or it's missing it's release date so try anyway) so create a task to try and fetch it
304+
# media has been released (or it's missing its release date so try anyway) so create a task to try and fetch it
298305
if not media.release_date or media.release_date <= today:
299306
logger_background.info('Wanted {type}: {media}'.format(type=media_type, media=media))
300307
# queue task for wanted media

0 commit comments

Comments
 (0)