From ec31c9ec9d75b5562efafc5843c7dd9b2818505f Mon Sep 17 00:00:00 2001 From: evilhero Date: Wed, 22 Jul 2015 17:00:45 -0400 Subject: [PATCH] FIX:(#1091) When trying to retrieve torrents from KAT, would create invalid torrent files --- mylar/helpers.py | 14 ++++++++++---- mylar/rsscheck.py | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mylar/helpers.py b/mylar/helpers.py index 8ec562b3..135d2488 100755 --- a/mylar/helpers.py +++ b/mylar/helpers.py @@ -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 diff --git a/mylar/rsscheck.py b/mylar/rsscheck.py index 480e83ee..02b369fe 100755 --- a/mylar/rsscheck.py +++ b/mylar/rsscheck.py @@ -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)