2015-06-16 22:54:44 +00:00
|
|
|
# coding=utf-8
|
|
|
|
#
|
2015-06-06 15:08:59 +00:00
|
|
|
# Author: SickGear
|
|
|
|
#
|
|
|
|
# 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 datetime
|
|
|
|
import time
|
|
|
|
|
2015-06-16 22:54:44 +00:00
|
|
|
from . import generic
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
from sickbeard import helpers, logger
|
2015-06-06 15:08:59 +00:00
|
|
|
from sickbeard.indexers.indexer_config import INDEXER_TVDB
|
|
|
|
|
|
|
|
|
|
|
|
class RarbgProvider(generic.TorrentProvider):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
generic.TorrentProvider.__init__(self, 'Rarbg')
|
|
|
|
|
2016-12-19 23:02:29 +00:00
|
|
|
self.url_base = 'https://rarbgmirror.xyz/'
|
2015-06-06 15:08:59 +00:00
|
|
|
# api_spec: https://rarbg.com/pubapi/apidocs_v2.txt
|
2015-06-16 22:54:44 +00:00
|
|
|
self.url_api = 'https://torrentapi.org/pubapi_v2.php?app_id=SickGear&'
|
|
|
|
self.urls = {'config_provider_home_uri': self.url_base,
|
2015-06-06 15:08:59 +00:00
|
|
|
'api_token': self.url_api + 'get_token=get_token',
|
|
|
|
'api_list': self.url_api + 'mode=list',
|
|
|
|
'api_search': self.url_api + 'mode=search'}
|
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
self.params = {'defaults': '&format=json_extended&category=18;41&limit=100&sort=last&ranked=%(r)s&token=%(t)s',
|
2015-06-06 15:08:59 +00:00
|
|
|
'param_iid': '&search_imdb=%(sid)s',
|
|
|
|
'param_tid': '&search_tvdb=%(sid)s',
|
|
|
|
'param_str': '&search_string=%(str)s',
|
|
|
|
'param_seed': '&min_seeders=%(min_seeds)s',
|
|
|
|
'param_peer': '&min_leechers=%(min_peers)s'}
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self.proper_search_terms = '{{.proper.|.repack.}}'
|
2015-06-06 15:08:59 +00:00
|
|
|
self.url = self.urls['config_provider_home_uri']
|
2015-06-16 22:54:44 +00:00
|
|
|
|
|
|
|
self.minseed, self.minleech, self.token, self.token_expiry = 4 * [None]
|
|
|
|
self.confirmed = False
|
|
|
|
self.request_throttle = datetime.datetime.now()
|
2015-06-06 15:08:59 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _authorised(self, reset=False, **kwargs):
|
2015-06-06 15:08:59 +00:00
|
|
|
|
|
|
|
if not reset and self.token and self.token_expiry and datetime.datetime.now() < self.token_expiry:
|
|
|
|
return True
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
for r in range(0, 3):
|
2018-01-15 17:54:36 +00:00
|
|
|
response = self.get_url(self.urls['api_token'], json=True)
|
|
|
|
if not self.should_skip() and response and 'token' in response:
|
2015-09-18 00:06:34 +00:00
|
|
|
self.token = response['token']
|
|
|
|
self.token_expiry = datetime.datetime.now() + datetime.timedelta(minutes=14)
|
|
|
|
return True
|
|
|
|
time.sleep(1.1)
|
2015-06-06 15:08:59 +00:00
|
|
|
|
|
|
|
logger.log(u'No usable API token returned from: %s' % self.urls['api_token'], logger.ERROR)
|
|
|
|
return False
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _search_provider(self, search_params, **kwargs):
|
2015-06-06 15:08:59 +00:00
|
|
|
|
|
|
|
results = []
|
2015-09-18 00:06:34 +00:00
|
|
|
if not self._authorised(reset=True):
|
2015-06-06 15:08:59 +00:00
|
|
|
return results
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []}
|
2015-06-16 22:54:44 +00:00
|
|
|
|
2015-06-06 15:08:59 +00:00
|
|
|
id_search = None
|
|
|
|
if hasattr(self, 'show') and self.show and self.show.indexer and self.show.indexerid:
|
2015-09-18 00:06:34 +00:00
|
|
|
sid, search_with = 2 * [None]
|
2015-06-06 15:08:59 +00:00
|
|
|
if 0 < len(self.show.imdb_info):
|
|
|
|
sid = self.show.imdb_info['imdb_id']
|
|
|
|
search_with = 'param_iid'
|
2015-09-18 00:06:34 +00:00
|
|
|
elif INDEXER_TVDB == self.show.indexer:
|
2015-06-06 15:08:59 +00:00
|
|
|
sid = self.show.indexerid
|
2015-09-18 00:06:34 +00:00
|
|
|
search_with = 'param_tid'
|
|
|
|
|
|
|
|
if sid and search_with:
|
|
|
|
id_search = self.params[search_with] % {'sid': sid}
|
2015-06-06 15:08:59 +00:00
|
|
|
|
|
|
|
dedupe = []
|
2016-08-26 23:36:01 +00:00
|
|
|
# sort type "_only" as first to process
|
|
|
|
search_types = sorted([x for x in search_params.items()], key=lambda tup: tup[0], reverse=True)
|
2015-06-06 15:08:59 +00:00
|
|
|
for mode_params in search_types:
|
|
|
|
mode_search = mode_params[0]
|
2015-09-18 00:06:34 +00:00
|
|
|
mode = mode_search.replace('_only', '')
|
2015-06-06 15:08:59 +00:00
|
|
|
for search_string in mode_params[1]:
|
2015-09-18 00:06:34 +00:00
|
|
|
searched_url = search_url = ''
|
2015-06-16 22:54:44 +00:00
|
|
|
url = 'api_list'
|
|
|
|
if 'Cache' != mode_search:
|
2015-06-06 15:08:59 +00:00
|
|
|
url = 'api_search'
|
|
|
|
|
|
|
|
if '_only' in mode_search and id_search:
|
|
|
|
search_url = id_search
|
|
|
|
|
|
|
|
if None is not search_string:
|
|
|
|
search_url += self.params['param_str'] % {'str': search_string}
|
|
|
|
|
|
|
|
search_url = self.urls[url] + self.params['defaults'] + search_url
|
|
|
|
|
|
|
|
if self.minseed:
|
|
|
|
search_url += self.params['param_seed'] % {'min_seeds': self.minseed}
|
|
|
|
|
|
|
|
if self.minleech:
|
|
|
|
search_url += self.params['param_peer'] % {'min_peers': self.minleech}
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
cnt = len(items[mode])
|
2015-06-16 22:54:44 +00:00
|
|
|
for r in range(0, 3):
|
2015-06-06 15:08:59 +00:00
|
|
|
time_out = 0
|
2015-06-16 22:54:44 +00:00
|
|
|
while(self.request_throttle > datetime.datetime.now()) and 2 >= time_out:
|
2015-06-06 15:08:59 +00:00
|
|
|
time_out += 1
|
|
|
|
time.sleep(1)
|
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
searched_url = search_url % {'r': int(self.confirmed), 't': self.token}
|
2015-09-18 00:06:34 +00:00
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
data_json = self.get_url(searched_url, json=True)
|
2018-01-15 17:54:36 +00:00
|
|
|
if self.should_skip():
|
|
|
|
return results
|
2015-09-18 00:06:34 +00:00
|
|
|
|
2015-06-16 22:54:44 +00:00
|
|
|
self.token_expiry = datetime.datetime.now() + datetime.timedelta(minutes=14)
|
2015-06-06 15:08:59 +00:00
|
|
|
self.request_throttle = datetime.datetime.now() + datetime.timedelta(seconds=3)
|
2016-08-26 23:36:01 +00:00
|
|
|
if not data_json:
|
2015-09-18 00:06:34 +00:00
|
|
|
continue
|
2015-06-06 15:08:59 +00:00
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
if 'error' in data_json:
|
|
|
|
if 5 == data_json['error_code']: # Too many requests per second.
|
2015-06-06 15:08:59 +00:00
|
|
|
continue
|
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
elif 2 == data_json['error_code']: # Invalid token set
|
2015-09-18 00:06:34 +00:00
|
|
|
if self._authorised(reset=True):
|
2015-06-06 15:08:59 +00:00
|
|
|
continue
|
2015-09-18 00:06:34 +00:00
|
|
|
self.log_result(mode, len(items[mode]) - cnt, searched_url)
|
|
|
|
return items[mode]
|
2015-06-06 15:08:59 +00:00
|
|
|
break
|
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
if 'error' not in data_json:
|
|
|
|
for item in data_json['torrent_results']:
|
2015-09-18 00:06:34 +00:00
|
|
|
title, download_magnet, seeders, size = [
|
|
|
|
item.get(x) for x in 'title', 'download', 'seeders', 'size']
|
|
|
|
title = None is title and item.get('filename') or title
|
|
|
|
if not (title and download_magnet) or download_magnet in dedupe:
|
|
|
|
continue
|
|
|
|
dedupe += [download_magnet]
|
2016-08-26 23:36:01 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
items[mode].append((title, download_magnet, seeders, self._bytesizer(size)))
|
|
|
|
|
|
|
|
self._log_search(mode, len(items[mode]) - cnt, searched_url)
|
2015-06-06 15:08:59 +00:00
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
results = self._sort_seeding(mode, results + items[mode])
|
2015-06-06 15:08:59 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
if '_only' in mode_search and len(results):
|
2015-06-06 15:08:59 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _season_strings(self, ep_obj, **kwargs):
|
2015-06-16 22:54:44 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return generic.TorrentProvider._season_strings(self, ep_obj, detail_only=True)
|
2015-06-16 22:54:44 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _episode_strings(self, ep_obj, **kwargs):
|
2015-06-16 22:54:44 +00:00
|
|
|
|
2017-12-04 15:11:18 +00:00
|
|
|
search_params = super(RarbgProvider, self)._episode_strings(ep_obj, detail_only=True, date_or=True, **kwargs)
|
2015-08-14 23:02:05 +00:00
|
|
|
if self.show.air_by_date and self.show.is_sports:
|
2015-06-16 22:54:44 +00:00
|
|
|
for x, types in enumerate(search_params):
|
|
|
|
for y, ep_type in enumerate(types):
|
|
|
|
search_params[x][ep_type][y] = '{{%s}}' % search_params[x][ep_type][y]
|
|
|
|
|
|
|
|
return search_params
|
|
|
|
|
2015-06-06 15:08:59 +00:00
|
|
|
|
|
|
|
provider = RarbgProvider()
|