mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-22 06:13:19 -07:00
add chnaged api handling for SickGear. Fixes #1630
This commit is contained in:
parent
9a958afac8
commit
10d21bd801
1 changed files with 39 additions and 24 deletions
|
@ -13,6 +13,34 @@ from six import iteritems
|
||||||
import core
|
import core
|
||||||
from core import logger
|
from core import logger
|
||||||
|
|
||||||
|
def api_check(r, excess_parameters, rem_parameters):
|
||||||
|
try:
|
||||||
|
json_data = r.json()
|
||||||
|
except ValueError:
|
||||||
|
logger.error('Failed to get JSON data from response')
|
||||||
|
logger.debug('Response received')
|
||||||
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
json_data = json_data['data']
|
||||||
|
except KeyError:
|
||||||
|
logger.error('Failed to get data from JSON')
|
||||||
|
logger.debug('Response received: {}'.format(json_data))
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
json_data = json_data.get('data', json_data)
|
||||||
|
|
||||||
|
try:
|
||||||
|
optional_parameters = json_data['optionalParameters'].keys()
|
||||||
|
# Find excess parameters
|
||||||
|
excess_parameters = set(params).difference(optional_parameters)
|
||||||
|
logger.debug('Removing excess parameters: {}'.format(sorted(excess_parameters)))
|
||||||
|
rem_params.extend(excess_parameters)
|
||||||
|
return excess_parameters, rem_parameters, True
|
||||||
|
except:
|
||||||
|
logger.error('Failed to identify optionalParameters')
|
||||||
|
return excess_parameters, rem_parameters, False
|
||||||
|
|
||||||
|
|
||||||
def auto_fork(section, input_category):
|
def auto_fork(section, input_category):
|
||||||
# auto-detect correct section
|
# auto-detect correct section
|
||||||
|
@ -98,30 +126,17 @@ def auto_fork(section, input_category):
|
||||||
r = []
|
r = []
|
||||||
if r and r.ok:
|
if r and r.ok:
|
||||||
if apikey:
|
if apikey:
|
||||||
try:
|
excess_parameters, rem_parameters, found = api_check(r, excess_parameters, rem_parameters)
|
||||||
json_data = r.json()
|
if not found: # try different api set for SickGear.
|
||||||
except ValueError:
|
url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=postprocess&jsonp=foo&help=1'.format(
|
||||||
logger.error('Failed to get JSON data from response')
|
protocol=protocol, host=host, port=port, root=web_root, apikey=apikey,
|
||||||
logger.debug('Response received')
|
)
|
||||||
raise
|
try:
|
||||||
|
r = s.get(url, auth=(username, password), verify=False)
|
||||||
try:
|
except requests.ConnectionError:
|
||||||
json_data = json_data['data']
|
logger.info('Could not connect to {section}:{category} to perform auto-fork detection!'.format
|
||||||
except KeyError:
|
(section=section, category=input_category))
|
||||||
logger.error('Failed to get data from JSON')
|
excess_parameters, rem_parameters, found = api_check(r, excess_parameters, rem_parameters)
|
||||||
logger.debug('Response received: {}'.format(json_data))
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
json_data = json_data.get('data', json_data)
|
|
||||||
|
|
||||||
try:
|
|
||||||
optional_parameters = json_data['optionalParameters'].keys()
|
|
||||||
# Find excess parameters
|
|
||||||
excess_parameters = set(params).difference(optional_parameters)
|
|
||||||
logger.debug('Removing excess parameters: {}'.format(sorted(excess_parameters)))
|
|
||||||
rem_params.extend(excess_parameters)
|
|
||||||
except:
|
|
||||||
logger.error('Failed to identify optionalParameters')
|
|
||||||
else:
|
else:
|
||||||
# Find excess parameters
|
# Find excess parameters
|
||||||
rem_params.extend(
|
rem_params.extend(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue