Skip to content

Commit

Permalink
skip search attempt if media has not been released
Browse files Browse the repository at this point in the history
  • Loading branch information
lardbit committed Nov 5, 2024
1 parent 25ca2d5 commit 2ab1fe1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/nefarious/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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 = {
Expand Down
13 changes: 10 additions & 3 deletions src/nefarious/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2ab1fe1

Please sign in to comment.