Skip to content

Commit

Permalink
Fixes for multi eps.
Browse files Browse the repository at this point in the history
  • Loading branch information
p0psicles authored and fernandog committed Mar 31, 2016
1 parent c56bacc commit e5c203f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
30 changes: 16 additions & 14 deletions sickbeard/search_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -137,7 +140,6 @@ def __init__(self):
self.success = None
self.started = None


def run(self):
generic_queue.QueueItem.run(self)
self.started = True
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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 <i>%s</i>".format(searchResult.name))
ui.notifications.message('Error while snatching selected result', "Couldn't snatch the result for <i>%s</i>".format(self.searchResult.name))

if self.success is None:
self.success = False
Expand Down
11 changes: 5 additions & 6 deletions sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,27 +1425,26 @@ 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'])
search_result.seeders = int(sql_return['seeders'])
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)

Expand Down

0 comments on commit e5c203f

Please sign in to comment.