Skip to content

Commit

Permalink
Merge pull request #731 from 3flex/subtitle-typing
Browse files Browse the repository at this point in the history
Use MediaStream type for subtitle stream processing
  • Loading branch information
nielsvanvelzen authored Dec 8, 2024
2 parents f668c3c + cb2897a commit 1b54a06
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,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.
Expand All @@ -460,10 +459,6 @@ export function createStreamInfo(
return;
}

const textStreamUrl = subtitleStream.IsExternalUrl
? subtitleStream.DeliveryUrl
: JellyfinApi.createUrl(subtitleStream.DeliveryUrl);

if (!info.subtitleStreamIndex) {
return;
}
Expand All @@ -473,10 +468,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;
Expand Down

0 comments on commit 1b54a06

Please sign in to comment.