2015-06-28 16:27:14 +00:00
|
|
|
# coding=utf-8
|
|
|
|
#
|
|
|
|
# This file is part of SickGear.
|
|
|
|
#
|
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
|
|
|
|
from . import generic
|
2015-09-18 00:06:34 +00:00
|
|
|
from sickbeard import tvcache
|
|
|
|
from sickbeard.helpers import tryInt
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SpeedCDProvider(generic.TorrentProvider):
|
|
|
|
|
|
|
|
def __init__(self):
|
2015-09-18 00:06:34 +00:00
|
|
|
generic.TorrentProvider.__init__(self, 'SpeedCD')
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
self.url_base = 'http://speed.cd/'
|
|
|
|
self.urls = {'config_provider_home_uri': self.url_base,
|
2015-09-18 00:06:34 +00:00
|
|
|
'login_action': self.url_base + 'login.php',
|
2015-06-28 16:27:14 +00:00
|
|
|
'search': self.url_base + 'V3/API/API.php',
|
|
|
|
'get': self.url_base + 'download.php?torrent=%s'}
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self.categories = {'Season': {'c41': 1, 'c53': 1},
|
|
|
|
'Episode': {'c2': 1, 'c49': 1, 'c50': 1, 'c55': 1},
|
|
|
|
'Cache': {'c41': 1, 'c2': 1, 'c49': 1, 'c50': 1, 'c53': 1, 'c55': 1}}
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
self.url = self.urls['config_provider_home_uri']
|
|
|
|
|
|
|
|
self.username, self.password, self.minseed, self.minleech = 4 * [None]
|
|
|
|
self.freeleech = False
|
|
|
|
self.cache = SpeedCDCache(self)
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _authorised(self, **kwargs):
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return super(SpeedCDProvider, self)._authorised(logged_in=(lambda x=None: self.has_all_cookies('inSpeed_speedian')))
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _search_provider(self, search_params, **kwargs):
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
results = []
|
2015-09-18 00:06:34 +00:00
|
|
|
if not self._authorised():
|
2015-06-28 16:27:14 +00:00
|
|
|
return results
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []}
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
remove_tag = re.compile(r'<[^>]*>')
|
|
|
|
for mode in search_params.keys():
|
2015-09-18 00:06:34 +00:00
|
|
|
search_mode = (mode, 'Episode')['Propers' == mode]
|
2015-06-28 16:27:14 +00:00
|
|
|
for search_string in search_params[mode]:
|
|
|
|
search_string = '+'.join(search_string.split())
|
|
|
|
post_data = dict({'/browse.php?': None, 'cata': 'yes', 'jxt': 4, 'jxw': 'b', 'search': search_string},
|
2015-09-18 00:06:34 +00:00
|
|
|
**self.categories[search_mode])
|
|
|
|
if self.freeleech:
|
|
|
|
post_data['freeleech'] = 'on'
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
data_json = self.get_url(self.urls['search'], post_data=post_data, json=True)
|
2015-09-18 00:06:34 +00:00
|
|
|
|
2015-06-28 16:27:14 +00:00
|
|
|
cnt = len(items[mode])
|
|
|
|
try:
|
|
|
|
if not data_json:
|
|
|
|
raise generic.HaltParseException
|
|
|
|
torrents = data_json.get('Fs', [])[0].get('Cn', {}).get('torrents', [])
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
for item in torrents:
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
if self.freeleech and not item.get('free'):
|
2015-06-28 16:27:14 +00:00
|
|
|
continue
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
seeders, leechers, size = [tryInt(n, n) for n in [item.get(x) for x in 'seed', 'leech', 'size']]
|
|
|
|
if self._peers_fail(mode, seeders, leechers):
|
2015-06-28 16:27:14 +00:00
|
|
|
continue
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
title = remove_tag.sub('', item.get('name'))
|
|
|
|
download_url = self.urls['get'] % item.get('id')
|
|
|
|
if title and download_url:
|
|
|
|
items[mode].append((title, download_url, seeders, self._bytesizer(size)))
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
except Exception:
|
|
|
|
time.sleep(1.1)
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self._log_search(mode, len(items[mode]) - cnt,
|
2015-06-28 16:27:14 +00:00
|
|
|
('search string: ' + search_string, self.name)['Cache' == mode])
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self._sort_seeders(mode, items)
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
results = list(set(results + items[mode]))
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
return results
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _episode_strings(self, ep_obj, **kwargs):
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return generic.TorrentProvider._episode_strings(self, ep_obj, sep_date='.', **kwargs)
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SpeedCDCache(tvcache.TVCache):
|
|
|
|
|
|
|
|
def __init__(self, this_provider):
|
|
|
|
tvcache.TVCache.__init__(self, this_provider)
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self.update_freq = 20 # cache update frequency
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _cache_data(self):
|
2015-06-28 16:27:14 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return self.provider.cache_data()
|
2015-06-28 16:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
provider = SpeedCDProvider()
|