diff --git a/media/radarr.py b/media/radarr.py index 298b758..353b35e 100644 --- a/media/radarr.py +++ b/media/radarr.py @@ -99,7 +99,7 @@ class Radarr: response_json = None 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) \ and response_json['tmdbId'] == movie_tmdbid: diff --git a/media/sonarr.py b/media/sonarr.py index bd5ce7f..8447efb 100644 --- a/media/sonarr.py +++ b/media/sonarr.py @@ -145,7 +145,7 @@ class Sonarr: response_json = None 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) \ and response_json['tvdbId'] == series_tvdbid: diff --git a/misc/helpers.py b/misc/helpers.py index 20790d6..60ad23e 100644 --- a/misc/helpers.py +++ b/misc/helpers.py @@ -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 try: 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): found_response = response else: