mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 11:32:20 -05:00
parent
5ec5dde9ba
commit
aafe9ad522
@ -259,11 +259,11 @@ class GenericProvider:
|
|||||||
itemList = [i for n, i in enumerate(itemList) if i not in itemList[n + 1:]]
|
itemList = [i for n, i in enumerate(itemList) if i not in itemList[n + 1:]]
|
||||||
|
|
||||||
if epObj.episode in searchItems:
|
if epObj.episode in searchItems:
|
||||||
searchItems[epObj.episode] += itemList
|
searchItems[epObj] += itemList
|
||||||
else:
|
else:
|
||||||
searchItems[epObj.episode] = itemList
|
searchItems[epObj] = itemList
|
||||||
|
|
||||||
for episode, items in searchItems.items():
|
for ep_obj, items in searchItems.items():
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|
||||||
|
|
||||||
@ -274,22 +274,25 @@ class GenericProvider:
|
|||||||
# parse the file name
|
# parse the file name
|
||||||
try:
|
try:
|
||||||
myParser = NameParser(False)
|
myParser = NameParser(False)
|
||||||
parse_result = myParser.parse(title).convert()
|
if ep_obj.season == ep_obj.scene_season and ep_obj.episode == ep_obj.scene_episode:
|
||||||
|
parse_result = myParser.parse(title)
|
||||||
|
else:
|
||||||
|
parse_result = myParser.parse(title)
|
||||||
except InvalidNameException:
|
except InvalidNameException:
|
||||||
logger.log(u"Unable to parse the filename " + title + " into a valid episode", logger.WARNING)
|
logger.log(u"Unable to parse the filename " + title + " into a valid episode", logger.WARNING)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not (self.show.air_by_date or self.show.sports):
|
if not (self.show.air_by_date or self.show.sports):
|
||||||
if not len(parse_result.episode_numbers) and (
|
if not len(parse_result.episode_numbers) and (
|
||||||
parse_result.season_number != None and parse_result.season_number != season) or (
|
parse_result.season_number != None and parse_result.season_number != ep_obj.season) or (
|
||||||
parse_result.season_number == None and season != 1):
|
parse_result.season_number == None and ep_obj.season != 1):
|
||||||
logger.log(u"The result " + title + " doesn't seem to be a valid season for season " + str(
|
logger.log(u"The result " + title + " doesn't seem to be a valid season for season " + str(
|
||||||
season) + ", ignoring", logger.DEBUG)
|
ep_obj.season) + ", ignoring", logger.DEBUG)
|
||||||
continue
|
continue
|
||||||
elif len(parse_result.episode_numbers) and (
|
elif len(parse_result.episode_numbers) and (
|
||||||
parse_result.season_number != season or episode not in parse_result.episode_numbers):
|
parse_result.season_number != ep_obj.season or ep_obj.episode not in parse_result.episode_numbers):
|
||||||
logger.log(u"Episode " + title + " isn't " + str(season) + "x" + str(
|
logger.log(u"Episode " + title + " isn't " + str(ep_obj.season) + "x" + str(
|
||||||
episode) + ", skipping it", logger.DEBUG)
|
ep_obj.episode) + ", skipping it", logger.DEBUG)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# we just use the existing info for normal searches
|
# we just use the existing info for normal searches
|
||||||
|
@ -175,8 +175,6 @@ def snatchEpisode(result, endStatus=SNATCHED):
|
|||||||
|
|
||||||
|
|
||||||
def searchForNeededEpisodes(curProvider):
|
def searchForNeededEpisodes(curProvider):
|
||||||
threading.currentThread().name = curProvider.name
|
|
||||||
|
|
||||||
logger.log(u"Searching all providers for any needed episodes")
|
logger.log(u"Searching all providers for any needed episodes")
|
||||||
foundResults = {}
|
foundResults = {}
|
||||||
|
|
||||||
@ -361,212 +359,230 @@ def filterSearchResults(show, results):
|
|||||||
|
|
||||||
return foundResults
|
return foundResults
|
||||||
|
|
||||||
def searchProviders(queueItem, show, season, episodes, curProvider, seasonSearch=False, manualSearch=False):
|
def searchProviders(queueItem, show, season, episodes, seasonSearch=False, manualSearch=False):
|
||||||
logger.log(u"Searching for stuff we need from " + show.name + " season " + str(season))
|
logger.log(u"Searching for stuff we need from " + show.name + " season " + str(season))
|
||||||
foundResults = {}
|
|
||||||
finalResults = []
|
finalResults = []
|
||||||
|
didSearch = False
|
||||||
|
|
||||||
# convert indexer numbering to scene numbering for searches
|
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
|
||||||
map(lambda x: x.convertToSceneNumbering, episodes)
|
|
||||||
|
|
||||||
try:
|
for provider in providers:
|
||||||
curResults = curProvider.findSearchResults(show, season, episodes, seasonSearch, manualSearch)
|
foundResults = {provider.name:{}}
|
||||||
except exceptions.AuthException, e:
|
|
||||||
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
|
||||||
return []
|
|
||||||
except Exception, e:
|
|
||||||
logger.log(u"Error while searching " + curProvider.name + ", skipping: " + ex(e), logger.ERROR)
|
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
|
||||||
return []
|
|
||||||
|
|
||||||
if not len(curResults):
|
try:
|
||||||
return []
|
curResults = provider.findSearchResults(show, season, episodes, seasonSearch, manualSearch)
|
||||||
|
except exceptions.AuthException, e:
|
||||||
|
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
|
||||||
|
return []
|
||||||
|
except Exception, e:
|
||||||
|
logger.log(u"Error while searching " + provider.name + ", skipping: " + ex(e), logger.ERROR)
|
||||||
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
|
return []
|
||||||
|
|
||||||
curResults = filterSearchResults(show, curResults)
|
didSearch = True
|
||||||
if len(curResults):
|
|
||||||
foundResults.update(curResults)
|
|
||||||
logger.log(u"Provider search results: " + repr(foundResults), logger.DEBUG)
|
|
||||||
|
|
||||||
if not len(foundResults):
|
if not len(curResults):
|
||||||
return []
|
continue
|
||||||
|
|
||||||
anyQualities, bestQualities = Quality.splitQuality(show.quality)
|
curResults = filterSearchResults(show, curResults)
|
||||||
|
if len(curResults):
|
||||||
|
foundResults[provider.name] = curResults
|
||||||
|
logger.log(u"Provider search results: " + repr(foundResults), logger.DEBUG)
|
||||||
|
|
||||||
# pick the best season NZB
|
if not len(foundResults[provider.name]):
|
||||||
bestSeasonNZB = None
|
continue
|
||||||
if SEASON_RESULT in foundResults:
|
|
||||||
bestSeasonNZB = pickBestResult(foundResults[SEASON_RESULT], show, anyQualities + bestQualities)
|
|
||||||
|
|
||||||
highest_quality_overall = 0
|
anyQualities, bestQualities = Quality.splitQuality(show.quality)
|
||||||
for cur_episode in foundResults:
|
|
||||||
for cur_result in foundResults[cur_episode]:
|
|
||||||
if cur_result.quality != Quality.UNKNOWN and cur_result.quality > highest_quality_overall:
|
|
||||||
highest_quality_overall = cur_result.quality
|
|
||||||
logger.log(u"The highest quality of any match is " + Quality.qualityStrings[highest_quality_overall], logger.DEBUG)
|
|
||||||
|
|
||||||
# see if every episode is wanted
|
# pick the best season NZB
|
||||||
if bestSeasonNZB:
|
bestSeasonNZB = None
|
||||||
|
if SEASON_RESULT in foundResults:
|
||||||
|
bestSeasonNZB = pickBestResult(foundResults[SEASON_RESULT], show, anyQualities + bestQualities)
|
||||||
|
|
||||||
# get the quality of the season nzb
|
highest_quality_overall = 0
|
||||||
seasonQual = Quality.sceneQuality(bestSeasonNZB.name)
|
for cur_episode in foundResults[provider.name]:
|
||||||
seasonQual = bestSeasonNZB.quality
|
for cur_result in foundResults[provider.name][cur_episode]:
|
||||||
logger.log(
|
if cur_result.quality != Quality.UNKNOWN and cur_result.quality > highest_quality_overall:
|
||||||
u"The quality of the season " + bestSeasonNZB.provider.providerType + " is " + Quality.qualityStrings[
|
highest_quality_overall = cur_result.quality
|
||||||
seasonQual], logger.DEBUG)
|
logger.log(u"The highest quality of any match is " + Quality.qualityStrings[highest_quality_overall], logger.DEBUG)
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
# see if every episode is wanted
|
||||||
allEps = [int(x["episode"]) for x in
|
if bestSeasonNZB:
|
||||||
myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND season = ?",
|
|
||||||
[show.indexerid, season])]
|
|
||||||
logger.log(u"Episode list: " + str(allEps), logger.DEBUG)
|
|
||||||
|
|
||||||
allWanted = True
|
# get the quality of the season nzb
|
||||||
anyWanted = False
|
seasonQual = Quality.sceneQuality(bestSeasonNZB.name)
|
||||||
for curEpNum in allEps:
|
seasonQual = bestSeasonNZB.quality
|
||||||
if not show.wantEpisode(season, curEpNum, seasonQual):
|
|
||||||
allWanted = False
|
|
||||||
else:
|
|
||||||
anyWanted = True
|
|
||||||
|
|
||||||
# if we need every ep in the season check if single episode releases should be preferred over season releases (missing single episode releases will be picked individually from season release)
|
|
||||||
preferSingleEpisodesOverSeasonReleases = sickbeard.PREFER_EPISODE_RELEASES
|
|
||||||
logger.log(u"Prefer single episodes over season releases: "+str(preferSingleEpisodesOverSeasonReleases), logger.DEBUG)
|
|
||||||
# if we need every ep in the season and there's nothing better then just download this and be done with it (unless single episodes are preferred)
|
|
||||||
if allWanted and bestSeasonNZB.quality == highest_quality_overall and not preferSingleEpisodesOverSeasonReleases:
|
|
||||||
logger.log(u"Every ep in this season is needed, downloading the whole " + bestSeasonNZB.provider.providerType + " " + bestSeasonNZB.name)
|
|
||||||
epObjs = []
|
|
||||||
for curEpNum in allEps:
|
|
||||||
epObjs.append(show.getEpisode(season, curEpNum))
|
|
||||||
bestSeasonNZB.episodes = epObjs
|
|
||||||
queueItem.results = [bestSeasonNZB]
|
|
||||||
return queueItem
|
|
||||||
|
|
||||||
elif not anyWanted:
|
|
||||||
logger.log(
|
logger.log(
|
||||||
u"No eps from this season are wanted at this quality, ignoring the result of " + bestSeasonNZB.name,
|
u"The quality of the season " + bestSeasonNZB.provider.providerType + " is " + Quality.qualityStrings[
|
||||||
logger.DEBUG)
|
seasonQual], logger.DEBUG)
|
||||||
|
|
||||||
else:
|
myDB = db.DBConnection()
|
||||||
|
allEps = [int(x["episode"]) for x in
|
||||||
|
myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND season = ?",
|
||||||
|
[show.indexerid, season])]
|
||||||
|
logger.log(u"Episode list: " + str(allEps), logger.DEBUG)
|
||||||
|
|
||||||
if bestSeasonNZB.provider.providerType == GenericProvider.NZB:
|
allWanted = True
|
||||||
logger.log(u"Breaking apart the NZB and adding the individual ones to our results", logger.DEBUG)
|
anyWanted = False
|
||||||
|
for curEpNum in allEps:
|
||||||
|
if not show.wantEpisode(season, curEpNum, seasonQual):
|
||||||
|
allWanted = False
|
||||||
|
else:
|
||||||
|
anyWanted = True
|
||||||
|
|
||||||
# if not, break it apart and add them as the lowest priority results
|
# if we need every ep in the season check if single episode releases should be preferred over season releases (missing single episode releases will be picked individually from season release)
|
||||||
individualResults = nzbSplitter.splitResult(bestSeasonNZB)
|
preferSingleEpisodesOverSeasonReleases = sickbeard.PREFER_EPISODE_RELEASES
|
||||||
|
logger.log(u"Prefer single episodes over season releases: "+str(preferSingleEpisodesOverSeasonReleases), logger.DEBUG)
|
||||||
individualResults = filter(
|
# if we need every ep in the season and there's nothing better then just download this and be done with it (unless single episodes are preferred)
|
||||||
lambda x: show_name_helpers.filterBadReleases(x.name) and show_name_helpers.isGoodResult(x.name,
|
if allWanted and bestSeasonNZB.quality == highest_quality_overall and not preferSingleEpisodesOverSeasonReleases:
|
||||||
show),
|
logger.log(u"Every ep in this season is needed, downloading the whole " + bestSeasonNZB.provider.providerType + " " + bestSeasonNZB.name)
|
||||||
individualResults)
|
|
||||||
|
|
||||||
for curResult in individualResults:
|
|
||||||
if len(curResult.episodes) == 1:
|
|
||||||
epNum = curResult.episodes[0].episode
|
|
||||||
elif len(curResult.episodes) > 1:
|
|
||||||
epNum = MULTI_EP_RESULT
|
|
||||||
|
|
||||||
if epNum in foundResults:
|
|
||||||
foundResults[epNum].append(curResult)
|
|
||||||
else:
|
|
||||||
foundResults[epNum] = [curResult]
|
|
||||||
|
|
||||||
# If this is a torrent all we can do is leech the entire torrent, user will have to select which eps not do download in his torrent client
|
|
||||||
else:
|
|
||||||
|
|
||||||
# Season result from Torrent Provider must be a full-season torrent, creating multi-ep result for it.
|
|
||||||
logger.log(
|
|
||||||
u"Adding multi-ep result for full-season torrent. Set the episodes you don't want to 'don't download' in your torrent client if desired!")
|
|
||||||
epObjs = []
|
epObjs = []
|
||||||
for curEpNum in allEps:
|
for curEpNum in allEps:
|
||||||
epObjs.append(show.getEpisode(season, curEpNum))
|
epObjs.append(show.getEpisode(season, curEpNum))
|
||||||
bestSeasonNZB.episodes = epObjs
|
bestSeasonNZB.episodes = epObjs
|
||||||
|
queueItem.results = [bestSeasonNZB]
|
||||||
|
return queueItem
|
||||||
|
|
||||||
epNum = MULTI_EP_RESULT
|
elif not anyWanted:
|
||||||
if epNum in foundResults:
|
|
||||||
foundResults[epNum].append(bestSeasonNZB)
|
|
||||||
else:
|
|
||||||
foundResults[epNum] = [bestSeasonNZB]
|
|
||||||
|
|
||||||
# go through multi-ep results and see if we really want them or not, get rid of the rest
|
|
||||||
multiResults = {}
|
|
||||||
if MULTI_EP_RESULT in foundResults:
|
|
||||||
for multiResult in foundResults[MULTI_EP_RESULT]:
|
|
||||||
|
|
||||||
logger.log(u"Seeing if we want to bother with multi-episode result " + multiResult.name, logger.DEBUG)
|
|
||||||
|
|
||||||
if sickbeard.USE_FAILED_DOWNLOADS and failed_history.hasFailed(multiResult.name, multiResult.size,
|
|
||||||
multiResult.provider.name):
|
|
||||||
logger.log(multiResult.name + u" has previously failed, rejecting this multi-ep result")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# see how many of the eps that this result covers aren't covered by single results
|
|
||||||
neededEps = []
|
|
||||||
notNeededEps = []
|
|
||||||
for epObj in multiResult.episodes:
|
|
||||||
epNum = epObj.episode
|
|
||||||
# if we have results for the episode
|
|
||||||
if epNum in foundResults and len(foundResults[epNum]) > 0:
|
|
||||||
# but the multi-ep is worse quality, we don't want it
|
|
||||||
# TODO: wtf is this False for
|
|
||||||
#if False and multiResult.quality <= pickBestResult(foundResults[epNum]):
|
|
||||||
# notNeededEps.append(epNum)
|
|
||||||
#else:
|
|
||||||
neededEps.append(epNum)
|
|
||||||
else:
|
|
||||||
neededEps.append(epNum)
|
|
||||||
|
|
||||||
logger.log(
|
|
||||||
u"Single-ep check result is neededEps: " + str(neededEps) + ", notNeededEps: " + str(notNeededEps),
|
|
||||||
logger.DEBUG)
|
|
||||||
|
|
||||||
if not neededEps:
|
|
||||||
logger.log(u"All of these episodes were covered by single nzbs, ignoring this multi-ep result",
|
|
||||||
logger.DEBUG)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# check if these eps are already covered by another multi-result
|
|
||||||
multiNeededEps = []
|
|
||||||
multiNotNeededEps = []
|
|
||||||
for epObj in multiResult.episodes:
|
|
||||||
epNum = epObj.episode
|
|
||||||
if epNum in multiResults:
|
|
||||||
multiNotNeededEps.append(epNum)
|
|
||||||
else:
|
|
||||||
multiNeededEps.append(epNum)
|
|
||||||
|
|
||||||
logger.log(
|
|
||||||
u"Multi-ep check result is multiNeededEps: " + str(multiNeededEps) + ", multiNotNeededEps: " + str(
|
|
||||||
multiNotNeededEps), logger.DEBUG)
|
|
||||||
|
|
||||||
if not multiNeededEps:
|
|
||||||
logger.log(
|
logger.log(
|
||||||
u"All of these episodes were covered by another multi-episode nzbs, ignoring this multi-ep result",
|
u"No eps from this season are wanted at this quality, ignoring the result of " + bestSeasonNZB.name,
|
||||||
logger.DEBUG)
|
logger.DEBUG)
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
if bestSeasonNZB.provider.providerType == GenericProvider.NZB:
|
||||||
|
logger.log(u"Breaking apart the NZB and adding the individual ones to our results", logger.DEBUG)
|
||||||
|
|
||||||
|
# if not, break it apart and add them as the lowest priority results
|
||||||
|
individualResults = nzbSplitter.splitResult(bestSeasonNZB)
|
||||||
|
|
||||||
|
individualResults = filter(
|
||||||
|
lambda x: show_name_helpers.filterBadReleases(x.name) and show_name_helpers.isGoodResult(x.name,
|
||||||
|
show),
|
||||||
|
individualResults)
|
||||||
|
|
||||||
|
for curResult in individualResults:
|
||||||
|
if len(curResult.episodes) == 1:
|
||||||
|
epNum = curResult.episodes[0].episode
|
||||||
|
elif len(curResult.episodes) > 1:
|
||||||
|
epNum = MULTI_EP_RESULT
|
||||||
|
|
||||||
|
if epNum in foundResults[provider.name]:
|
||||||
|
foundResults[provider.name][epNum] += curResult
|
||||||
|
else:
|
||||||
|
foundResults[provider.name][epNum] = [curResult]
|
||||||
|
|
||||||
|
# If this is a torrent all we can do is leech the entire torrent, user will have to select which eps not do download in his torrent client
|
||||||
|
else:
|
||||||
|
|
||||||
|
# Season result from Torrent Provider must be a full-season torrent, creating multi-ep result for it.
|
||||||
|
logger.log(
|
||||||
|
u"Adding multi-ep result for full-season torrent. Set the episodes you don't want to 'don't download' in your torrent client if desired!")
|
||||||
|
epObjs = []
|
||||||
|
for curEpNum in allEps:
|
||||||
|
epObjs.append(show.getEpisode(season, curEpNum))
|
||||||
|
bestSeasonNZB.episodes = epObjs
|
||||||
|
|
||||||
|
epNum = MULTI_EP_RESULT
|
||||||
|
if epNum in foundResults[provider.name]:
|
||||||
|
foundResults[provider.name][epNum] += bestSeasonNZB
|
||||||
|
else:
|
||||||
|
foundResults[provider.name][epNum] = [bestSeasonNZB]
|
||||||
|
|
||||||
|
# go through multi-ep results and see if we really want them or not, get rid of the rest
|
||||||
|
multiResults = {}
|
||||||
|
if MULTI_EP_RESULT in foundResults[provider.name]:
|
||||||
|
for multiResult in foundResults[provider.name][MULTI_EP_RESULT]:
|
||||||
|
|
||||||
|
logger.log(u"Seeing if we want to bother with multi-episode result " + multiResult.name, logger.DEBUG)
|
||||||
|
|
||||||
|
if sickbeard.USE_FAILED_DOWNLOADS and failed_history.hasFailed(multiResult.name, multiResult.size,
|
||||||
|
multiResult.provider.name):
|
||||||
|
logger.log(multiResult.name + u" has previously failed, rejecting this multi-ep result")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# see how many of the eps that this result covers aren't covered by single results
|
||||||
|
neededEps = []
|
||||||
|
notNeededEps = []
|
||||||
|
for epObj in multiResult.episodes:
|
||||||
|
epNum = epObj.episode
|
||||||
|
# if we have results for the episode
|
||||||
|
if epNum in foundResults[provider.name] and len(foundResults[provider.name][epNum]) > 0:
|
||||||
|
# but the multi-ep is worse quality, we don't want it
|
||||||
|
# TODO: wtf is this False for
|
||||||
|
#if False and multiResult.quality <= pickBestResult(foundResults[epNum]):
|
||||||
|
# notNeededEps.append(epNum)
|
||||||
|
#else:
|
||||||
|
neededEps.append(epNum)
|
||||||
|
else:
|
||||||
|
neededEps.append(epNum)
|
||||||
|
|
||||||
|
logger.log(
|
||||||
|
u"Single-ep check result is neededEps: " + str(neededEps) + ", notNeededEps: " + str(notNeededEps),
|
||||||
|
logger.DEBUG)
|
||||||
|
|
||||||
|
if not neededEps:
|
||||||
|
logger.log(u"All of these episodes were covered by single nzbs, ignoring this multi-ep result",
|
||||||
|
logger.DEBUG)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# check if these eps are already covered by another multi-result
|
||||||
|
multiNeededEps = []
|
||||||
|
multiNotNeededEps = []
|
||||||
|
for epObj in multiResult.episodes:
|
||||||
|
epNum = epObj.episode
|
||||||
|
if epNum in multiResults:
|
||||||
|
multiNotNeededEps.append(epNum)
|
||||||
|
else:
|
||||||
|
multiNeededEps.append(epNum)
|
||||||
|
|
||||||
|
logger.log(
|
||||||
|
u"Multi-ep check result is multiNeededEps: " + str(multiNeededEps) + ", multiNotNeededEps: " + str(
|
||||||
|
multiNotNeededEps), logger.DEBUG)
|
||||||
|
|
||||||
|
if not multiNeededEps:
|
||||||
|
logger.log(
|
||||||
|
u"All of these episodes were covered by another multi-episode nzbs, ignoring this multi-ep result",
|
||||||
|
logger.DEBUG)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# if we're keeping this multi-result then remember it
|
||||||
|
for epObj in multiResult.episodes:
|
||||||
|
multiResults[epObj.episode] = multiResult
|
||||||
|
|
||||||
|
# don't bother with the single result if we're going to get it with a multi result
|
||||||
|
for epObj in multiResult.episodes:
|
||||||
|
epNum = epObj.episode
|
||||||
|
if epNum in foundResults[provider.name]:
|
||||||
|
logger.log(u"A needed multi-episode result overlaps with a single-episode result for ep #" + str(
|
||||||
|
epNum) + ", removing the single-episode results from the list", logger.DEBUG)
|
||||||
|
del foundResults[provider.name][epNum]
|
||||||
|
|
||||||
|
finalResults += set(multiResults.values())
|
||||||
|
|
||||||
|
# of all the single ep results narrow it down to the best one for each episode
|
||||||
|
for curEp in foundResults[provider.name]:
|
||||||
|
if curEp in (MULTI_EP_RESULT, SEASON_RESULT):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# if we're keeping this multi-result then remember it
|
if len(foundResults[provider.name][curEp]) == 0:
|
||||||
for epObj in multiResult.episodes:
|
continue
|
||||||
multiResults[epObj.episode] = multiResult
|
|
||||||
|
|
||||||
# don't bother with the single result if we're going to get it with a multi result
|
result = pickBestResult(foundResults[provider.name][curEp], show)
|
||||||
for epObj in multiResult.episodes:
|
finalResults.append(result)
|
||||||
epNum = epObj.episode
|
|
||||||
if epNum in foundResults:
|
|
||||||
logger.log(u"A needed multi-episode result overlaps with a single-episode result for ep #" + str(
|
|
||||||
epNum) + ", removing the single-episode results from the list", logger.DEBUG)
|
|
||||||
del foundResults[epNum]
|
|
||||||
|
|
||||||
finalResults += set(multiResults.values())
|
logger.log(u"Checking if we should snatch " + result.name, logger.DEBUG)
|
||||||
|
any_qualities, best_qualities = Quality.splitQuality(show.quality)
|
||||||
|
|
||||||
# of all the single ep results narrow it down to the best one for each episode
|
# if there is a redownload that's higher than this then we definitely need to keep looking
|
||||||
for curEp in foundResults:
|
if best_qualities and result.quality == max(best_qualities):
|
||||||
if curEp in (MULTI_EP_RESULT, SEASON_RESULT):
|
queueItem.results = [result]
|
||||||
continue
|
return queueItem
|
||||||
|
|
||||||
if len(foundResults[curEp]) == 0:
|
# if there's no redownload that's higher (above) and this is the highest initial download then we're good
|
||||||
continue
|
elif any_qualities and result.quality in any_qualities:
|
||||||
|
queueItem.results = [result]
|
||||||
finalResults.append(pickBestResult(foundResults[curEp], show))
|
return queueItem
|
||||||
|
|
||||||
queueItem.results = finalResults
|
queueItem.results = finalResults
|
||||||
return queueItem
|
return queueItem
|
||||||
|
@ -29,7 +29,6 @@ from sickbeard import db, logger, common, exceptions, helpers
|
|||||||
from sickbeard import generic_queue, scheduler
|
from sickbeard import generic_queue, scheduler
|
||||||
from sickbeard import search, failed_history, history
|
from sickbeard import search, failed_history, history
|
||||||
from sickbeard import ui
|
from sickbeard import ui
|
||||||
from sickbeard.snatch_queue import SnatchQueue
|
|
||||||
|
|
||||||
search_queue_lock = threading.Lock()
|
search_queue_lock = threading.Lock()
|
||||||
|
|
||||||
@ -89,6 +88,14 @@ class SearchQueue(generic_queue.GenericQueue):
|
|||||||
else:
|
else:
|
||||||
logger.log(u"Not adding item, it's already in the queue", logger.DEBUG)
|
logger.log(u"Not adding item, it's already in the queue", logger.DEBUG)
|
||||||
|
|
||||||
|
def snatch_item(self, item):
|
||||||
|
for result in item.results:
|
||||||
|
# just use the first result for now
|
||||||
|
logger.log(u"Downloading " + result.name + " from " + result.provider.name)
|
||||||
|
status = search.snatchEpisode(result)
|
||||||
|
item.success = status
|
||||||
|
generic_queue.QueueItem.finish(item)
|
||||||
|
return status
|
||||||
|
|
||||||
class ManualSearchQueueItem(generic_queue.QueueItem):
|
class ManualSearchQueueItem(generic_queue.QueueItem):
|
||||||
def __init__(self, ep_obj):
|
def __init__(self, ep_obj):
|
||||||
@ -104,31 +111,15 @@ class ManualSearchQueueItem(generic_queue.QueueItem):
|
|||||||
|
|
||||||
didSearch = False
|
didSearch = False
|
||||||
|
|
||||||
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
|
|
||||||
try:
|
try:
|
||||||
for provider in providers:
|
logger.log("Beginning manual search for [" + self.ep_obj.prettyName() + "]")
|
||||||
thread_name = self.thread_name + str(provider.name).upper()
|
searchResult = search.searchProviders(self, self.show, self.ep_obj.season, [self.ep_obj],False,True)
|
||||||
threading.currentThread().name = thread_name
|
|
||||||
|
|
||||||
logger.log("Beginning manual search for [" + self.ep_obj.prettyName() + "]")
|
if searchResult:
|
||||||
searchResult = search.searchProviders(self, self.show, self.ep_obj.season, [self.ep_obj], provider,
|
self.success = SearchQueue().snatch_item(searchResult)
|
||||||
False,
|
|
||||||
True)
|
|
||||||
|
|
||||||
didSearch = True
|
|
||||||
if searchResult:
|
|
||||||
self.success = SnatchQueue().process_results(searchResult)
|
|
||||||
if self.success:
|
|
||||||
break
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
stop = True
|
|
||||||
|
|
||||||
if not didSearch:
|
|
||||||
logger.log(
|
|
||||||
u"No NZB/Torrent providers found or enabled in your SickRage config. Please check your settings.",
|
|
||||||
logger.ERROR)
|
|
||||||
|
|
||||||
if not self.success:
|
if not self.success:
|
||||||
ui.notifications.message('No downloads were found',
|
ui.notifications.message('No downloads were found',
|
||||||
@ -194,28 +185,15 @@ class BacklogQueueItem(generic_queue.QueueItem):
|
|||||||
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive() and x]
|
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive() and x]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for provider in providers:
|
logger.log("Beginning backlog search for episodes from [" + self.show.name + "] - Season[" + str(self.segment) + "]")
|
||||||
thread_name = self.thread_name + str(provider.name).upper()
|
searchResult = search.searchProviders(self, self.show, self.segment, self.wantedEpisodes, seasonSearch, False)
|
||||||
threading.currentThread().name = thread_name
|
|
||||||
|
|
||||||
logger.log("Beginning backlog search for episodes from [" + self.show.name + "] - Season[" + str(self.segment) + "]")
|
if searchResult:
|
||||||
searchResult = search.searchProviders(self, self.show, self.segment, self.wantedEpisodes, provider,
|
self.success = SearchQueue().snatch_item(searchResult)
|
||||||
seasonSearch, False)
|
|
||||||
|
|
||||||
didSearch = True
|
|
||||||
if searchResult:
|
|
||||||
self.success = SnatchQueue().process_results(searchResult)
|
|
||||||
if self.success:
|
|
||||||
break
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
|
|
||||||
if not didSearch:
|
|
||||||
logger.log(
|
|
||||||
u"No NZB/Torrent providers found or enabled in your SickRage config. Please check your settings.",
|
|
||||||
logger.ERROR)
|
|
||||||
|
|
||||||
if not self.success:
|
if not self.success:
|
||||||
logger.log(u"No needed episodes found during backlog search")
|
logger.log(u"No needed episodes found during backlog search")
|
||||||
|
|
||||||
@ -274,30 +252,16 @@ class FailedQueueItem(generic_queue.QueueItem):
|
|||||||
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
|
providers = [x for x in sickbeard.providers.sortedProviderList() if x.isActive()]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for provider in providers:
|
logger.log(
|
||||||
thread_name = self.thread_name + str(provider.name).upper()
|
"Beginning failed download search for episodes from Season [" + self.episodes[0].season + "]")
|
||||||
threading.currentThread().name = thread_name
|
|
||||||
|
|
||||||
logger.log(
|
searchResult = search.searchProviders(self.show, self.episodes[0].season, self.episodes, False, True)
|
||||||
"Beginning failed download search for episodes from Season [" + self.episodes[0].season + "]")
|
if searchResult:
|
||||||
|
self.success = SearchQueue().snatch_item(searchResult)
|
||||||
searchResult = search.searchProviders(self.show, self.episodes[0].season, self.episodes, provider,
|
|
||||||
False, True)
|
|
||||||
|
|
||||||
didSearch = True
|
|
||||||
if searchResult:
|
|
||||||
self.success = SnatchQueue().process_results(searchResult)
|
|
||||||
if self.success:
|
|
||||||
break
|
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.log(traceback.format_exc(), logger.DEBUG)
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
||||||
|
|
||||||
if not didSearch:
|
|
||||||
logger.log(
|
|
||||||
u"No NZB/Torrent providers found or enabled in your SickRage config. Please check your settings.",
|
|
||||||
logger.ERROR)
|
|
||||||
|
|
||||||
if not self.success:
|
if not self.success:
|
||||||
logger.log(u"No needed episodes found on the RSS feeds")
|
logger.log(u"No needed episodes found on the RSS feeds")
|
||||||
|
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
import Queue
|
|
||||||
import threading
|
|
||||||
|
|
||||||
import sickbeard
|
|
||||||
from sickbeard import logger, search, generic_queue, ui
|
|
||||||
from sickbeard.common import Quality
|
|
||||||
|
|
||||||
snatch_queue_lock = threading.Lock()
|
|
||||||
|
|
||||||
class SnatchQueue(generic_queue.GenericQueue):
|
|
||||||
def __init__(self):
|
|
||||||
generic_queue.GenericQueue.__init__(self)
|
|
||||||
self.queue_name = "SNATCHQUEUE"
|
|
||||||
|
|
||||||
# snatch queues
|
|
||||||
self.ManualQueue = Queue.Queue()
|
|
||||||
self.BacklogQueue = Queue.Queue()
|
|
||||||
self.FailedQueue = Queue.Queue()
|
|
||||||
|
|
||||||
def is_in_queue(self, queue, show, episodes, quality):
|
|
||||||
for i, cur_item in enumerate(queue.queue):
|
|
||||||
if cur_item.results.show == show and cur_item.results.episodes.sort() == episodes.sort():
|
|
||||||
if cur_item.results.quality < quality:
|
|
||||||
queue.queue.pop(i)
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def add_item(self, item):
|
|
||||||
resultsKeep = []
|
|
||||||
for result in item.results:
|
|
||||||
show = result.extraInfo[0]
|
|
||||||
episodes = result.episodes
|
|
||||||
quality = result.quality
|
|
||||||
|
|
||||||
# check if we already have a item ready to snatch with same or better quality score
|
|
||||||
if not self.is_in_queue(self.queue, show, episodes, quality):
|
|
||||||
generic_queue.GenericQueue.add_item(self, item)
|
|
||||||
resultsKeep.append(result)
|
|
||||||
logger.log(
|
|
||||||
u"Adding item [" + result.name + "] to snatch queue",
|
|
||||||
logger.DEBUG)
|
|
||||||
else:
|
|
||||||
logger.log(
|
|
||||||
u"Not adding item [" + result.name + "] it's already in the queue with same or higher quality",
|
|
||||||
logger.DEBUG)
|
|
||||||
|
|
||||||
# update item with new results we want to snatch and disgard the rest
|
|
||||||
item.results = resultsKeep
|
|
||||||
|
|
||||||
def snatch_item(self, item):
|
|
||||||
for result in item.results:
|
|
||||||
# just use the first result for now
|
|
||||||
logger.log(u"Downloading " + result.name + " from " + result.provider.name)
|
|
||||||
status = search.snatchEpisode(result)
|
|
||||||
item.success = status
|
|
||||||
generic_queue.QueueItem.finish(item)
|
|
||||||
return status
|
|
||||||
|
|
||||||
def process_results(self, item):
|
|
||||||
# dynamically select our snatch queue
|
|
||||||
if isinstance(item, sickbeard.search_queue.ManualSearchQueueItem):
|
|
||||||
self.queue = self.ManualQueue
|
|
||||||
elif isinstance(item, sickbeard.search_queue.BacklogQueueItem):
|
|
||||||
self.queue = self.BacklogQueue
|
|
||||||
elif isinstance(item, sickbeard.search_queue.FailedQueueItem):
|
|
||||||
self.queue = self.FailedQueue
|
|
||||||
|
|
||||||
for result in item.results:
|
|
||||||
logger.log(u"Checking if we should snatch " + result.name, logger.DEBUG)
|
|
||||||
show_obj = result.episodes[0].show
|
|
||||||
any_qualities, best_qualities = Quality.splitQuality(show_obj.quality)
|
|
||||||
|
|
||||||
# if there is a redownload that's higher than this then we definitely need to keep looking
|
|
||||||
if best_qualities and result.quality == max(best_qualities):
|
|
||||||
return self.snatch_item(item)
|
|
||||||
|
|
||||||
# if there's no redownload that's higher (above) and this is the highest initial download then we're good
|
|
||||||
elif any_qualities and result.quality in any_qualities:
|
|
||||||
return self.snatch_item(item)
|
|
||||||
|
|
||||||
# Add item to queue if we couldn't find a match to snatch
|
|
||||||
self.add_item(item)
|
|
@ -1158,6 +1158,8 @@ class TVEpisode(object):
|
|||||||
|
|
||||||
self.specifyEpisode(self.season, self.episode)
|
self.specifyEpisode(self.season, self.episode)
|
||||||
|
|
||||||
|
self.convertToSceneNumbering()
|
||||||
|
|
||||||
self.relatedEps = []
|
self.relatedEps = []
|
||||||
|
|
||||||
self.checkForMetaFiles()
|
self.checkForMetaFiles()
|
||||||
|
Loading…
Reference in New Issue
Block a user