From aa22e9cea0d155d7f47a4da86e923f1ca51f5cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Chv=C3=ADla?= Date: Sun, 4 May 2025 18:27:07 +0200 Subject: [PATCH] playutils: Fix streams indexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Chvíla --- jellyfin_kodi/helper/playutils.py | 70 ++++++++++++++++--------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/jellyfin_kodi/helper/playutils.py b/jellyfin_kodi/helper/playutils.py index 80a67344..519134a9 100644 --- a/jellyfin_kodi/helper/playutils.py +++ b/jellyfin_kodi/helper/playutils.py @@ -605,21 +605,21 @@ class PlayUtils(object): IsTextSubtitleStream if true, is available to download from server. """ prefs = "" - audio_streams = list() - subs_streams = list() - streams = source["MediaStreams"] + audio_stream_indexes = list() + subs_stream_indexes = list() + streams = dict() server_settings = self.api_client.get_transcode_settings() allow_burned_subs = settings("allowBurnedSubs.bool") - for stream in streams: - + for stream in source["MediaStreams"]: index = stream["Index"] stream_type = stream["Type"] - if stream_type == "Audio": + streams[index] = stream - audio_streams.append(index) + if stream_type == "Audio": + audio_stream_indexes.append(index) elif stream_type == "Subtitle": if stream["IsExternal"]: @@ -633,7 +633,7 @@ class PlayUtils(object): if not avail_for_extraction and not allow_burned_subs: continue - subs_streams.append(index) + subs_stream_indexes.append(index) skip_dialog = int(settings("skipDialogTranscode") or 0) @@ -641,54 +641,54 @@ class PlayUtils(object): return streams[track_index]["DisplayTitle"] or ("Track %s" % track_index) # Select audio stream - audio_selected = None + audio_selected_index = None if skip_dialog == Transcode.MediaDefault: # NOTE: "DefaultAudioStreamIndex" is the default according to Jellyfin. # The media's default is marked by the "IsDefault" value. - for track_index in audio_streams: + for track_index in audio_stream_indexes: if streams[track_index]["IsDefault"]: audio = track_index break # Compare to None in the off-chance the track index is 0. if audio is not None: - audio_selected = audio + audio_selected_index = audio elif skip_dialog in (Transcode.Enabled, Transcode.Audio): - if len(audio_streams) > 1: - selection = list(map(get_track_title, audio_streams)) + if len(audio_stream_indexes) > 1: + selection = list(map(get_track_title, audio_stream_indexes)) resp = dialog("select", translate(33013), selection) if resp > -1: - audio_selected = audio_streams[resp] + audio_selected_index = audio_stream_indexes[resp] else: - audio_selected = source["DefaultAudioStreamIndex"] - elif audio_streams: + audio_selected_index = source["DefaultAudioStreamIndex"] + elif audio_stream_indexes: # Only one choice - audio_selected = audio_streams[0] + audio_selected_index = audio_stream_indexes[0] else: - audio_selected = source["DefaultAudioStreamIndex"] + audio_selected_index = source["DefaultAudioStreamIndex"] - if audio_selected is not None: - self.info["AudioStreamIndex"] = audio_selected - prefs += "&AudioStreamIndex=%s" % audio_selected + if audio_selected_index is not None: + self.info["AudioStreamIndex"] = audio_selected_index + prefs += "&AudioStreamIndex=%s" % audio_selected_index # Select audio stream - subtitle_selected = None + subtitle_selected_index = None if skip_dialog == Transcode.MediaDefault: - for track_index in subs_streams: + for track_index in subs_stream_indexes: if streams[track_index]["IsDefault"]: subtitle = track_index break if subtitle is not None: - subtitle_selected = subtitle + subtitle_selected_index = subtitle - elif skip_dialog in (Transcode.Enabled, Transcode.Subtitle) and subs_streams: + elif skip_dialog in (Transcode.Enabled, Transcode.Subtitle) and subs_stream_indexes: selection = list(["No subtitles"]) + list( - map(get_track_title, subs_streams) + map(get_track_title, subs_stream_indexes) ) resp = dialog("select", translate(33014), selection) - 1 # Possible responses: @@ -696,23 +696,25 @@ class PlayUtils(object): # -1 No subtitles (Default) # -2 Dialog was cancelled if resp > -1: - track_index = subs_streams[resp] - subtitle_selected = track_index + subtitle_selected_index = subs_stream_indexes[resp] - if subtitle_selected is not None: + if subtitle_selected_index is not None: server_settings = self.api_client.get_transcode_settings() - stream = streams[track_index] + stream = streams[subtitle_selected_index] if ( server_settings["EnableSubtitleExtraction"] and stream["SupportsExternalStream"] ): self.info["SubtitleUrl"] = self.get_subtitles( - source, stream, subtitle_selected + source, stream, subtitle_selected_index ) - self.info["SubtitleStreamIndex"] = subtitle_selected + self.info["SubtitleStreamIndex"] = subtitle_selected_index elif allow_burned_subs: - prefs += "&SubtitleStreamIndex=%s" % subtitle_selected - self.info["SubtitleStreamIndex"] = subtitle_selected + prefs += "&SubtitleStreamIndex=%s" % subtitle_selected_index + self.info["SubtitleStreamIndex"] = subtitle_selected_index + + prefs += "&SubtitleMethod=Encode" + self.info["SubtitleMethod"] = "Encode" return prefs