From cb2897a3f13e4058c50a54c67e4282948308bf53 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 7 Dec 2024 17:11:37 +1100 Subject: [PATCH] Use MediaStream type for subtitle stream processing --- src/helpers.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index e11b4ab7..8e714d92 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -415,8 +415,7 @@ export function createStreamInfo( }) ?? []; const subtitleTracks: framework.messages.Track[] = []; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - subtitleStreams.forEach((subtitleStream: any) => { + subtitleStreams.forEach((subtitleStream) => { if (subtitleStream.DeliveryUrl === undefined) { /* The CAF v3 player only supports vtt currently, * SRT subs can be "transcoded" to vtt by jellyfin. @@ -427,10 +426,6 @@ export function createStreamInfo( return; } - const textStreamUrl = subtitleStream.IsExternalUrl - ? subtitleStream.DeliveryUrl - : JellyfinApi.createUrl(subtitleStream.DeliveryUrl); - if (!info.subtitleStreamIndex) { return; } @@ -440,10 +435,26 @@ export function createStreamInfo( cast.framework.messages.TrackType.TEXT ); - track.trackId = subtitleStream.Index; - track.trackContentId = textStreamUrl; - track.language = subtitleStream.Language; - track.name = subtitleStream.DisplayTitle; + if (subtitleStream.IsExternal && subtitleStream.DeliveryUrl) { + track.trackContentId = subtitleStream.DeliveryUrl; + } else if (subtitleStream.DeliveryUrl) { + track.trackContentId = JellyfinApi.createUrl( + subtitleStream.DeliveryUrl + ); + } + + if (subtitleStream.Index) { + track.trackId = subtitleStream.Index; + } + + if (subtitleStream.Language) { + track.language = subtitleStream.Language; + } + + if (subtitleStream.DisplayTitle) { + track.name = subtitleStream.DisplayTitle; + } + // TODO this should not be hardcoded but we only support VTT currently track.trackContentType = 'text/vtt'; track.subtype = cast.framework.messages.TextTrackType.SUBTITLES;