|
|
@ -3,6 +3,7 @@ from urllib.parse import urljoin
|
|
|
|
import backoff
|
|
|
|
import backoff
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from misc import helpers
|
|
|
|
from misc.log import logger
|
|
|
|
from misc.log import logger
|
|
|
|
|
|
|
|
|
|
|
|
log = logger.get_logger(__name__)
|
|
|
|
log = logger.get_logger(__name__)
|
|
|
@ -142,13 +143,17 @@ class Sonarr:
|
|
|
|
log.debug("Request Response Code: %d", req.status_code)
|
|
|
|
log.debug("Request Response Code: %d", req.status_code)
|
|
|
|
log.debug("Request Response Text:\n%s", req.text)
|
|
|
|
log.debug("Request Response Text:\n%s", req.text)
|
|
|
|
|
|
|
|
|
|
|
|
if (req.status_code == 201 or req.status_code == 200) and 'json' in req.headers['Content-Type'].lower() \
|
|
|
|
response_json = None
|
|
|
|
and req.json()['tvdbId'] == series_tvdbid:
|
|
|
|
if 'json' in req.headers['Content-Type'].lower():
|
|
|
|
|
|
|
|
response_json = helpers.get_response_dict(req.json())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.status_code == 201 or req.status_code == 200) and (response_json and 'tvdbId' in response_json) \
|
|
|
|
|
|
|
|
and response_json['tvdbId'] == series_tvdbid:
|
|
|
|
log.debug("Successfully added %s (%d)", series_title, series_tvdbid)
|
|
|
|
log.debug("Successfully added %s (%d)", series_title, series_tvdbid)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
elif 'json' in req.headers['Content-Type'].lower() and 'errorMessage' in req.text:
|
|
|
|
elif response_json and 'errorMessage' in response_json:
|
|
|
|
log.error("Failed to add %s (%d) - status_code: %d, reason: %s", series_title, series_tvdbid,
|
|
|
|
log.error("Failed to add %s (%d) - status_code: %d, reason: %s", series_title, series_tvdbid,
|
|
|
|
req.status_code, req.json()['errorMessage'])
|
|
|
|
req.status_code, response_json['errorMessage'])
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
log.error("Failed to add %s (%d), unexpected response:\n%s", series_title, series_tvdbid, req.text)
|
|
|
|
log.error("Failed to add %s (%d), unexpected response:\n%s", series_title, series_tvdbid, req.text)
|
|
|
|