Fix for SSL issues.

Fix for Download Station issues.
This commit is contained in:
echel0n 2014-04-26 00:09:00 -07:00
parent 07cee09c83
commit 690e842bb1
8 changed files with 74 additions and 55 deletions

View file

@ -1,7 +1,5 @@
# Authors:
# Pedro Jose Pereira Vieito <pvieito@gmail.com> (Twitter: @pvieito)
#
# URL: https://github.com/echel0n/SickBeard-TVRage
# Authors: Mr_Orange & Jens Timmerman <jens.timmerman@gmail.com>
# URL: https://github.com/mr-orange/Sick-Beard
#
# This file is part of Sick Beard.
#
@ -17,14 +15,14 @@
#
# You should have received a copy of the GNU General Public License
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
#
# Uses the Synology Download Station API: http://download.synology.com/download/other/Synology_Download_Station_Official_API_V3.pdf.
import sickbeard
from sickbeard import logger
from sickbeard.clients.generic import GenericClient
class DownloadStationAPI(GenericClient):
def __init__(self, host=None, username=None, password=None):
super(DownloadStationAPI, self).__init__('DownloadStation', host, username, password)
@ -33,40 +31,48 @@ class DownloadStationAPI(GenericClient):
def _get_auth(self):
auth_url = self.host + 'webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=' + self.username + '&passwd=' + self.password + '&session=DownloadStation&format=sid'
params = {'api': 'SYNO.API.Auth',
'version': '2',
'method': 'login',
'account': self.username,
'passwd': self.password,
'session': 'SickBeard',
'format': 'sid',
}
try:
self.response = self.session.get(auth_url)
self.auth = self.response.json()['data']['sid']
except:
self.response = self.session.get(self.host + 'webapi/auth.cgi', params=params)
if not self.response.json["success"]:
return None
self.auth = self.response.json["data"]["sid"]
return self.auth
def _add_torrent_uri(self, result):
data = {'api': 'SYNO.DownloadStation.Task',
'version': '1', 'method': 'create',
'session': 'DownloadStation',
params = {'api': 'SYNO.DownloadStation.Task',
'version': '1',
'method': 'create',
'_sid': self.auth,
'uri': result.url
'uri': result.url,
}
self._request(method='post', data=data)
return self.response.json()['success']
self._request(method='get', params=params)
return self.response.json["success"]
def _add_torrent_file(self, result):
data = {'api': 'SYNO.DownloadStation.Task',
params = {'api': 'SYNO.DownloadStation.Task',
'version': '1',
'method': 'create',
'session': 'DownloadStation',
'_sid': self.auth
'_sid': self.auth,
'file': 'tv.torrent',
}
files = {'file': (result.name + '.torrent', result.content)}
self._request(method='post', data=data, files=files)
return self.response.json()['success']
self._request(method='get', params=params, files={'file': result.content})
return self.response.json["success"]
api = DownloadStationAPI()

View file

@ -37,10 +37,15 @@ class GenericClient(object):
params) + ' Data=' + str(data if data else 'None')[0:99] + (
'...' if len(data if data else 'None') > 200 else ''), logger.DEBUG)
logger.log(
self.name + u': Requested a ' + method.upper() + ' connection to url ' + self.url + ' with Params= ' + str(
params) + (
(' Data=' + str(data)[0:100] + ('...' if len(data) > 100 else '')) if data is not None else ""),
logger.DEBUG)
if not self.auth:
logger.log(self.name + u': Authentication Failed', logger.ERROR)
return False
try:
self.response = self.session.__getattribute__(method)(self.url, params=params, data=data, files=files,
timeout=10, verify=False)

View file

@ -37,7 +37,7 @@ class uTorrentAPI(GenericClient):
def _get_auth(self):
try:
self.response = self.session.get(self.url + 'token.html')
self.response = self.session.get(self.url + 'token.html', verify=False)
self.auth = re.findall("<div.*?>(.*?)</", self.response.text)[0]
except:
return None

View file

@ -233,7 +233,7 @@ class IPTorrentsProvider(generic.TorrentProvider):
parsed = list(urlparse.urlparse(url))
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
url = urlparse.urlunparse(parsed)
response = self.session.get(url)
response = self.session.get(url, verify=False)
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
return None

View file

@ -110,7 +110,7 @@ class NextGenProvider(generic.TorrentProvider):
self.session = requests.Session()
self.session.headers.update(
{'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20130519 Firefox/24.0)'})
data = self.session.get(self.urls['login_page'])
data = self.session.get(self.urls['login_page'], verify=False)
bs = BeautifulSoup(data.content.decode('iso-8859-1'))
csrfraw = bs.find('form', attrs={'id': 'login'})['action']
output = self.session.post(self.urls['base_url'] + csrfraw, data=login_params)
@ -279,7 +279,7 @@ class NextGenProvider(generic.TorrentProvider):
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
url = urlparse.urlunparse(parsed)
response = self.session.get(url)
response = self.session.get(url, verify=False)
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
return None

View file

@ -229,7 +229,7 @@ class TorrentDayProvider(generic.TorrentProvider):
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
url = urlparse.urlunparse(parsed)
response = self.session.get(url)
response = self.session.get(url, verify=False)
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
return None

View file

@ -232,7 +232,7 @@ class TorrentLeechProvider(generic.TorrentProvider):
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
url = urlparse.urlunparse(parsed)
response = self.session.get(url)
response = self.session.get(url, verify=False)
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
return None

View file

@ -18,24 +18,32 @@
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
import re
import unittest
import sys, os.path
sys.path.append(os.path.abspath('..'))
sys.path.append(os.path.abspath('../lib'))
import sickbeard
from lib.feedparser import feedparser
class APICheck(unittest.TestCase):
data = feedparser.parse('http://pirateproxy.net/tv/latest/')
resultFilters = ["sub(pack|s|bed)", "swesub(bed)?",
"(dir|sample|sub|nfo)fix", "sample", "(dvd)?extras",
"dub(bed)?"]
lang = "en"
search_term = 'Gold Rush South America'
search_term = u'Watershed.-.Exploring.a.New.Water.Ethic.for.the.New.West.1080i.HDTV.DD2.0.H.264-TrollHD'
#search_term = re.escape(search_term)
results = {}
final_results = []
filters = [re.compile('(^|[\W_]|[\s_])%s($|[\W_]|[\s_])' % filter.strip(), re.I) for filter in resultFilters + sickbeard.IGNORE_WORDS.split(',')]
for regfilter in filters:
if regfilter.search(search_term):
print 'bad'
print 'good'
if __name__ == "__main__":
unittest.main()