diff --git a/src/nefarious/processors.py b/src/nefarious/processors.py index 9141e5c2..790fab96 100644 --- a/src/nefarious/processors.py +++ b/src/nefarious/processors.py @@ -18,7 +18,7 @@ class WatchProcessorBase: - watch_media = None + watch_media: WatchMovie | WatchTVEpisode | WatchTVSeason = None nefarious_settings: NefariousSettings = None _reprocess_without_possessive_apostrophes = False _possessive_apostrophes_regex = regex.compile(r"(?!\w)'s\b", regex.I) @@ -36,6 +36,13 @@ def __init__(self, watch_media_id: int): def fetch(self): logger_background.info('Processing request to watch {}'.format(self._sanitize_title(str(self.watch_media)))) + + # skip attempt if media hasn't been released yet + if self.watch_media.release_date and self.watch_media.release_date > datetime.now().date(): + logger_background.warning('skipping search for "{}" since it has not been released yet ({})'.format( + self.watch_media, self.watch_media.release_date)) + return + valid_search_results = [] search = self._get_search_results() @@ -299,7 +306,7 @@ def _get_tmdb_media(self): def _get_search_results(self): # query the show name AND the season/episode name separately - # i.e search for "Atlanta" and "Atlanta s01e05" individually for best results + # i.e. search for "Atlanta" and "Atlanta s01e05" individually for best results watch_episode = self.watch_media # type: WatchTVEpisode show_result = self.tmdb_client.TV(watch_episode.watch_tv_show.tmdb_show_id) params = { diff --git a/src/nefarious/tasks.py b/src/nefarious/tasks.py index 8bb63d06..6f1c06c4 100644 --- a/src/nefarious/tasks.py +++ b/src/nefarious/tasks.py @@ -68,10 +68,17 @@ def log_exception(**kwargs): @app.task(base=QueueOnce, once={'graceful': True}) def watch_tv_show_season_task(watch_tv_season_id: int): processor = WatchTVSeasonProcessor(watch_media_id=watch_tv_season_id) - success = processor.fetch() - watch_tv_season = get_object_or_404(WatchTVSeason, pk=watch_tv_season_id) + # skip attempt if media hasn't been released yet + if watch_tv_season.release_date and watch_tv_season.release_date > datetime.now().date(): + logger_background.warning('skipping search for tv season "{}" since it has not been released yet ({})'.format( + watch_tv_season, watch_tv_season.release_date)) + return + + # make attempt + success = processor.fetch() + # success so update the season request instance as "collected" if success: season_request = WatchTVSeasonRequest.objects.filter( @@ -294,7 +301,7 @@ def wanted_media_task(): for media_type, data in wanted_media_data.items(): for media in data['query']: - # media has been released (or it's missing it's release date so try anyway) so create a task to try and fetch it + # media has been released (or it's missing its release date so try anyway) so create a task to try and fetch it if not media.release_date or media.release_date <= today: logger_background.info('Wanted {type}: {media}'.format(type=media_type, media=media)) # queue task for wanted media