iterate response list looking for matching result dict.

pull/54/head
l3uddz 7 years ago
parent 1845ceaa10
commit 5449a550e3

@ -99,7 +99,7 @@ class Radarr:
response_json = None response_json = None
if 'json' in req.headers['Content-Type'].lower(): if 'json' in req.headers['Content-Type'].lower():
response_json = helpers.get_response_dict(req.json()) response_json = helpers.get_response_dict(req.json(), 'tmdbId', movie_tmdbid)
if (req.status_code == 201 or req.status_code == 200) and (response_json and 'tmdbId' in response_json) \ if (req.status_code == 201 or req.status_code == 200) and (response_json and 'tmdbId' in response_json) \
and response_json['tmdbId'] == movie_tmdbid: and response_json['tmdbId'] == movie_tmdbid:

@ -145,7 +145,7 @@ class Sonarr:
response_json = None response_json = None
if 'json' in req.headers['Content-Type'].lower(): if 'json' in req.headers['Content-Type'].lower():
response_json = helpers.get_response_dict(req.json()) response_json = helpers.get_response_dict(req.json(), 'tvdbId', series_tvdbid)
if (req.status_code == 201 or req.status_code == 200) and (response_json and 'tvdbId' in response_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: and response_json['tvdbId'] == series_tvdbid:

@ -387,11 +387,21 @@ def trakt_is_movie_blacklisted(movie, blacklist_settings):
############################################################ ############################################################
def get_response_dict(response): def get_response_dict(response, key_field=None, key_value=None):
found_response = None found_response = None
try: try:
if isinstance(response, list): if isinstance(response, list):
found_response = response[0] if not key_field or not key_value:
found_response = response[0]
else:
for result in response:
if isinstance(result, dict) and key_field in result and result[key_field] == key_value:
found_response = result
break
if not found_response:
log.error("Unable to find a result with key %s where the value is %s", key_field, key_value)
elif isinstance(response, dict): elif isinstance(response, dict):
found_response = response found_response = response
else: else:

Loading…
Cancel
Save