1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-04 15:12:23 -05:00
This commit is contained in:
echel0n 2014-12-24 09:19:25 -08:00
parent 450a09f1a0
commit 9fedc24c55
7 changed files with 41 additions and 71 deletions

View File

@ -108,10 +108,10 @@ class SearchResult:
self.version = -1 self.version = -1
# hash # hash
self.hash = "" self.hash = None
# content # content
self.content = "" self.content = None
def __str__(self): def __str__(self):

View File

@ -147,7 +147,6 @@ class GenericClient(object):
if len(result.hash) == 32: if len(result.hash) == 32:
result.hash = b16encode(b32decode(result.hash)).lower() result.hash = b16encode(b32decode(result.hash)).lower()
else: else:
result.content = result.provider.getURL(result.url)
info = bdecode(result.content)["info"] info = bdecode(result.content)["info"]
result.hash = sha1(bencode(info)).hexdigest() result.hash = sha1(bencode(info)).hexdigest()
@ -198,7 +197,7 @@ class GenericClient(object):
logger.log(self.name + u': Unable to set priority for Torrent', logger.ERROR) logger.log(self.name + u': Unable to set priority for Torrent', logger.ERROR)
except Exception, e: except Exception, e:
logger.log(self.name + u': Failed Sending Torrent: ' + str(result.name) + ' - ' + str(result.hash), logger.ERROR) logger.log(self.name + u': Failed Sending Torrent', logger.ERROR)
logger.log(self.name + u': Exception raised when sending torrent: ' + ex(e), logger.DEBUG) logger.log(self.name + u': Exception raised when sending torrent: ' + ex(e), logger.DEBUG)
return r_code return r_code

View File

@ -1174,7 +1174,6 @@ def getURL(url, post_data=None, params=None, headers={}, timeout=30, session=Non
logger.log(u"Unknown exception while loading URL " + url + ": " + traceback.format_exc(), logger.WARNING) logger.log(u"Unknown exception while loading URL " + url + ": " + traceback.format_exc(), logger.WARNING)
return return
return resp.content if not json else resp.json() return resp.content if not json else resp.json()
def download_file(url, filename, session=None): def download_file(url, filename, session=None):

View File

@ -143,55 +143,57 @@ class ProperFinder():
curProper.release_group = parse_result.release_group curProper.release_group = parse_result.release_group
curProper.version = parse_result.version curProper.version = parse_result.version
curProper.quality = Quality.nameQuality(curProper.name, parse_result.is_anime) curProper.quality = Quality.nameQuality(curProper.name, parse_result.is_anime)
curProper.content = None
# filter release # filter release
if not pickBestResult(curProper): bestResult = pickBestResult(curProper)
if not bestResult:
logger.log(u"Proper " + curProper.name + " were rejected by our release filters.", logger.DEBUG) logger.log(u"Proper " + curProper.name + " were rejected by our release filters.", logger.DEBUG)
continue continue
# only get anime proper if it has release group and version # only get anime proper if it has release group and version
if parse_result.is_anime: if bestResult.show.is_anime:
if not curProper.release_group and curProper.version == -1: if not bestResult.release_group and bestResult.version == -1:
logger.log(u"Proper " + curProper.name + " doesn't have a release group and version, ignoring it", logger.log(u"Proper " + bestResult.name + " doesn't have a release group and version, ignoring it",
logger.DEBUG) logger.DEBUG)
continue continue
# check if we actually want this proper (if it's the right quality) # check if we actually want this proper (if it's the right quality)
myDB = db.DBConnection() myDB = db.DBConnection()
sqlResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?", sqlResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
[curProper.indexerid, curProper.season, curProper.episode]) [bestResult.indexerid, bestResult.season, bestResult.episode])
if not sqlResults: if not sqlResults:
continue continue
# only keep the proper if we have already retrieved the same quality ep (don't get better/worse ones) # only keep the proper if we have already retrieved the same quality ep (don't get better/worse ones)
oldStatus, oldQuality = Quality.splitCompositeStatus(int(sqlResults[0]["status"])) oldStatus, oldQuality = Quality.splitCompositeStatus(int(sqlResults[0]["status"]))
if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != curProper.quality: if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != bestResult.quality:
continue continue
# check if we actually want this proper (if it's the right release group and a higher version) # check if we actually want this proper (if it's the right release group and a higher version)
if parse_result.is_anime: if bestResult.show.is_anime:
myDB = db.DBConnection() myDB = db.DBConnection()
sqlResults = myDB.select( sqlResults = myDB.select(
"SELECT release_group, version FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?", "SELECT release_group, version FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
[curProper.indexerid, curProper.season, curProper.episode]) [bestResult.indexerid, bestResult.season, bestResult.episode])
oldVersion = int(sqlResults[0]["version"]) oldVersion = int(sqlResults[0]["version"])
oldRelease_group = (sqlResults[0]["release_group"]) oldRelease_group = (sqlResults[0]["release_group"])
if oldVersion > -1 and oldVersion < curProper.version: if oldVersion > -1 and oldVersion < bestResult.version:
logger.log("Found new anime v" + str(curProper.version) + " to replace existing v" + str(oldVersion)) logger.log("Found new anime v" + str(bestResult.version) + " to replace existing v" + str(oldVersion))
else: else:
continue continue
if oldRelease_group != curProper.release_group: if oldRelease_group != bestResult.release_group:
logger.log("Skipping proper from release group: " + curProper.release_group + ", does not match existing release group: " + oldRelease_group) logger.log("Skipping proper from release group: " + bestResult.release_group + ", does not match existing release group: " + oldRelease_group)
continue continue
# if the show is in our list and there hasn't been a proper already added for that particular episode then add it to our list of propers # if the show is in our list and there hasn't been a proper already added for that particular episode then add it to our list of propers
if curProper.indexerid != -1 and (curProper.indexerid, curProper.season, curProper.episode) not in map( if bestResult.indexerid != -1 and (bestResult.indexerid, bestResult.season, bestResult.episode) not in map(
operator.attrgetter('indexerid', 'season', 'episode'), finalPropers): operator.attrgetter('indexerid', 'season', 'episode'), finalPropers):
logger.log(u"Found a proper that we need: " + str(curProper.name)) logger.log(u"Found a proper that we need: " + str(bestResult.name))
finalPropers.append(curProper) finalPropers.append(bestResult)
return finalPropers return finalPropers
@ -231,12 +233,7 @@ class ProperFinder():
continue continue
# get the episode object # get the episode object
showObj = helpers.findCertainShow(sickbeard.showList, curProper.indexerid) epObj = curProper.show.getEpisode(curProper.season, curProper.episode)
if showObj == None:
logger.log(u"Unable to find the show with indexerid " + str(
curProper.indexerid) + " so unable to download the proper", logger.ERROR)
continue
epObj = showObj.getEpisode(curProper.season, curProper.episode)
# make the result object # make the result object
result = curProper.provider.getResult([epObj]) result = curProper.provider.getResult([epObj])

View File

@ -424,8 +424,8 @@ class GenericProvider:
result.name = title result.name = title
result.quality = quality result.quality = quality
result.release_group = release_group result.release_group = release_group
result.content = None
result.version = version result.version = version
result.content = None
if len(epObj) == 1: if len(epObj) == 1:
epNum = epObj[0].episode epNum = epObj[0].episode

View File

@ -130,15 +130,7 @@ def snatchEpisode(result, endStatus=SNATCHED):
if sickbeard.TORRENT_METHOD == "blackhole": if sickbeard.TORRENT_METHOD == "blackhole":
dlResult = _downloadResult(result) dlResult = _downloadResult(result)
else: else:
# make sure we have the torrent file content #result.content = result.provider.getURL(result.url) if not result.url.startswith('magnet') else None
if not result.content:
if not result.url.startswith('magnet'):
result.content = result.provider.getURL(result.url)
if not result.content:
logger.log(
u"Torrent content failed to download from " + result.url, logger.ERROR
)
# Snatches torrent with client
client = clients.getClientIstance(sickbeard.TORRENT_METHOD)() client = clients.getClientIstance(sickbeard.TORRENT_METHOD)()
dlResult = client.sendTORRENT(result) dlResult = client.sendTORRENT(result)
else: else:
@ -208,6 +200,13 @@ def pickBestResult(results, show=None, quality_list=None):
if show and cur_result.show is not show: if show and cur_result.show is not show:
continue continue
# filter out possible bad torrents from providers such as ezrss
if cur_result.resultType == "torrent" and sickbeard.TORRENT_METHOD != "blackhole":
if not cur_result.url.startswith('magnet'):
cur_result.content = cur_result.provider.getURL(cur_result.url)
if not cur_result.content:
continue
# build the black And white list # build the black And white list
if not bwl and cur_result.show.is_anime: if not bwl and cur_result.show.is_anime:
bwl = BlackAndWhiteList(cur_result.show.indexerid) bwl = BlackAndWhiteList(cur_result.show.indexerid)
@ -397,12 +396,6 @@ def searchForNeededEpisodes():
# pick a single result for each episode, respecting existing results # pick a single result for each episode, respecting existing results
for curEp in curFoundResults: for curEp in curFoundResults:
# find the best result for the current episode
bestResult = None
for curResult in curFoundResults[curEp]:
if not bestResult or bestResult.quality < curResult.quality:
bestResult = curResult
bestResult = pickBestResult(curFoundResults[curEp], curEp.show) bestResult = pickBestResult(curFoundResults[curEp], curEp.show)
# if all results were rejected move on to the next episode # if all results were rejected move on to the next episode
@ -414,14 +407,6 @@ def searchForNeededEpisodes():
if curEp in foundResults and bestResult.quality <= foundResults[curEp].quality: if curEp in foundResults and bestResult.quality <= foundResults[curEp].quality:
continue continue
# filter out possible bad torrents from providers such as ezrss
if bestResult.resultType == "torrent" and sickbeard.TORRENT_METHOD != "blackhole":
bestResult.content = None
if not bestResult.url.startswith('magnet'):
bestResult.content = bestResult.provider.getURL(bestResult.url)
if not bestResult.content:
continue
foundResults[curEp] = bestResult foundResults[curEp] = bestResult
threading.currentThread().name = origThreadName threading.currentThread().name = origThreadName
@ -534,8 +519,8 @@ def searchProviders(show, episodes, manualSearch=False):
# see if every episode is wanted # see if every episode is wanted
if bestSeasonResult: if bestSeasonResult:
searchedSeasons = []
searchedSeasons = [str(x.season) for x in episodes] searchedSeasons = [str(x.season) for x in episodes]
# get the quality of the season nzb # get the quality of the season nzb
seasonQual = bestSeasonResult.quality seasonQual = bestSeasonResult.quality
logger.log( logger.log(
@ -543,10 +528,10 @@ def searchProviders(show, episodes, manualSearch=False):
seasonQual], logger.DEBUG) seasonQual], logger.DEBUG)
myDB = db.DBConnection() myDB = db.DBConnection()
allEps = [int(x["episode"]) allEps = [int(x["episode"])
for x in myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND ( season IN ( " + ','.join(searchedSeasons) + " ) )", for x in myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND ( season IN ( " + ','.join(searchedSeasons) + " ) )",
[show.indexerid])] [show.indexerid])]
logger.log(u"Executed query: [SELECT episode FROM tv_episodes WHERE showid = %s AND season in %s]" % (show.indexerid, ','.join(searchedSeasons))) logger.log(u"Executed query: [SELECT episode FROM tv_episodes WHERE showid = %s AND season in %s]" % (show.indexerid, ','.join(searchedSeasons)))
logger.log(u"Episode list: " + str(allEps), logger.DEBUG) logger.log(u"Episode list: " + str(allEps), logger.DEBUG)
@ -565,7 +550,8 @@ def searchProviders(show, episodes, manualSearch=False):
u"Every ep in this season is needed, downloading the whole " + bestSeasonResult.provider.providerType + " " + bestSeasonResult.name) u"Every ep in this season is needed, downloading the whole " + bestSeasonResult.provider.providerType + " " + bestSeasonResult.name)
epObjs = [] epObjs = []
for curEpNum in allEps: for curEpNum in allEps:
epObjs.append(show.getEpisode(season, curEpNum)) for season in set([x.season for x in episodes]):
epObjs.append(show.getEpisode(season, curEpNum))
bestSeasonResult.episodes = epObjs bestSeasonResult.episodes = epObjs
return [bestSeasonResult] return [bestSeasonResult]
@ -681,23 +667,14 @@ def searchProviders(show, episodes, manualSearch=False):
if curEp in (MULTI_EP_RESULT, SEASON_RESULT): if curEp in (MULTI_EP_RESULT, SEASON_RESULT):
continue continue
if len(foundResults[curProvider.name][curEp]) == 0: if not len(foundResults[curProvider.name][curEp]) > 0:
continue continue
bestResult = pickBestResult(foundResults[curProvider.name][curEp], show)
# if all results were rejected move on to the next episode # if all results were rejected move on to the next episode
bestResult = pickBestResult(foundResults[curProvider.name][curEp], show)
if not bestResult: if not bestResult:
continue continue
# filter out possible bad torrents from providers such as ezrss
if bestResult.resultType == "torrent" and sickbeard.TORRENT_METHOD != "blackhole":
bestResult.content = None
if not bestResult.url.startswith('magnet'):
bestResult.content = bestResult.provider.getURL(bestResult.url)
if not bestResult.content:
continue
# add result if its not a duplicate and # add result if its not a duplicate and
found = False found = False
for i, result in enumerate(finalResults): for i, result in enumerate(finalResults):

View File

@ -28,11 +28,10 @@ import sickbeard
from sickbeard import db from sickbeard import db
from sickbeard import logger from sickbeard import logger
from sickbeard.common import Quality from sickbeard.common import Quality
from sickbeard import helpers, show_name_helpers from sickbeard import helpers
from sickbeard.exceptions import MultipleShowObjectsException, ex from sickbeard.exceptions import ex
from sickbeard.exceptions import AuthException from sickbeard.exceptions import AuthException
from sickbeard.rssfeeds import RSSFeeds from sickbeard.rssfeeds import RSSFeeds
from sickbeard import clients
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
from sickbeard import encodingKludge as ek from sickbeard import encodingKludge as ek
@ -47,8 +46,7 @@ class CacheDBConnection(db.DBConnection):
self.action( self.action(
"CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT, release_group TEXT)") "CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT, release_group TEXT)")
else: else:
sqlResults = self.select( sqlResults = self.select("SELECT url, COUNT(url) AS count FROM [" + providerName + "] GROUP BY url HAVING count > 1")
"SELECT url, COUNT(url) AS count FROM [" + providerName + "] GROUP BY url HAVING count > 1")
for cur_dupe in sqlResults: for cur_dupe in sqlResults:
self.action("DELETE FROM [" + providerName + "] WHERE url = ?", [cur_dupe["url"]]) self.action("DELETE FROM [" + providerName + "] WHERE url = ?", [cur_dupe["url"]])