mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 03:22:22 -05:00
Fix for SSL issues.
Fix for Download Station issues.
This commit is contained in:
parent
07cee09c83
commit
690e842bb1
@ -1,7 +1,5 @@
|
|||||||
# Authors:
|
# Authors: Mr_Orange & Jens Timmerman <jens.timmerman@gmail.com>
|
||||||
# Pedro Jose Pereira Vieito <pvieito@gmail.com> (Twitter: @pvieito)
|
# URL: https://github.com/mr-orange/Sick-Beard
|
||||||
#
|
|
||||||
# URL: https://github.com/echel0n/SickBeard-TVRage
|
|
||||||
#
|
#
|
||||||
# This file is part of 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
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
# 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
|
import sickbeard
|
||||||
|
from sickbeard import logger
|
||||||
from sickbeard.clients.generic import GenericClient
|
from sickbeard.clients.generic import GenericClient
|
||||||
|
|
||||||
|
|
||||||
class DownloadStationAPI(GenericClient):
|
class DownloadStationAPI(GenericClient):
|
||||||
|
|
||||||
def __init__(self, host=None, username=None, password=None):
|
def __init__(self, host=None, username=None, password=None):
|
||||||
|
|
||||||
super(DownloadStationAPI, self).__init__('DownloadStation', host, username, password)
|
super(DownloadStationAPI, self).__init__('DownloadStation', host, username, password)
|
||||||
|
|
||||||
self.url = self.host + 'webapi/DownloadStation/task.cgi'
|
self.url = self.host + 'webapi/DownloadStation/task.cgi'
|
||||||
|
|
||||||
def _get_auth(self):
|
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'
|
self.response = self.session.get(self.host + 'webapi/auth.cgi', params=params)
|
||||||
|
|
||||||
try:
|
if not self.response.json["success"]:
|
||||||
self.response = self.session.get(auth_url)
|
|
||||||
self.auth = self.response.json()['data']['sid']
|
|
||||||
except:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
self.auth = self.response.json["data"]["sid"]
|
||||||
|
|
||||||
return self.auth
|
return self.auth
|
||||||
|
|
||||||
def _add_torrent_uri(self, result):
|
def _add_torrent_uri(self, result):
|
||||||
|
|
||||||
data = {'api': 'SYNO.DownloadStation.Task',
|
params = {'api': 'SYNO.DownloadStation.Task',
|
||||||
'version': '1', 'method': 'create',
|
'version': '1',
|
||||||
'session': 'DownloadStation',
|
'method': 'create',
|
||||||
'_sid': self.auth,
|
'_sid': self.auth,
|
||||||
'uri': result.url
|
'uri': result.url,
|
||||||
}
|
}
|
||||||
self._request(method='post', data=data)
|
|
||||||
|
self._request(method='get', params=params)
|
||||||
return self.response.json()['success']
|
|
||||||
|
return self.response.json["success"]
|
||||||
|
|
||||||
def _add_torrent_file(self, result):
|
def _add_torrent_file(self, result):
|
||||||
|
|
||||||
data = {'api': 'SYNO.DownloadStation.Task',
|
params = {'api': 'SYNO.DownloadStation.Task',
|
||||||
'version': '1',
|
'version': '1',
|
||||||
'method': 'create',
|
'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)
|
self._request(method='get', params=params, files={'file': result.content})
|
||||||
|
|
||||||
return self.response.json()['success']
|
return self.response.json["success"]
|
||||||
|
|
||||||
|
api = DownloadStationAPI()
|
||||||
api = DownloadStationAPI()
|
|
@ -37,10 +37,15 @@ class GenericClient(object):
|
|||||||
params) + ' Data=' + str(data if data else 'None')[0:99] + (
|
params) + ' Data=' + str(data if data else 'None')[0:99] + (
|
||||||
'...' if len(data if data else 'None') > 200 else ''), logger.DEBUG)
|
'...' 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:
|
if not self.auth:
|
||||||
logger.log(self.name + u': Authentication Failed', logger.ERROR)
|
logger.log(self.name + u': Authentication Failed', logger.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.response = self.session.__getattribute__(method)(self.url, params=params, data=data, files=files,
|
self.response = self.session.__getattribute__(method)(self.url, params=params, data=data, files=files,
|
||||||
timeout=10, verify=False)
|
timeout=10, verify=False)
|
||||||
@ -81,28 +86,28 @@ class GenericClient(object):
|
|||||||
|
|
||||||
def _add_torrent_uri(self, result):
|
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)
|
when a torrent is added via url (magnet or .torrent link)
|
||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _add_torrent_file(self, result):
|
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)
|
when a torrent is added via result.content (only .torrent file)
|
||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _set_torrent_label(self, result):
|
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
|
when a torrent is set with label
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _set_torrent_ratio(self, result):
|
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
|
when a torrent is set with ratio
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
@ -116,14 +121,14 @@ class GenericClient(object):
|
|||||||
|
|
||||||
def _set_torrent_path(self, torrent_path):
|
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
|
when a torrent is set with path
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _set_torrent_pause(self, result):
|
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
|
when a torrent is set with pause
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
@ -37,7 +37,7 @@ class uTorrentAPI(GenericClient):
|
|||||||
def _get_auth(self):
|
def _get_auth(self):
|
||||||
|
|
||||||
try:
|
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]
|
self.auth = re.findall("<div.*?>(.*?)</", self.response.text)[0]
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
@ -233,7 +233,7 @@ class IPTorrentsProvider(generic.TorrentProvider):
|
|||||||
parsed = list(urlparse.urlparse(url))
|
parsed = list(urlparse.urlparse(url))
|
||||||
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
||||||
url = urlparse.urlunparse(parsed)
|
url = urlparse.urlunparse(parsed)
|
||||||
response = self.session.get(url)
|
response = self.session.get(url, verify=False)
|
||||||
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
||||||
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
||||||
return None
|
return None
|
||||||
|
@ -110,7 +110,7 @@ class NextGenProvider(generic.TorrentProvider):
|
|||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.headers.update(
|
self.session.headers.update(
|
||||||
{'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20130519 Firefox/24.0)'})
|
{'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'))
|
bs = BeautifulSoup(data.content.decode('iso-8859-1'))
|
||||||
csrfraw = bs.find('form', attrs={'id': 'login'})['action']
|
csrfraw = bs.find('form', attrs={'id': 'login'})['action']
|
||||||
output = self.session.post(self.urls['base_url'] + csrfraw, data=login_params)
|
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
|
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
||||||
url = urlparse.urlunparse(parsed)
|
url = urlparse.urlunparse(parsed)
|
||||||
|
|
||||||
response = self.session.get(url)
|
response = self.session.get(url, verify=False)
|
||||||
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
||||||
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
||||||
return None
|
return None
|
||||||
|
@ -229,7 +229,7 @@ class TorrentDayProvider(generic.TorrentProvider):
|
|||||||
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
||||||
url = urlparse.urlunparse(parsed)
|
url = urlparse.urlunparse(parsed)
|
||||||
|
|
||||||
response = self.session.get(url)
|
response = self.session.get(url, verify=False)
|
||||||
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
||||||
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
||||||
return None
|
return None
|
||||||
|
@ -232,7 +232,7 @@ class TorrentLeechProvider(generic.TorrentProvider):
|
|||||||
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
|
||||||
url = urlparse.urlunparse(parsed)
|
url = urlparse.urlunparse(parsed)
|
||||||
|
|
||||||
response = self.session.get(url)
|
response = self.session.get(url, verify=False)
|
||||||
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
|
||||||
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
logger.log(u"Error loading " + self.name + " URL: " + ex(e), logger.ERROR)
|
||||||
return None
|
return None
|
||||||
|
@ -18,24 +18,32 @@
|
|||||||
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
import re
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import sys, os.path
|
import sys, os.path
|
||||||
|
|
||||||
sys.path.append(os.path.abspath('..'))
|
sys.path.append(os.path.abspath('..'))
|
||||||
sys.path.append(os.path.abspath('../lib'))
|
sys.path.append(os.path.abspath('../lib'))
|
||||||
|
|
||||||
|
import sickbeard
|
||||||
from lib.feedparser import feedparser
|
from lib.feedparser import feedparser
|
||||||
|
|
||||||
class APICheck(unittest.TestCase):
|
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 = u'Watershed.-.Exploring.a.New.Water.Ethic.for.the.New.West.1080i.HDTV.DD2.0.H.264-TrollHD'
|
||||||
search_term = 'Gold Rush South America'
|
#search_term = re.escape(search_term)
|
||||||
|
|
||||||
results = {}
|
filters = [re.compile('(^|[\W_]|[\s_])%s($|[\W_]|[\s_])' % filter.strip(), re.I) for filter in resultFilters + sickbeard.IGNORE_WORDS.split(',')]
|
||||||
final_results = []
|
for regfilter in filters:
|
||||||
|
if regfilter.search(search_term):
|
||||||
|
print 'bad'
|
||||||
|
|
||||||
|
print 'good'
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user