mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-12 11:02:21 -05:00
Fixed failed download handling.
Improved search queue code.
This commit is contained in:
parent
6ce43c7782
commit
59675f27ac
@ -64,10 +64,8 @@ class FailedProcessor(object):
|
||||
logger.log(u" - " + str(parsed.release_group), logger.DEBUG)
|
||||
logger.log(u" - " + str(parsed.air_date), logger.DEBUG)
|
||||
|
||||
segment = {parsed.season_number: []}
|
||||
for episode in parsed.episode_numbers:
|
||||
epObj = parsed.show.getEpisode(parsed.season_number, episode)
|
||||
segment[parsed.season_number].append(epObj)
|
||||
segment = parsed.show.getEpisode(parsed.season_number, episode)
|
||||
|
||||
cur_failed_queue_item = search_queue.FailedQueueItem(parsed.show, segment)
|
||||
sickbeard.searchQueueScheduler.action.add_item(cur_failed_queue_item)
|
||||
|
@ -60,7 +60,7 @@ class EZRSSProvider(generic.TorrentProvider):
|
||||
|
||||
return quality
|
||||
|
||||
def findSearchResults(self, show, season, episodes, search_mode, manualSearch=False):
|
||||
def findSearchResults(self, show, episodes, search_mode, manualSearch=False):
|
||||
|
||||
self.show = show
|
||||
|
||||
@ -71,7 +71,7 @@ class EZRSSProvider(generic.TorrentProvider):
|
||||
logger.WARNING)
|
||||
return results
|
||||
|
||||
results = generic.TorrentProvider.findSearchResults(self, show, season, episodes, search_mode, manualSearch)
|
||||
results = generic.TorrentProvider.findSearchResults(self, show, episodes, search_mode, manualSearch)
|
||||
|
||||
return results
|
||||
|
||||
|
@ -248,7 +248,7 @@ class GenericProvider:
|
||||
|
||||
return title, url
|
||||
|
||||
def findSearchResults(self, show, season, episodes, search_mode, manualSearch=False):
|
||||
def findSearchResults(self, show, episodes, search_mode, manualSearch=False):
|
||||
|
||||
self._checkAuth()
|
||||
self.show = show
|
||||
|
@ -55,8 +55,8 @@ class NyaaProvider(generic.TorrentProvider):
|
||||
quality = Quality.sceneQuality(title)
|
||||
return quality
|
||||
|
||||
def findSearchResults(self, show, season, episodes, search_mode, manualSearch=False):
|
||||
return generic.TorrentProvider.findSearchResults(self, show, season, episodes, search_mode, manualSearch)
|
||||
def findSearchResults(self, show, episodes, search_mode, manualSearch=False):
|
||||
return generic.TorrentProvider.findSearchResults(self, show, episodes, search_mode, manualSearch)
|
||||
|
||||
def _get_season_search_strings(self, ep_obj):
|
||||
return show_name_helpers.makeSceneShowSearchStrings(self.show)
|
||||
|
@ -390,22 +390,12 @@ def searchForNeededEpisodes():
|
||||
return foundResults.values()
|
||||
|
||||
|
||||
def searchProviders(show, season, episodes, manualSearch=False):
|
||||
def searchProviders(show, episodes, manualSearch=False):
|
||||
foundResults = {}
|
||||
finalResults = []
|
||||
|
||||
didSearch = False
|
||||
|
||||
# build name cache for show
|
||||
sickbeard.name_cache.buildNameCache(show)
|
||||
|
||||
# check if we want to search for season packs instead of just season/episode
|
||||
seasonSearch = False
|
||||
if not manualSearch:
|
||||
seasonEps = show.getAllEpisodes(season)
|
||||
if len(seasonEps) == len(episodes):
|
||||
seasonSearch = True
|
||||
|
||||
origThreadName = threading.currentThread().name
|
||||
|
||||
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive() and x.enable_backlog]
|
||||
@ -417,23 +407,21 @@ def searchProviders(show, season, episodes, manualSearch=False):
|
||||
threading.currentThread().name = origThreadName + " :: [" + curProvider.name + "]"
|
||||
|
||||
foundResults[curProvider.name] = {}
|
||||
searchCount = 0
|
||||
|
||||
search_mode = 'eponly'
|
||||
if seasonSearch and curProvider.search_mode == 'sponly':
|
||||
searchCount = 0
|
||||
search_mode = curProvider.search_mode
|
||||
|
||||
while(True):
|
||||
searchCount += 1
|
||||
|
||||
if search_mode == 'sponly':
|
||||
logger.log(u"Searching for " + show.name + " Season " + str(season) + " pack")
|
||||
if search_mode == 'eponly':
|
||||
logger.log(u"Performing episode search for " + show.name)
|
||||
else:
|
||||
logger.log(u"Searching for episodes we need from " + show.name + " Season " + str(season))
|
||||
logger.log(u"Performing season pack search for " + show.name)
|
||||
|
||||
try:
|
||||
curProvider.cache.updateCache()
|
||||
searchResults = curProvider.findSearchResults(show, season, episodes, search_mode, manualSearch)
|
||||
searchResults = curProvider.findSearchResults(show, episodes, search_mode, manualSearch)
|
||||
except exceptions.AuthException, e:
|
||||
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
||||
break
|
||||
|
@ -99,12 +99,13 @@ class BacklogSearcher:
|
||||
|
||||
segments = self._get_segments(curShow, fromDate)
|
||||
|
||||
if len(segments):
|
||||
backlog_queue_item = search_queue.BacklogQueueItem(curShow, segments)
|
||||
for season, segment in segments.items():
|
||||
self.currentSearchInfo = {'title': self.show.name + " Season " + str(season)}
|
||||
|
||||
backlog_queue_item = search_queue.BacklogQueueItem(curShow, segment)
|
||||
sickbeard.searchQueueScheduler.action.add_item(backlog_queue_item) # @UndefinedVariable
|
||||
else:
|
||||
logger.log(u"Nothing needs to be downloaded for " + str(curShow.name) + ", skipping this season",
|
||||
logger.DEBUG)
|
||||
logger.log(u"Nothing needs to be downloaded for " + str(curShow.name) + ", skipping",logger.DEBUG)
|
||||
|
||||
# don't consider this an actual backlog search if we only did recent eps
|
||||
# or if we only did certain shows
|
||||
|
@ -49,6 +49,12 @@ class SearchQueue(generic_queue.GenericQueue):
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_ep_in_queue(self, ep_obj):
|
||||
for cur_item in self.queue:
|
||||
if isinstance(cur_item, (ManualSearchQueueItem, FailedQueueItem)) and cur_item.ep_obj == ep_obj:
|
||||
return True
|
||||
return False
|
||||
|
||||
def pause_backlog(self):
|
||||
self.min_priority = generic_queue.QueuePriorities.HIGH
|
||||
|
||||
@ -72,13 +78,21 @@ class SearchQueue(generic_queue.GenericQueue):
|
||||
return False
|
||||
|
||||
def add_item(self, item):
|
||||
if isinstance(item, DailySearchQueueItem) or (
|
||||
isinstance(item, (BacklogQueueItem, ManualSearchQueueItem, FailedQueueItem)) and not self.is_in_queue(
|
||||
item.show, item.segment)):
|
||||
if isinstance(item, DailySearchQueueItem):
|
||||
# daily searches
|
||||
generic_queue.GenericQueue.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, FailedQueueItem)) and not self.is_ep_in_queue(item.segment):
|
||||
# manual and failed searches
|
||||
generic_queue.GenericQueue.add_item(self, item)
|
||||
else:
|
||||
logger.log(u"Not adding item, it's already in the queue", logger.DEBUG)
|
||||
return
|
||||
|
||||
# build name cache for show
|
||||
sickbeard.name_cache.buildNameCache(item.show)
|
||||
|
||||
class DailySearchQueueItem(generic_queue.QueueItem):
|
||||
def __init__(self):
|
||||
@ -123,7 +137,7 @@ class ManualSearchQueueItem(generic_queue.QueueItem):
|
||||
|
||||
try:
|
||||
logger.log("Beginning manual search for [" + self.segment.prettyName() + "]")
|
||||
searchResult = search.searchProviders(self.show, self.segment.season, [self.segment], True)
|
||||
searchResult = search.searchProviders(self.show, [self.segment], True)
|
||||
|
||||
if searchResult:
|
||||
# just use the first result for now
|
||||
@ -161,14 +175,8 @@ class BacklogQueueItem(generic_queue.QueueItem):
|
||||
generic_queue.QueueItem.run(self)
|
||||
|
||||
try:
|
||||
for season in self.segment:
|
||||
sickbeard.searchBacklog.BacklogSearcher.currentSearchInfo = {
|
||||
'title': self.show.name + " Season " + str(season)}
|
||||
|
||||
wantedEps = self.segment[season]
|
||||
|
||||
logger.log("Beginning backlog search for [" + self.show.name + "]")
|
||||
searchResult = search.searchProviders(self.show, season, wantedEps, False)
|
||||
searchResult = search.searchProviders(self.show, self.segment, False)
|
||||
|
||||
if searchResult:
|
||||
for result in searchResult:
|
||||
@ -199,20 +207,18 @@ class FailedQueueItem(generic_queue.QueueItem):
|
||||
generic_queue.QueueItem.run(self)
|
||||
|
||||
try:
|
||||
for season, episodes in self.segment.items():
|
||||
for epObj in episodes:
|
||||
logger.log(u"Marking episode as bad: [" + epObj.prettyName() + "]")
|
||||
failed_history.markFailed(epObj)
|
||||
logger.log(u"Marking episode as bad: [" + self.segment.prettyName() + "]")
|
||||
failed_history.markFailed(self.segment)
|
||||
|
||||
(release, provider) = failed_history.findRelease(epObj)
|
||||
(release, provider) = failed_history.findRelease(self.segment)
|
||||
if release:
|
||||
failed_history.logFailed(release)
|
||||
history.logFailed(epObj, release, provider)
|
||||
history.logFailed(self.segment, release, provider)
|
||||
|
||||
failed_history.revertEpisode(epObj)
|
||||
logger.log("Beginning failed download search for [" + epObj.prettyName() + "]")
|
||||
failed_history.revertEpisode(self.segment)
|
||||
logger.log("Beginning failed download search for [" + self.segment.prettyName() + "]")
|
||||
|
||||
searchResult = search.searchProviders(self.show, season, [epObj], True)
|
||||
searchResult = search.searchProviders(self.show, [self.segment], True)
|
||||
|
||||
if searchResult:
|
||||
for result in searchResult:
|
||||
@ -223,7 +229,7 @@ class FailedQueueItem(generic_queue.QueueItem):
|
||||
# give the CPU a break
|
||||
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
|
||||
else:
|
||||
logger.log(u"No valid episode found to retry for [" + epObj.prettyName() + "]")
|
||||
logger.log(u"No valid episode found to retry for [" + self.segment.prettyName() + "]")
|
||||
except Exception:
|
||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||
|
||||
|
@ -31,7 +31,6 @@ from lib.trakt import *
|
||||
class TraktChecker():
|
||||
def __init__(self):
|
||||
self.todoWanted = []
|
||||
self.todoBacklog = []
|
||||
|
||||
def run(self, force=False):
|
||||
try:
|
||||
@ -207,7 +206,7 @@ class TraktChecker():
|
||||
epObj = show.getEpisode(int(s), int(e))
|
||||
if epObj:
|
||||
|
||||
ep_segment = {}
|
||||
segments = {}
|
||||
|
||||
with epObj.lock:
|
||||
if epObj.status != SKIPPED:
|
||||
@ -217,35 +216,27 @@ class TraktChecker():
|
||||
# figure out what segment the episode is in and remember it so we can backlog it
|
||||
|
||||
if epObj.season in ep_segment:
|
||||
ep_segment[epObj.season].append(epObj)
|
||||
segments[epObj.season].append(epObj)
|
||||
else:
|
||||
ep_segment[epObj.season] = [epObj]
|
||||
segments[epObj.season] = [epObj]
|
||||
|
||||
epObj.status = WANTED
|
||||
epObj.saveToDB()
|
||||
|
||||
backlog = (show, ep_segment)
|
||||
if self.todoBacklog.count(backlog) == 0:
|
||||
self.todoBacklog.append(backlog)
|
||||
for season, segment in segments.items():
|
||||
cur_backlog_queue_item = search_queue.BacklogQueueItem(show, segment[1])
|
||||
sickbeard.searchQueueScheduler.action.add_item(cur_backlog_queue_item)
|
||||
|
||||
logger.log(u"Starting backlog for " + show.name + " season " + str(
|
||||
season) + " because some eps were set to wanted")
|
||||
|
||||
def manageNewShow(self, show):
|
||||
episodes = [i for i in self.todoWanted if i[0] == show.indexerid]
|
||||
for episode in episodes:
|
||||
self.todoWanted.remove(episode)
|
||||
|
||||
if episode[1] == -1 and sickbeard.TRAKT_START_PAUSED:
|
||||
show.paused = 1
|
||||
continue
|
||||
|
||||
self.setEpisodeToWanted(show, episode[1], episode[2])
|
||||
self.startBacklog(show)
|
||||
|
||||
def startBacklog(self, show):
|
||||
segments = [i for i in self.todoBacklog if i[0] == show]
|
||||
for segment in segments:
|
||||
cur_backlog_queue_item = search_queue.BacklogQueueItem(show, segment[1])
|
||||
sickbeard.searchQueueScheduler.action.add_item(cur_backlog_queue_item)
|
||||
|
||||
for season in segment[1]:
|
||||
logger.log(u"Starting backlog for " + show.name + " season " + str(
|
||||
season) + " because some eps were set to wanted")
|
||||
self.todoBacklog.remove(segment)
|
||||
|
@ -341,9 +341,6 @@ class TVCache():
|
||||
Quality.qualityStrings[curQuality], logger.DEBUG)
|
||||
continue
|
||||
|
||||
# build name cache for show
|
||||
sickbeard.name_cache.buildNameCache(showObj)
|
||||
|
||||
if episode:
|
||||
epObj = episode
|
||||
else:
|
||||
|
@ -969,7 +969,7 @@ class CMD_EpisodeSetStatus(ApiCall):
|
||||
ep_results = []
|
||||
failure = False
|
||||
start_backlog = False
|
||||
ep_segment = {}
|
||||
segments = {}
|
||||
|
||||
sql_l = []
|
||||
for epObj in ep_list:
|
||||
@ -977,9 +977,9 @@ class CMD_EpisodeSetStatus(ApiCall):
|
||||
if self.status == WANTED:
|
||||
# figure out what episodes are wanted so we can backlog them
|
||||
if epObj.season in ep_segment:
|
||||
ep_segment[epObj.season].append(epObj)
|
||||
segments[epObj.season].append(epObj)
|
||||
else:
|
||||
ep_segment[epObj.season] = [epObj]
|
||||
segments[epObj.season] = [epObj]
|
||||
|
||||
# don't let them mess up UNAIRED episodes
|
||||
if epObj.status == UNAIRED:
|
||||
@ -1009,11 +1009,13 @@ class CMD_EpisodeSetStatus(ApiCall):
|
||||
|
||||
extra_msg = ""
|
||||
if start_backlog:
|
||||
cur_backlog_queue_item = search_queue.BacklogQueueItem(showObj, ep_segment)
|
||||
for season, segment in segments.items():
|
||||
cur_backlog_queue_item = search_queue.BacklogQueueItem(showObj, segment)
|
||||
sickbeard.searchQueueScheduler.action.add_item(cur_backlog_queue_item) #@UndefinedVariable
|
||||
for season in ep_segment:
|
||||
|
||||
logger.log(u"API :: Starting backlog for " + showObj.name + " season " + str(
|
||||
season) + " because some episodes were set to WANTED")
|
||||
|
||||
extra_msg = " Backlog started"
|
||||
|
||||
if failure:
|
||||
|
@ -4121,7 +4121,7 @@ class Home(MainHandler):
|
||||
else:
|
||||
return self._genericMessage("Error", errMsg)
|
||||
|
||||
segment = {}
|
||||
segments = {}
|
||||
if eps is not None:
|
||||
|
||||
sql_l = []
|
||||
@ -4138,10 +4138,10 @@ class Home(MainHandler):
|
||||
|
||||
if int(status) in [WANTED, FAILED]:
|
||||
# figure out what episodes are wanted so we can backlog them
|
||||
if epObj.season in segment:
|
||||
segment[epObj.season].append(epObj)
|
||||
if epObj.season in segments:
|
||||
segments[epObj.season].append(epObj)
|
||||
else:
|
||||
segment[epObj.season] = [epObj]
|
||||
segments[epObj.season] = [epObj]
|
||||
|
||||
with epObj.lock:
|
||||
# don't let them mess up UNAIRED episodes
|
||||
@ -4175,30 +4175,34 @@ class Home(MainHandler):
|
||||
|
||||
if int(status) == WANTED:
|
||||
msg = "Backlog was automatically started for the following seasons of <b>" + showObj.name + "</b>:<br />"
|
||||
for season in segment:
|
||||
msg += "<li>Season " + str(season) + "</li>"
|
||||
logger.log(u"Sending backlog for " + showObj.name + " season " + str(
|
||||
season) + " because some eps were set to wanted")
|
||||
msg += "</ul>"
|
||||
|
||||
for season, segment in segments.items():
|
||||
cur_backlog_queue_item = search_queue.BacklogQueueItem(showObj, segment)
|
||||
sickbeard.searchQueueScheduler.action.add_item(cur_backlog_queue_item) # @UndefinedVariable
|
||||
|
||||
if segment:
|
||||
msg += "<li>Season " + str(season) + "</li>"
|
||||
logger.log(u"Sending backlog for " + showObj.name + " season " + str(
|
||||
season) + " because some eps were set to wanted")
|
||||
|
||||
msg += "</ul>"
|
||||
|
||||
if segments:
|
||||
ui.notifications.message("Backlog started", msg)
|
||||
|
||||
if int(status) == FAILED:
|
||||
msg = "Retrying Search was automatically started for the following season of <b>" + showObj.name + "</b>:<br />"
|
||||
for season in segment:
|
||||
msg += "<li>Season " + str(season) + "</li>"
|
||||
logger.log(u"Retrying Search for " + showObj.name + " season " + str(
|
||||
season) + " because some eps were set to failed")
|
||||
msg += "</ul>"
|
||||
|
||||
for season, segment in segments.items():
|
||||
cur_failed_queue_item = search_queue.FailedQueueItem(showObj, segment)
|
||||
sickbeard.searchQueueScheduler.action.add_item(cur_failed_queue_item) # @UndefinedVariable
|
||||
|
||||
if segment:
|
||||
msg += "<li>Season " + str(season) + "</li>"
|
||||
logger.log(u"Retrying Search for " + showObj.name + " season " + str(
|
||||
season) + " because some eps were set to failed")
|
||||
|
||||
msg += "</ul>"
|
||||
|
||||
if segments:
|
||||
ui.notifications.message("Retry Search started", msg)
|
||||
|
||||
if direct:
|
||||
@ -4440,11 +4444,8 @@ class Home(MainHandler):
|
||||
if isinstance(ep_obj, str):
|
||||
return json.dumps({'result': 'failure'})
|
||||
|
||||
# create failed segment
|
||||
segment = {season: [ep_obj]}
|
||||
|
||||
# make a queue item for it and put it on the queue
|
||||
ep_queue_item = search_queue.FailedQueueItem(ep_obj.show, segment)
|
||||
ep_queue_item = search_queue.FailedQueueItem(ep_obj.show, ep_obj)
|
||||
sickbeard.searchQueueScheduler.action.add_item(ep_queue_item) # @UndefinedVariable
|
||||
|
||||
# wait until the queue item tells us whether it worked or not
|
||||
|
Loading…
Reference in New Issue
Block a user