From e5c203f2f267a7e2bc640eedb20c1b51919b8cd0 Mon Sep 17 00:00:00 2001 From: P0psicles Date: Thu, 31 Mar 2016 17:12:31 +0200 Subject: [PATCH] Fixes for multi eps. --- sickbeard/search_queue.py | 30 ++++++++++++++++-------------- sickbeard/webserve.py | 11 +++++------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/sickbeard/search_queue.py b/sickbeard/search_queue.py index 9647bc523e..d48336042e 100644 --- a/sickbeard/search_queue.py +++ b/sickbeard/search_queue.py @@ -123,7 +123,10 @@ def add_item(self, item): elif isinstance(item, BacklogQueueItem) and not self.is_in_queue(item.show, item.segment): # backlog searches generic_queue.GenericQueue.add_item(self, item) - elif isinstance(item, (ManualSearchQueueItem, ManualSnatchQueueItem, FailedQueueItem)) and not self.is_ep_in_queue(item.segment): + elif isinstance(item, (ManualSearchQueueItem, FailedQueueItem)) and not self.is_ep_in_queue(item.segment): + # manual and failed searches + generic_queue.GenericQueue.add_item(self, item) + elif isinstance(item, ManualSnatchQueueItem): # manual and failed searches generic_queue.GenericQueue.add_item(self, item) else: @@ -137,7 +140,6 @@ def __init__(self): self.success = None self.started = None - def run(self): generic_queue.QueueItem.run(self) self.started = True @@ -188,7 +190,6 @@ def __init__(self, show, segment, downCurQuality=False, manual_snatch=False): self.downCurQuality = downCurQuality self.manual_snatch = manual_snatch - def run(self): generic_queue.QueueItem.run(self) self.started = True @@ -201,10 +202,11 @@ def run(self): if not self.manual_snatch and searchResult: # just use the first result for now if searchResult[0].seeders not in (-1, None) and searchResult[0].leechers not in (-1, None): - logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}".format(searchResult[0].name, - searchResult[0].seeders, searchResult[0].leechers, searchResult[0].provider.name)) + logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}". + format(searchResult[0].name, + searchResult[0].seeders, searchResult[0].leechers, searchResult[0].provider.name)) else: - logger.log(u"Downloading {0} from {1}".format(searchResult[0].name, searchResult[0].provider.name)) + logger.log(u"Downloading {0} from {1}".format(searchResult[0].name, searchResult[0].provider.name)) self.success = search.snatchEpisode(searchResult[0]) # give the CPU a break @@ -230,31 +232,31 @@ def run(self): self.finish() + class ManualSnatchQueueItem(generic_queue.QueueItem): - def __init__(self, searchResult, segment): + def __init__(self, searchResult): generic_queue.QueueItem.__init__(self, u'Manual Snatch', MANUAL_SNATCH) self.priority = generic_queue.QueuePriorities.HIGH self.success = None self.started = None self.results = None - self.segment = segment self.searchResult = searchResult - def run(self): generic_queue.QueueItem.run(self) self.started = True try: - logger.log(u"Beginning to manual snatch release: {} from provider: {}".format(self.searchResult.name, self.searchResult.provider.name)) + logger.log(u"Beginning to manual snatch release: {}".format(self.searchResult.name)) if self.searchResult: if self.searchResult.seeders not in (-1, None) and self.searchResult.leechers not in (-1, None): - logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}".format(self.searchResult.name, - self.searchResult.seeders, self.searchResult.seeders, self.searchResult.provider.name)) + logger.log(u"Downloading {0} with {1} seeders and {2} leechers from {3}". + format(self.searchResult.name, + self.searchResult.seeders, self.searchResult.seeders, self.searchResult.provider.name)) else: - logger.log(u"Downloading {0} from {1}".format(self.searchResult.name, self.searchResult.provider.name)) + logger.log(u"Downloading {0} from {1}".format(self.searchResult.name, self.searchResult.provider.name)) self.success = search.snatchEpisode(self.searchResult) else: logger.log(u"Unable to snatch release: {}".format(self.searchResult.name)) @@ -265,7 +267,7 @@ def run(self): except Exception: self.success = False logger.log(traceback.format_exc(), logger.DEBUG) - ui.notifications.message('Error while snatching selected result', "Couldn't snatch the result for %s".format(searchResult.name)) + ui.notifications.message('Error while snatching selected result', "Couldn't snatch the result for %s".format(self.searchResult.name)) if self.success is None: self.success = False diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index b51cfa77a6..f682d036f4 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1425,17 +1425,17 @@ def pickManualSnatch(self, show=None, season=None, episode=None, provider=None, # Create a list of episode object(s) # if multi-episode: |1|2| # if single-episode: |1| + # TODO: Handle Season Packs: || (no episode) episodes = sql_return['episodes'].strip("|").split("|") ep_objs = [] for episode in episodes: if episode: ep_objs.append(TVEpisode(show_obj, int(season), int(episode))) - # Create the search_result object - search_result = SearchResult(episodes=ep_objs) - search_result.provider = sickbeard.providers.getProviderClass(provider) + # TODO: Can this be moved to the ManualSnatchQueueItem? + search_result = sickbeard.providers.getProviderClass(provider).get_result(ep_objs) search_result.show = show_obj - search_result.url = sql_return['url'] + search_result.url = sql_return['url'] search_result.quality = int(sql_return['quality']) search_result.name = sql_return['name'] search_result.size = int(sql_return['size']) @@ -1443,9 +1443,8 @@ def pickManualSnatch(self, show=None, season=None, episode=None, provider=None, search_result.leechers = int(sql_return['leechers']) search_result.release_group = sql_return['release_group'] search_result.version = int(sql_return['version']) - search_result.resultType = search_result.provider.provider_type - ep_queue_item = search_queue.ManualSnatchQueueItem(search_result, ep_objs[0]) + ep_queue_item = search_queue.ManualSnatchQueueItem(search_result) sickbeard.searchQueueScheduler.action.add_item(ep_queue_item)