FIX:(#1091) When trying to retrieve torrents from KAT, would create invalid torrent files

This commit is contained in:
evilhero 2015-07-22 17:00:45 -04:00
parent abcc4e88ec
commit ec31c9ec9d
2 changed files with 26 additions and 6 deletions

View File

@ -1741,15 +1741,21 @@ def create_https_certificates(ssl_cert, ssl_key):
return True
def torrent_create(site, linkid):
def torrent_create(site, linkid, alt=None):
if site == '32P':
pass
elif site == 'KAT':
if 'http' in linkid:
#if it's being passed here with the http alread in, then it's an old rssdb entry and we can take it as is.
url = linkid
if alt is None:
#if it's being passed here with the http alread in, then it's an old rssdb entry and we can take it as is.
url = linkid
else:
url = re.sub('http://torcache.net/','http://torrage.com/', linkid).strip()
else:
url = 'http://torcache.net/torrent/' + str(linkid) + '.torrent'
if alt is None:
url = 'http://torcache.net/torrent/' + str(linkid) + '.torrent'
else:
url = 'http://torrage.com/torrent/' + str(linkid) + '.torrent'
return url

View File

@ -738,10 +738,11 @@ def torsend2client(seriesname, issue, seriesyear, linkit, site):
else:
kat_referrer = linkit[:stfind]
logger.fdebug('KAT Referer set to :' + kat_referrer)
#logger.fdebug('KAT Referer set to :' + kat_referrer)
headers = {'Accept-encoding': 'gzip',
'Referer': kat_referrer}
'User-Agent': str(mylar.USER_AGENT)}
#'Referer': kat_referrer}
url = helpers.torrent_create('KAT', linkit)
@ -786,6 +787,19 @@ def torsend2client(seriesname, issue, seriesyear, linkit, site):
else:
return "fail"
if str(r.status_code) == '403':
#retry with the alternate torrent link.
url = helpers.torrent_create('KAT', linkit, True)
try:
r = requests.get(url, params=payload, verify=verify, stream=True, headers=headers)
except Exception, e:
return "fail"
if str(r.status_code) != '200':
logger.warn('Unable to download torrent from ' + site + ' [Status Code returned: ' + str(r.status_code) + ']')
return "fail"
if site == 'KAT':
if r.headers.get('Content-Encoding') == 'gzip':
buf = StringIO(r.content)