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
# hash
self.hash = ""
self.hash = None
# content
self.content = ""
self.content = None
def __str__(self):

View File

@ -147,7 +147,6 @@ class GenericClient(object):
if len(result.hash) == 32:
result.hash = b16encode(b32decode(result.hash)).lower()
else:
result.content = result.provider.getURL(result.url)
info = bdecode(result.content)["info"]
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)
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)
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)
return
return resp.content if not json else resp.json()
def download_file(url, filename, session=None):

View File

@ -143,55 +143,57 @@ class ProperFinder():
curProper.release_group = parse_result.release_group
curProper.version = parse_result.version
curProper.quality = Quality.nameQuality(curProper.name, parse_result.is_anime)
curProper.content = None
# 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)
continue
# only get anime proper if it has release group and version
if parse_result.is_anime:
if not curProper.release_group and curProper.version == -1:
logger.log(u"Proper " + curProper.name + " doesn't have a release group and version, ignoring it",
if bestResult.show.is_anime:
if not bestResult.release_group and bestResult.version == -1:
logger.log(u"Proper " + bestResult.name + " doesn't have a release group and version, ignoring it",
logger.DEBUG)
continue
# check if we actually want this proper (if it's the right quality)
myDB = db.DBConnection()
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:
continue
# 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"]))
if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != curProper.quality:
if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != bestResult.quality:
continue
# 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()
sqlResults = myDB.select(
"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"])
oldRelease_group = (sqlResults[0]["release_group"])
if oldVersion > -1 and oldVersion < curProper.version:
logger.log("Found new anime v" + str(curProper.version) + " to replace existing v" + str(oldVersion))
if oldVersion > -1 and oldVersion < bestResult.version:
logger.log("Found new anime v" + str(bestResult.version) + " to replace existing v" + str(oldVersion))
else:
continue
if oldRelease_group != curProper.release_group:
logger.log("Skipping proper from release group: " + curProper.release_group + ", does not match existing release group: " + oldRelease_group)
if oldRelease_group != bestResult.release_group:
logger.log("Skipping proper from release group: " + bestResult.release_group + ", does not match existing release group: " + oldRelease_group)
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 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):
logger.log(u"Found a proper that we need: " + str(curProper.name))
finalPropers.append(curProper)
logger.log(u"Found a proper that we need: " + str(bestResult.name))
finalPropers.append(bestResult)
return finalPropers
@ -231,12 +233,7 @@ class ProperFinder():
continue
# get the episode object
showObj = helpers.findCertainShow(sickbeard.showList, curProper.indexerid)
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)
epObj = curProper.show.getEpisode(curProper.season, curProper.episode)
# make the result object
result = curProper.provider.getResult([epObj])

View File

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

View File

@ -130,15 +130,7 @@ def snatchEpisode(result, endStatus=SNATCHED):
if sickbeard.TORRENT_METHOD == "blackhole":
dlResult = _downloadResult(result)
else:
# make sure we have the torrent file content
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
#result.content = result.provider.getURL(result.url) if not result.url.startswith('magnet') else None
client = clients.getClientIstance(sickbeard.TORRENT_METHOD)()
dlResult = client.sendTORRENT(result)
else:
@ -208,6 +200,13 @@ def pickBestResult(results, show=None, quality_list=None):
if show and cur_result.show is not show:
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
if not bwl and cur_result.show.is_anime:
bwl = BlackAndWhiteList(cur_result.show.indexerid)
@ -397,12 +396,6 @@ def searchForNeededEpisodes():
# pick a single result for each episode, respecting existing results
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)
# 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:
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
threading.currentThread().name = origThreadName
@ -534,8 +519,8 @@ def searchProviders(show, episodes, manualSearch=False):
# see if every episode is wanted
if bestSeasonResult:
searchedSeasons = []
searchedSeasons = [str(x.season) for x in episodes]
# get the quality of the season nzb
seasonQual = bestSeasonResult.quality
logger.log(
@ -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)
epObjs = []
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
return [bestSeasonResult]
@ -681,23 +667,14 @@ def searchProviders(show, episodes, manualSearch=False):
if curEp in (MULTI_EP_RESULT, SEASON_RESULT):
continue
if len(foundResults[curProvider.name][curEp]) == 0:
if not len(foundResults[curProvider.name][curEp]) > 0:
continue
bestResult = pickBestResult(foundResults[curProvider.name][curEp], show)
# if all results were rejected move on to the next episode
bestResult = pickBestResult(foundResults[curProvider.name][curEp], show)
if not bestResult:
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
found = False
for i, result in enumerate(finalResults):

View File

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