2015-07-08 00:02:29 +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 traceback
|
|
|
|
|
|
|
|
from . import generic
|
2015-09-18 00:06:34 +00:00
|
|
|
from sickbeard import helpers, logger, tvcache
|
|
|
|
from sickbeard.helpers import tryInt
|
2015-07-08 00:02:29 +00:00
|
|
|
from lib.unidecode import unidecode
|
|
|
|
|
|
|
|
|
|
|
|
class TransmithenetProvider(generic.TorrentProvider):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
generic.TorrentProvider.__init__(self, 'Transmithe.net')
|
|
|
|
|
|
|
|
self.url_base = 'https://transmithe.net/'
|
|
|
|
self.urls = {'config_provider_home_uri': self.url_base,
|
2015-09-18 00:06:34 +00:00
|
|
|
'login_action': self.url_base + 'login.php',
|
|
|
|
'user': self.url_base + 'ajax.php?action=index',
|
|
|
|
'browse': self.url_base + 'ajax.php?action=browse&auth=%s&passkey=%s',
|
|
|
|
'search': '&searchstr=%s',
|
|
|
|
'get': self.url_base + 'torrents.php?action=download&authkey=%s&torrent_pass=%s&id=%s'}
|
2015-07-08 00:02:29 +00:00
|
|
|
|
|
|
|
self.url = self.urls['config_provider_home_uri']
|
2015-09-18 00:06:34 +00:00
|
|
|
self.user_authkey, self.user_passkey = 2 * [None]
|
2015-07-08 00:02:29 +00:00
|
|
|
|
|
|
|
self.username, self.password, self.minseed, self.minleech = 4 * [None]
|
2015-09-18 00:06:34 +00:00
|
|
|
self.freeleech = False
|
2015-07-08 00:02:29 +00:00
|
|
|
self.cache = TransmithenetCache(self)
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _authorised(self, **kwargs):
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
if not super(TransmithenetProvider, self)._authorised(
|
|
|
|
logged_in=(lambda x=None: self.has_all_cookies('session')),
|
|
|
|
post_params={'keeplogged': '1', 'login': 'Login'}):
|
|
|
|
return False
|
|
|
|
if not self.user_authkey:
|
|
|
|
response = helpers.getURL(self.urls['user'], session=self.session, json=True)
|
|
|
|
if 'response' in response:
|
|
|
|
self.user_authkey, self.user_passkey = [response['response'].get(v) for v in 'authkey', 'passkey']
|
|
|
|
return self.user_authkey
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _search_provider(self, search_params, **kwargs):
|
2015-07-08 00:02:29 +00:00
|
|
|
|
|
|
|
results = []
|
2015-09-18 00:06:34 +00:00
|
|
|
if not self._authorised():
|
2015-07-08 00:02:29 +00:00
|
|
|
return results
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []}
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
rc = dict((k, re.compile('(?i)' + v)) for (k, v) in {'nodots': '[\.\s]+'}.items())
|
2015-07-08 00:02:29 +00:00
|
|
|
for mode in search_params.keys():
|
|
|
|
for search_string in search_params[mode]:
|
2015-09-18 00:06:34 +00:00
|
|
|
search_string = isinstance(search_string, unicode) and unidecode(search_string) or search_string
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
search_url = self.urls['browse'] % (self.user_authkey, self.user_passkey)
|
2015-07-08 00:02:29 +00:00
|
|
|
if 'Cache' != mode:
|
2015-09-18 00:06:34 +00:00
|
|
|
search_url += self.urls['search'] % rc['nodots'].sub('+', search_string)
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
data_json = self.get_url(search_url, json=True)
|
2015-07-08 00:02:29 +00:00
|
|
|
|
|
|
|
cnt = len(items[mode])
|
|
|
|
try:
|
2016-01-09 15:20:18 +00:00
|
|
|
for item in data_json['response'].get('results', []):
|
2015-09-18 00:06:34 +00:00
|
|
|
if self.freeleech and not item.get('isFreeleech'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
seeders, leechers, group_name, torrent_id, size = [tryInt(n, n) for n in [item.get(x) for x in [
|
|
|
|
'seeders', 'leechers', 'groupName', 'torrentId', 'size']]]
|
|
|
|
if self._peers_fail(mode, seeders, leechers):
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
title_parts = group_name.split('[')
|
|
|
|
maybe_res = re.findall('((?:72|108)0\w)', title_parts[1])
|
|
|
|
detail = title_parts[1].split('/')
|
|
|
|
detail[1] = detail[1].strip().lower().replace('mkv', 'x264')
|
|
|
|
title = '%s.%s' % (title_parts[0].strip(), '.'.join(
|
|
|
|
(len(maybe_res) and [maybe_res[0]] or []) + [detail[0].strip(), detail[1]]))
|
|
|
|
except (IndexError, KeyError):
|
|
|
|
title = group_name
|
|
|
|
download_url = self.urls['get'] % (self.user_authkey, self.user_passkey, torrent_id)
|
|
|
|
|
|
|
|
if title and download_url:
|
|
|
|
items[mode].append((title, download_url, seeders, self._bytesizer(size)))
|
|
|
|
|
2015-07-08 00:02:29 +00:00
|
|
|
except Exception:
|
|
|
|
logger.log(u'Failed to parse. Traceback: %s' % traceback.format_exc(), logger.ERROR)
|
2015-09-18 00:06:34 +00:00
|
|
|
self._log_search(mode, len(items[mode]) - cnt, search_url)
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self._sort_seeders(mode, items)
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
results = list(set(results + items[mode]))
|
2015-07-08 00:02:29 +00:00
|
|
|
|
|
|
|
return results
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _season_strings(self, ep_obj, **kwargs):
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return generic.TorrentProvider._season_strings(self, ep_obj, scene=False)
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _episode_strings(self, ep_obj, **kwargs):
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return generic.TorrentProvider._episode_strings(self, ep_obj, scene=False, **kwargs)
|
2015-07-08 00:02:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TransmithenetCache(tvcache.TVCache):
|
|
|
|
|
|
|
|
def __init__(self, this_provider):
|
|
|
|
tvcache.TVCache.__init__(self, this_provider)
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self.update_freq = 17
|
|
|
|
|
|
|
|
def _cache_data(self):
|
2015-07-08 00:02:29 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return self.provider.cache_data()
|
2015-07-08 00:02:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
provider = TransmithenetProvider()
|