From 690e842bb1f3b698f1dc525620b16cae828593b2 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 26 Apr 2014 00:09:00 -0700 Subject: [PATCH] Fix for SSL issues. Fix for Download Station issues. --- sickbeard/clients/download_station.py | 80 ++++++++++++++------------- sickbeard/clients/generic.py | 19 ++++--- sickbeard/clients/utorrent.py | 2 +- sickbeard/providers/iptorrents.py | 2 +- sickbeard/providers/nextgen.py | 4 +- sickbeard/providers/torrentday.py | 2 +- sickbeard/providers/torrentleech.py | 2 +- tests/tests.py | 18 ++++-- 8 files changed, 74 insertions(+), 55 deletions(-) diff --git a/sickbeard/clients/download_station.py b/sickbeard/clients/download_station.py index fdc329f0..a1017cb6 100644 --- a/sickbeard/clients/download_station.py +++ b/sickbeard/clients/download_station.py @@ -1,7 +1,5 @@ -# Authors: -# Pedro Jose Pereira Vieito (Twitter: @pvieito) -# -# URL: https://github.com/echel0n/SickBeard-TVRage +# Authors: Mr_Orange & Jens Timmerman +# URL: https://github.com/mr-orange/Sick-Beard # # This file is part of Sick Beard. # @@ -17,56 +15,64 @@ # # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . -# -# 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) - + self.url = self.host + 'webapi/DownloadStation/task.cgi' def _get_auth(self): + + params = {'api': 'SYNO.API.Auth', + 'version': '2', + 'method': 'login', + 'account': self.username, + 'passwd': self.password, + 'session': 'SickBeard', + 'format': 'sid', + } - 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' - - 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', - '_sid': self.auth, - 'uri': result.url - } - self._request(method='post', data=data) - - return self.response.json()['success'] - + params = {'api': 'SYNO.DownloadStation.Task', + 'version': '1', + 'method': 'create', + '_sid': self.auth, + 'uri': result.url, + } + + self._request(method='get', params=params) + + return self.response.json["success"] + def _add_torrent_file(self, result): - data = {'api': 'SYNO.DownloadStation.Task', - 'version': '1', - 'method': 'create', - 'session': 'DownloadStation', - '_sid': self.auth - } - files = {'file': (result.name + '.torrent', result.content)} - self._request(method='post', data=data, files=files) - - return self.response.json()['success'] - - -api = DownloadStationAPI() + params = {'api': 'SYNO.DownloadStation.Task', + 'version': '1', + 'method': 'create', + '_sid': self.auth, + 'file': 'tv.torrent', + } + + self._request(method='get', params=params, files={'file': result.content}) + + return self.response.json["success"] + +api = DownloadStationAPI() \ No newline at end of file diff --git a/sickbeard/clients/generic.py b/sickbeard/clients/generic.py index 253ca07e..dce85c7f 100644 --- a/sickbeard/clients/generic.py +++ b/sickbeard/clients/generic.py @@ -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) @@ -81,28 +86,28 @@ class GenericClient(object): def _add_torrent_uri(self, result): """ - This should be overridden should return the True/False from the client + This should be overridden should return the True/False from the client when a torrent is added via url (magnet or .torrent link) """ return False def _add_torrent_file(self, result): """ - This should be overridden should return the True/False from the client + This should be overridden should return the True/False from the client when a torrent is added via result.content (only .torrent file) """ return False def _set_torrent_label(self, result): """ - This should be overridden should return the True/False from the client + This should be overridden should return the True/False from the client when a torrent is set with label """ return True def _set_torrent_ratio(self, result): """ - This should be overridden should return the True/False from the client + This should be overridden should return the True/False from the client when a torrent is set with ratio """ return True @@ -116,14 +121,14 @@ class GenericClient(object): def _set_torrent_path(self, torrent_path): """ - This should be overridden should return the True/False from the client + This should be overridden should return the True/False from the client when a torrent is set with path """ return True def _set_torrent_pause(self, result): """ - This should be overridden should return the True/False from the client + This should be overridden should return the True/False from the client when a torrent is set with pause """ return True diff --git a/sickbeard/clients/utorrent.py b/sickbeard/clients/utorrent.py index 321de455..adfb3bfe 100644 --- a/sickbeard/clients/utorrent.py +++ b/sickbeard/clients/utorrent.py @@ -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("(.*?). 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() \ No newline at end of file