diff --git a/resources/lib/player.py b/resources/lib/player.py index 6a8f94bb..aaf8c14d 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -160,23 +160,28 @@ class Player(xbmc.Player): } } result = xbmc.executeJSONRPC(json.dumps(tracks_query)) - result = json.loads(result) - result = result.get('result') + tracks_data = None + try: + tracks_data = json.loads(result) + tracks_data = tracks_data.get('result') + except: + tracks_data = None - try: # Audio tracks - indexAudio = result['currentaudiostream']['index'] - except (KeyError, TypeError): - indexAudio = 0 + if tracks_data is not None: + try: # Audio tracks + indexAudio = tracks_data['currentaudiostream']['index'] + except (KeyError, TypeError): + indexAudio = 0 - try: # Subtitles tracks - indexSubs = result['currentsubtitle']['index'] - except (KeyError, TypeError): - indexSubs = 0 + try: # Subtitles tracks + indexSubs = tracks_data['currentsubtitle']['index'] + except (KeyError, TypeError): + indexSubs = 0 - try: # If subtitles are enabled - subsEnabled = result['subtitleenabled'] - except (KeyError, TypeError): - subsEnabled = "" + try: # If subtitles are enabled + subsEnabled = tracks_data['subtitleenabled'] + except (KeyError, TypeError): + subsEnabled = "" # Postdata for the audio postdata['AudioStreamIndex'] = indexAudio + 1