SickGear/sickbeard/providers/beyondhd.py
JackDandy 0ead7771de Change improve the manage searches error stats UI and backend functions.
Add the improved error handling to torrent providers.
Change cache_db to always include db upgrade statements when running SG for the first time.
Change split newznab limit logic into a reusable function, hit_limit_update() and use in BTN prov.
Change tweak CSS to make things a little neater with button spacings.
Add the actual time when current limit will expire to the UI.
Change instead of terminology "errors", use "failures".
Change improve BTN error handling.
Change ensure provider name is output to log at times where it wasn't.
Change ensure failed request URLs and POST params are output to log.
Add time of last failure + type to should_skip log message.
Change code DRY and simplification for improved readability.
Change occurrences of "error" to "fail" for consistency.
Add tmr limit handling to omg and change log_failure_url level to warning.
Change log the failed URL when an API hit limit is reached.
Change "hit" to the more universally generic "tmr" - Too Many Requests.
Change Db columns containing "hit_" are renamed "tmr_"
2018-01-26 01:35:02 +00:00

98 lines
3.9 KiB
Python

# 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
from sickbeard import logger
from sickbeard.exceptions import AuthException
from lib.unidecode import unidecode
class BeyondHDProvider(generic.TorrentProvider):
def __init__(self):
generic.TorrentProvider.__init__(self, 'BeyondHD')
self.url_base = 'https://beyond-hd.me/'
self.urls = {'config_provider_home_uri': self.url_base,
'browse': self.url_base + 'api_tv.php?passkey=%s&cats=%s',
'search': '&search=%s'}
self.categories = {'Season': '89', 'Episode': '40,44,48,46,45'}
self.categories['Cache'] = '%s,%s' % (self.categories['Episode'], self.categories['Season'])
self.url = self.urls['config_provider_home_uri']
self.passkey, self.scene, self.minseed, self.minleech = 4 * [None]
def _check_auth_from_data(self, data_json):
if 'error' not in data_json:
return True
logger.log(u'Incorrect authentication credentials for %s : %s' % (self.name, data_json['error']), logger.DEBUG)
raise AuthException('Authentication credentials for %s are incorrect, check your config' % self.name)
def _search_provider(self, search_params, **kwargs):
results = []
if not self._check_auth():
return results
items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []}
for mode in search_params.keys():
if mode in ['Season', 'Episode']:
show_type = self.show.air_by_date and 'Air By Date' \
or self.show.is_sports and 'Sports' or self.show.is_anime and 'Anime' or None
if show_type:
logger.log(u'Provider does not carry shows of type: [%s], skipping' % show_type, logger.DEBUG)
return results
mode_cats = (mode, 'Cache')['Propers' == mode]
for search_string in search_params[mode]:
search_string = isinstance(search_string, unicode) and unidecode(search_string) or search_string
search_url = self.urls['browse'] % (self.passkey, self.categories[mode_cats])
if 'Cache' != mode:
search_url += self.urls['search'] % re.sub('[.\s]+', ' ', search_string)
data_json = self.get_url(search_url, json=True)
if self.should_skip():
return results
cnt = len(items[mode])
if data_json and 'results' in data_json and self._check_auth_from_data(data_json):
for item in data_json['results']:
seeders, leechers = item.get('seeders', 0), item.get('leechers', 0)
if self._peers_fail(mode, seeders, leechers):
continue
title, download_url = item.get('file'), self._link(item.get('get'))
if title and download_url:
items[mode].append((title, download_url, seeders, self._bytesizer(item.get('size'))))
time.sleep(1.1)
self._log_search(mode, len(items[mode]) - cnt, search_url)
results = self._sort_seeding(mode, results + items[mode])
return results
provider = BeyondHDProvider()