2015-06-12 10:18:04 +00:00
|
|
|
# coding=utf-8
|
|
|
|
#
|
|
|
|
# This file is part of SickGear.
|
2015-04-15 06:16:27 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2015-04-15 06:16:27 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2015-04-15 06:16:27 +00:00
|
|
|
# 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
|
2014-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-05-07 07:50:49 +00:00
|
|
|
|
2015-06-12 10:18:04 +00:00
|
|
|
import re
|
2014-05-17 13:55:58 +00:00
|
|
|
import urllib
|
2015-04-18 04:55:04 +00:00
|
|
|
|
2015-06-12 10:18:04 +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 logger
|
2015-04-18 04:55:04 +00:00
|
|
|
from sickbeard.exceptions import AuthException
|
2015-09-18 00:06:34 +00:00
|
|
|
from sickbeard.helpers import tryInt
|
|
|
|
from sickbeard.indexers import indexer_config
|
2015-04-18 04:55:04 +00:00
|
|
|
|
2014-05-17 13:55:58 +00:00
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
|
|
|
from lib import simplejson as json
|
|
|
|
|
|
|
|
|
|
|
|
class HDBitsProvider(generic.TorrentProvider):
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2014-05-17 13:55:58 +00:00
|
|
|
def __init__(self):
|
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
|
|
|
generic.TorrentProvider.__init__(self, 'HDBits', cache_update_freq=15)
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-06-12 10:18:04 +00:00
|
|
|
# api_spec: https://hdbits.org/wiki/API
|
|
|
|
self.url_base = 'https://hdbits.org/'
|
|
|
|
self.urls = {'config_provider_home_uri': self.url_base,
|
|
|
|
'search': self.url_base + 'api/torrents',
|
|
|
|
'get': self.url_base + 'download.php?%s'}
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self.categories = [3, 5, 2]
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self.proper_search_terms = [' proper ', ' repack ']
|
2015-06-12 10:18:04 +00:00
|
|
|
self.url = self.urls['config_provider_home_uri']
|
|
|
|
|
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
|
|
|
self.username, self.passkey, self.freeleech, self.minseed, self.minleech = 5 * [None]
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-06-12 10:18:04 +00:00
|
|
|
def check_auth_from_data(self, parsed_json):
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-06-12 10:18:04 +00:00
|
|
|
if 'status' in parsed_json and 5 == parsed_json.get('status') and 'message' in parsed_json:
|
2016-08-26 23:36:01 +00:00
|
|
|
logger.log(u'Incorrect username or password for %s: %s' % (self.name, parsed_json['message']), logger.DEBUG)
|
2015-06-12 10:18:04 +00:00
|
|
|
raise AuthException('Your username or password for %s is incorrect, check your config.' % self.name)
|
2014-05-17 13:55:58 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _season_strings(self, ep_obj, **kwargs):
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-12-02 15:19:28 +00:00
|
|
|
params = super(HDBitsProvider, self)._season_strings(ep_obj, scene=False)
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
show = ep_obj.show
|
|
|
|
if indexer_config.INDEXER_TVDB == show.indexer and show.indexerid:
|
|
|
|
params[0]['Season'].insert(0, dict(tvdb=dict(
|
|
|
|
id=show.indexerid,
|
|
|
|
season=(show.air_by_date or show.is_sports) and str(ep_obj.airdate)[:7] or
|
|
|
|
(show.is_anime and ('%d' % ep_obj.scene_absolute_number) or
|
|
|
|
(ep_obj.season, ep_obj.scene_season)[bool(show.is_scene)]))))
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return params
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _episode_strings(self, ep_obj, **kwargs):
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-12-02 15:19:28 +00:00
|
|
|
params = super(HDBitsProvider, self)._episode_strings(ep_obj, scene=False, sep_date='|')
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
show = ep_obj.show
|
|
|
|
if indexer_config.INDEXER_TVDB == show.indexer and show.indexerid:
|
|
|
|
id_param = dict(
|
|
|
|
id=show.indexerid,
|
|
|
|
episode=show.air_by_date and str(ep_obj.airdate).replace('-', ' ') or
|
|
|
|
(show.is_sports and ep_obj.airdate.strftime('%b') or
|
|
|
|
(show.is_anime and ('%i' % int(ep_obj.scene_absolute_number)) or
|
|
|
|
(ep_obj.episode, ep_obj.scene_episode)[bool(show.is_scene)])))
|
|
|
|
if not(show.air_by_date and show.is_sports and show.is_anime):
|
|
|
|
id_param['season'] = (ep_obj.season, ep_obj.scene_season)[bool(show.is_scene)]
|
|
|
|
params[0]['Episode'].insert(0, dict(tvdb=id_param))
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return params
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _search_provider(self, search_params, **kwargs):
|
2014-05-05 07:39:20 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
self._check_auth()
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
results = []
|
|
|
|
api_data = {'username': self.username, 'passkey': self.passkey, 'category': self.categories}
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []}
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
for mode in search_params.keys():
|
2015-12-02 15:19:28 +00:00
|
|
|
for search_param in search_params[mode]:
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
post_data = api_data.copy()
|
2015-12-02 15:19:28 +00:00
|
|
|
if isinstance(search_param, dict):
|
|
|
|
post_data.update(search_param)
|
2015-09-18 00:06:34 +00:00
|
|
|
id_search = True
|
|
|
|
else:
|
2015-12-02 15:19:28 +00:00
|
|
|
post_data['search'] = search_param
|
2015-09-18 00:06:34 +00:00
|
|
|
id_search = False
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
post_data = json.dumps(post_data)
|
|
|
|
search_url = self.urls['search']
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
json_resp = self.get_url(search_url, post_data=post_data, json=True)
|
2015-12-02 15:19:28 +00:00
|
|
|
|
2016-11-01 18:13:51 +00:00
|
|
|
if not (json_resp and self.check_auth_from_data(json_resp) and 'data' in json_resp):
|
2015-09-18 00:06:34 +00:00
|
|
|
logger.log(u'Response from %s does not contain any json data, abort' % self.name, logger.ERROR)
|
|
|
|
return results
|
2014-05-17 13:55:58 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
cnt = len(items[mode])
|
|
|
|
for item in json_resp['data']:
|
2014-05-17 13:55:58 +00:00
|
|
|
try:
|
2016-08-26 23:36:01 +00:00
|
|
|
seeders, leechers, size = [tryInt(n, n) for n in [item.get(x) for x in
|
|
|
|
'seeders', 'leechers', 'size']]
|
2015-09-18 00:06:34 +00:00
|
|
|
if self._peers_fail(mode, seeders, leechers)\
|
|
|
|
or self.freeleech and re.search('(?i)no', item.get('freeleech', 'no')):
|
2015-06-12 10:18:04 +00:00
|
|
|
continue
|
2016-08-26 23:36:01 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
title = item['name']
|
|
|
|
download_url = self.urls['get'] % urllib.urlencode({'id': item['id'], 'passkey': self.passkey})
|
|
|
|
except (AttributeError, TypeError, ValueError):
|
|
|
|
continue
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
if title and download_url:
|
|
|
|
items[mode].append((title, download_url, item.get('seeders', 0), self._bytesizer(size)))
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
self._log_search(mode, len(items[mode]) - cnt,
|
2015-12-02 15:19:28 +00:00
|
|
|
('search_param: ' + str(search_param), self.name)['Cache' == mode])
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
results = self._sort_seeding(mode, results + items[mode])
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2016-08-26 23:36:01 +00:00
|
|
|
if id_search and len(results):
|
|
|
|
return results
|
2015-06-12 10:18:04 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
return results
|
2014-05-17 13:55:58 +00:00
|
|
|
|
|
|
|
|
2015-04-15 06:16:27 +00:00
|
|
|
provider = HDBitsProvider()
|