Skip to content

Commit

Permalink
Merge pull request #1136 from CastagnaIT/audio_desc_fix
Browse files Browse the repository at this point in the history
Fixed wrong selection of impaired audio track
  • Loading branch information
CastagnaIT authored Apr 16, 2021
2 parents 2d8d23d + 2a50371 commit 562a46b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
10 changes: 10 additions & 0 deletions resources/lib/common/kodi_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions resources/lib/services/nfsession/msl/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 2 additions & 8 deletions resources/lib/services/playback/am_stream_continuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={}'
Expand All @@ -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')
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 562a46b

Please sign in to comment.