mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Change accept lists in JSON responses.
Change do not log error for empty BTN un/pw in most cases. Change BTN to only try API once when doing alternative name searches. Change when API fails, warn users as a tip that they can configure un/pw.
This commit is contained in:
parent
bd86a20adf
commit
cf5f6e3891
4 changed files with 25 additions and 7 deletions
10
CHANGES.md
10
CHANGES.md
|
@ -1,4 +1,12 @@
|
|||
### 0.12.6 (2017-02-17 03:48:00 UTC)
|
||||
### 0.12.7 (2017-02-17 15:00:00 UTC)
|
||||
|
||||
* Change accept lists in JSON responses
|
||||
* Change do not log error for empty BTN un/pw in most cases
|
||||
* Change BTN to only try API once when doing alternative name searches
|
||||
* Change when API fails, warn users as a tip that they can configure un/pw
|
||||
|
||||
|
||||
### 0.12.6 (2017-02-17 03:48:00 UTC)
|
||||
|
||||
* Change skip episodes that have no wanted qualities
|
||||
* Change download picked .nzb file on demand and not before
|
||||
|
|
|
@ -1220,7 +1220,7 @@ def getURL(url, post_data=None, params=None, headers=None, timeout=30, session=N
|
|||
if json:
|
||||
try:
|
||||
data_json = resp.json()
|
||||
return ({}, data_json)[isinstance(data_json, dict)]
|
||||
return ({}, data_json)[isinstance(data_json, (dict, list))]
|
||||
except (TypeError, Exception) as e:
|
||||
logger.log(u'JSON data issue from URL %s\r\nDetail... %s' % (url, e.message), logger.WARNING)
|
||||
return None
|
||||
|
|
|
@ -22,6 +22,7 @@ import time
|
|||
from . import generic
|
||||
from sickbeard import helpers, logger, scene_exceptions, tvcache
|
||||
from sickbeard.bs4_parser import BS4Parser
|
||||
from sickbeard.exceptions import AuthException
|
||||
from sickbeard.helpers import tryInt
|
||||
from lib.unidecode import unidecode
|
||||
|
||||
|
@ -57,8 +58,12 @@ class BTNProvider(generic.TorrentProvider):
|
|||
|
||||
def _authorised(self, **kwargs):
|
||||
|
||||
return self._check_auth()
|
||||
|
||||
def _check_auth(self, **kwargs):
|
||||
|
||||
if not self.api_key and not (self.username and self.password):
|
||||
raise AuthException('Must set ApiKey or Username/Password for %s in config provider options' % self.name)
|
||||
raise AuthException('Must set Api key or Username/Password for %s in config provider options' % self.name)
|
||||
return True
|
||||
|
||||
def _search_provider(self, search_params, age=0, **kwargs):
|
||||
|
@ -67,6 +72,7 @@ class BTNProvider(generic.TorrentProvider):
|
|||
self.auth_html = None
|
||||
|
||||
results = []
|
||||
api_up = True
|
||||
|
||||
for mode in search_params.keys():
|
||||
for search_param in search_params[mode]:
|
||||
|
@ -87,11 +93,12 @@ class BTNProvider(generic.TorrentProvider):
|
|||
|
||||
try:
|
||||
response = None
|
||||
if self.api_key:
|
||||
if api_up and self.api_key:
|
||||
self.session.headers['Content-Type'] = 'application/json-rpc'
|
||||
response = helpers.getURL(
|
||||
self.url_api, post_data=json_rpc(params), session=self.session, json=True)
|
||||
if not response:
|
||||
api_up = False
|
||||
results = self.html(mode, search_string, results)
|
||||
error_text = response['error']['message']
|
||||
logger.log(
|
||||
|
@ -100,9 +107,12 @@ class BTNProvider(generic.TorrentProvider):
|
|||
or u'Action prematurely ended. %(prov)s server error response = %(desc)s') %
|
||||
{'prov': self.name, 'desc': error_text}, logger.WARNING)
|
||||
return results
|
||||
except AuthException:
|
||||
logger.log('API looks to be down, add un/pw config detail to be used as a fallback', logger.WARNING)
|
||||
except (KeyError, Exception):
|
||||
data_json = response and 'result' in response and response['result'] or {}
|
||||
pass
|
||||
|
||||
data_json = response and 'result' in response and response['result'] or {}
|
||||
if data_json:
|
||||
|
||||
found_torrents = 'torrents' in data_json and data_json['torrents'] or {}
|
||||
|
|
|
@ -1098,7 +1098,7 @@ class TorrentProvider(object, GenericProvider):
|
|||
elif hasattr(self, 'username') and hasattr(self, 'api_key'):
|
||||
if self.username and self.api_key:
|
||||
return True
|
||||
setting = 'Apikey or Username'
|
||||
setting = 'Api key or Username'
|
||||
elif hasattr(self, 'username') and hasattr(self, 'passkey'):
|
||||
if self.username and self.passkey:
|
||||
return True
|
||||
|
@ -1110,7 +1110,7 @@ class TorrentProvider(object, GenericProvider):
|
|||
elif hasattr(self, 'api_key'):
|
||||
if self.api_key:
|
||||
return True
|
||||
setting = 'Apikey'
|
||||
setting = 'Api key'
|
||||
elif hasattr(self, 'passkey'):
|
||||
if self.passkey:
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue