diff --git a/resources/lib/common/kodi_ops.py b/resources/lib/common/kodi_ops.py index 1c0dfe0dc..7aefa9344 100644 --- a/resources/lib/common/kodi_ops.py +++ b/resources/lib/common/kodi_ops.py @@ -207,6 +207,16 @@ def get_kodi_ui_language(iso_format=xbmc.ISO_639_1): return convert_language_iso(setting.split('.')[-1][:2], iso_format) +def get_kodi_is_prefer_sub_impaired(): + """Return True if subtitles for impaired are enabled in Kodi settings""" + return json_rpc('Settings.GetSettingValue', {'setting': 'accessibility.subhearing'})['value'] + + +def get_kodi_is_prefer_audio_impaired(): + """Return True if audio for impaired is enabled in Kodi settings""" + return json_rpc('Settings.GetSettingValue', {'setting': 'accessibility.audiovisual'})['value'] + + def convert_language_iso(from_value, iso_format=xbmc.ISO_639_1): """ Convert given value (English name or two/three letter code) to the specified format diff --git a/resources/lib/services/nfsession/msl/converter.py b/resources/lib/services/nfsession/msl/converter.py index 623cedc05..720fba10b 100644 --- a/resources/lib/services/nfsession/msl/converter.py +++ b/resources/lib/services/nfsession/msl/converter.py @@ -44,7 +44,7 @@ def convert_to_dash(manifest): id_default_audio_tracks = _get_id_default_audio_tracks(manifest) for audio_track in manifest['audio_tracks']: - is_default = audio_track['id'] in id_default_audio_tracks + is_default = audio_track['id'] == id_default_audio_tracks _convert_audio_track(audio_track, period, init_length, is_default, has_audio_drm_streams, cdn_index) for text_track in manifest['timedtexttracks']: @@ -309,13 +309,14 @@ def _get_id_default_audio_tracks(manifest): audio_stream = _find_audio_stream(manifest, 'isNative', True, channels_multi) if not audio_stream: audio_stream = _find_audio_stream(manifest, 'isNative', True, channels_stereo) - # Try find the default track for impaired imp_audio_stream = {} - if not is_prefer_stereo: - imp_audio_stream = _find_audio_stream(manifest, 'language', audio_language, channels_multi, True) - if not imp_audio_stream: - imp_audio_stream = _find_audio_stream(manifest, 'language', audio_language, channels_stereo, True) - return audio_stream.get('id'), imp_audio_stream.get('id') + if common.get_kodi_is_prefer_audio_impaired(): + # Try to find the default track for impaired + if not is_prefer_stereo: + imp_audio_stream = _find_audio_stream(manifest, 'language', audio_language, channels_multi, True) + if not imp_audio_stream: + imp_audio_stream = _find_audio_stream(manifest, 'language', audio_language, channels_stereo, True) + return imp_audio_stream.get('id') or audio_stream.get('id') def _find_audio_stream(manifest, property_name, property_value, channels_list, is_impaired=False): diff --git a/resources/lib/services/playback/am_stream_continuity.py b/resources/lib/services/playback/am_stream_continuity.py index e7a7fd1c3..b5e2d3f34 100644 --- a/resources/lib/services/playback/am_stream_continuity.py +++ b/resources/lib/services/playback/am_stream_continuity.py @@ -59,8 +59,6 @@ def __init__(self): self.resume = {} self.is_kodi_forced_subtitles_only = None self.is_prefer_alternative_lang = None - self.is_prefer_sub_impaired = None - self.is_prefer_audio_impaired = None def __str__(self): return ('enabled={}, videoid_parent={}' @@ -69,10 +67,6 @@ def __str__(self): def initialize(self, data): self.is_kodi_forced_subtitles_only = common.get_kodi_subtitle_language() == 'forced_only' self.is_prefer_alternative_lang = G.ADDON.getSettingBool('prefer_alternative_lang') - self.is_prefer_sub_impaired = common.json_rpc('Settings.GetSettingValue', - {'setting': 'accessibility.subhearing'}).get('value') - self.is_prefer_audio_impaired = common.json_rpc('Settings.GetSettingValue', - {'setting': 'accessibility.audiovisual'}).get('value') def on_playback_started(self, player_state): is_enabled = G.ADDON.getSettingBool('StreamContinuityManager_enabled') @@ -248,7 +242,7 @@ def _select_lang_with_country_code(self): lang_code = _find_lang_with_country_code(audio_list, pref_audio_language) if lang_code and common.get_kodi_audio_language() not in ['mediadefault', 'original']: stream_audio = None - if self.is_prefer_audio_impaired: + if common.get_kodi_is_prefer_audio_impaired(): stream_audio = next((audio_track for audio_track in audio_list if audio_track['language'] == lang_code and audio_track['isimpaired'] @@ -350,7 +344,7 @@ def _ensure_subtitles_no_audio_available(self): def _find_subtitle_stream(self, language, is_forced=False): # Take in account if a user have enabled Kodi impaired subtitles preference # but only without forced setting (same Kodi player behaviour) - is_prefer_impaired = self.is_prefer_sub_impaired and not is_forced + is_prefer_impaired = common.get_kodi_is_prefer_sub_impaired() and not is_forced subtitles_list = self.player_state.get(STREAMS['subtitle']['list']) stream = None if is_prefer_impaired: