Skip to content

Commit

Permalink
Improve multi-episode and season snatches. Fixes #229
Browse files Browse the repository at this point in the history
  • Loading branch information
medariox committed Jul 15, 2018
1 parent 2244b5b commit fe095c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 39 deletions.
7 changes: 5 additions & 2 deletions medusa/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ def add_result_to_cache(self, cache):

def create_episode_object(self):
"""Use this result to create an episode segment out of it."""
if self.actual_season and self.actual_episodes and self.series:
self.episodes = [self.series.get_episode(self.actual_season, ep) for ep in self.actual_episodes]
if self.actual_season and self.series:
if self.actual_episodes:
self.episodes = [self.series.get_episode(self.actual_season, ep) for ep in self.actual_episodes]
else:
self.episodes = self.series.get_all_episodes(self.actual_season)
return self.episodes

def finish_search_result(self, provider):
Expand Down
8 changes: 4 additions & 4 deletions medusa/providers/generic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,15 @@ def find_search_results(self, series, episodes, search_mode, forced_search=False

log.debug('Found result {0} at {1}', search_result.name, search_result.url)

episode_object = search_result.create_episode_object()
search_result.create_episode_object()
# result = self.get_result(episode_object, search_result)
search_result.finish_search_result(self)

if not episode_object:
if not search_result.actual_episodes:
episode_number = SEASON_RESULT
log.debug('Found season pack result {0} at {1}', search_result.name, search_result.url)
elif len(episode_object) == 1:
episode_number = episode_object[0].episode
elif len(search_result.actual_episodes) == 1:
episode_number = search_result.actual_episode
log.debug('Found single episode result {0} at {1}', search_result.name, search_result.url)
else:
episode_number = MULTI_EP_RESULT
Expand Down
42 changes: 9 additions & 33 deletions medusa/search/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,41 +805,20 @@ def collect_multi_candidates(candidates, series_obj, episodes, down_cur_quality)
if not wanted_candidates:
return multi_candidates, single_candidates

searched_seasons = {str(x.season) for x in episodes}
main_db_con = db.DBConnection()
selection = main_db_con.select(
'SELECT episode '
'FROM tv_episodes '
'WHERE indexer = ?'
' AND showid = ?'
' AND ( season IN ( {0} ) )'.format(','.join(searched_seasons)),
[series_obj.indexer, series_obj.series_id]
)
all_eps = [int(x[b'episode']) for x in selection]
log.debug(u'Episodes list: {0}', all_eps)

for candidate in wanted_candidates:
season_quality = candidate.quality

all_wanted = True
any_wanted = False
for cur_ep_num in all_eps:
for season in {x.season for x in episodes}:
if not series_obj.want_episode(season, cur_ep_num, season_quality,
down_cur_quality):
all_wanted = False
else:
any_wanted = True
for ep_obj in candidate.episodes:
if not series_obj.want_episode(ep_obj.season, ep_obj.episode,
candidate.quality, down_cur_quality):
all_wanted = False
else:
any_wanted = True

if all_wanted:
log.info(u'All episodes in this season are needed, adding {0} {1}',
candidate.provider.provider_type,
candidate.name)
ep_objs = []
for cur_ep_num in all_eps:
for season in {x.season for x in episodes}:
ep_objs.append(series_obj.get_episode(season, cur_ep_num))
candidate.episodes = ep_objs

# Skip the result if search delay is enabled for the provider
if not delay_search(candidate):
Expand Down Expand Up @@ -871,12 +850,9 @@ def collect_multi_candidates(candidates, series_obj, episodes, down_cur_quality)
else:
log.info(u'Adding multi-episode result for full-season torrent.'
u' Undesired episodes can be skipped in the torrent client if desired!')
ep_objs = []
for cur_ep_num in all_eps:
for season in {x.season for x in episodes}:
ep_objs.append(series_obj.get_episode(season, cur_ep_num))
candidate.episodes = ep_objs
multi_candidates.append(candidate)
# Skip the result if search delay is enabled for the provider
if not delay_search(candidate):
multi_candidates.append(candidate)

return multi_candidates, single_candidates

Expand Down

0 comments on commit fe095c5

Please sign in to comment.