1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge branch 'master' into burn-subtitle-transcoding

This commit is contained in:
gnattu 2024-10-09 06:53:18 +08:00 committed by GitHub
commit da4265eb46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
89 changed files with 3292 additions and 1480 deletions

View file

@ -24,6 +24,7 @@ import { MediaType } from '@jellyfin/sdk/lib/generated-client/models/media-type'
import { MediaError } from 'types/mediaError';
import { getMediaError } from 'utils/mediaError';
import { toApi } from 'utils/jellyfin-apiclient/compat';
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind.js';
const UNLIMITED_ITEMS = -1;
@ -697,7 +698,7 @@ function sortPlayerTargets(a, b) {
return aVal.localeCompare(bVal);
}
class PlaybackManager {
export class PlaybackManager {
constructor() {
const self = this;
@ -2417,20 +2418,20 @@ class PlaybackManager {
});
}
function rankStreamType(prevIndex, prevSource, mediaSource, streamType, isSecondarySubtitle) {
function rankStreamType(prevIndex, prevSource, mediaStreams, trackOptions, streamType, isSecondarySubtitle) {
if (prevIndex == -1) {
console.debug(`AutoSet ${streamType} - No Stream Set`);
if (streamType == 'Subtitle') {
if (isSecondarySubtitle) {
mediaSource.DefaultSecondarySubtitleStreamIndex = -1;
trackOptions.DefaultSecondarySubtitleStreamIndex = -1;
} else {
mediaSource.DefaultSubtitleStreamIndex = -1;
trackOptions.DefaultSubtitleStreamIndex = -1;
}
}
return;
}
if (!prevSource.MediaStreams || !mediaSource.MediaStreams) {
if (!prevSource.MediaStreams || !mediaStreams) {
console.debug(`AutoSet ${streamType} - No MediaStreams`);
return;
}
@ -2456,7 +2457,7 @@ class PlaybackManager {
}
let newRelIndex = 0;
for (const stream of mediaSource.MediaStreams) {
for (const stream of mediaStreams) {
if (stream.Type != streamType) continue;
let score = 0;
@ -2479,38 +2480,38 @@ class PlaybackManager {
console.debug(`AutoSet ${streamType} - Using ${bestStreamIndex} score ${bestStreamScore}.`);
if (streamType == 'Subtitle') {
if (isSecondarySubtitle) {
mediaSource.DefaultSecondarySubtitleStreamIndex = bestStreamIndex;
trackOptions.DefaultSecondarySubtitleStreamIndex = bestStreamIndex;
} else {
mediaSource.DefaultSubtitleStreamIndex = bestStreamIndex;
trackOptions.DefaultSubtitleStreamIndex = bestStreamIndex;
}
}
if (streamType == 'Audio') {
mediaSource.DefaultAudioStreamIndex = bestStreamIndex;
trackOptions.DefaultAudioStreamIndex = bestStreamIndex;
}
} else {
console.debug(`AutoSet ${streamType} - Threshold not met. Using default.`);
}
}
function autoSetNextTracks(prevSource, mediaSource, audio, subtitle) {
function autoSetNextTracks(prevSource, mediaStreams, trackOptions, audio, subtitle) {
try {
if (!prevSource) return;
if (!mediaSource) {
console.warn('AutoSet - No mediaSource');
if (!mediaStreams) {
console.warn('AutoSet - No mediaStreams');
return;
}
if (audio && typeof prevSource.DefaultAudioStreamIndex == 'number') {
rankStreamType(prevSource.DefaultAudioStreamIndex, prevSource, mediaSource, 'Audio');
rankStreamType(prevSource.DefaultAudioStreamIndex, prevSource, mediaStreams, trackOptions, 'Audio');
}
if (subtitle && typeof prevSource.DefaultSubtitleStreamIndex == 'number') {
rankStreamType(prevSource.DefaultSubtitleStreamIndex, prevSource, mediaSource, 'Subtitle');
rankStreamType(prevSource.DefaultSubtitleStreamIndex, prevSource, mediaStreams, trackOptions, 'Subtitle');
}
if (subtitle && typeof prevSource.DefaultSecondarySubtitleStreamIndex == 'number') {
rankStreamType(prevSource.DefaultSecondarySubtitleStreamIndex, prevSource, mediaSource, 'Subtitle', true);
rankStreamType(prevSource.DefaultSecondarySubtitleStreamIndex, prevSource, mediaStreams, trackOptions, 'Subtitle', true);
}
} catch (e) {
console.error(`AutoSet - Caught unexpected error: ${e}`);
@ -2582,12 +2583,25 @@ class PlaybackManager {
});
}
return Promise.all([promise, player.getDeviceProfile(item)]).then(function (responses) {
const apiClient = ServerConnections.getApiClient(item.ServerId);
let mediaSourceId;
const isLiveTv = [BaseItemKind.TvChannel, BaseItemKind.LiveTvChannel].includes(item.Type);
if (!isLiveTv) {
mediaSourceId = playOptions.mediaSourceId || item.Id;
}
const getMediaStreams = isLiveTv ? Promise.resolve([]) : apiClient.getItem(apiClient.getCurrentUserId(), mediaSourceId)
.then(fullItem => {
return fullItem.MediaStreams;
});
return Promise.all([promise, player.getDeviceProfile(item), apiClient.getCurrentUser(), getMediaStreams]).then(function (responses) {
const deviceProfile = responses[1];
const user = responses[2];
const mediaStreams = responses[3];
const apiClient = ServerConnections.getApiClient(item.ServerId);
const mediaSourceId = playOptions.mediaSourceId;
const audioStreamIndex = playOptions.audioStreamIndex;
const subtitleStreamIndex = playOptions.subtitleStreamIndex;
const options = {
@ -2610,9 +2624,20 @@ class PlaybackManager {
// this reference was only needed by sendPlaybackListToPlayer
playOptions.items = null;
const trackOptions = {};
autoSetNextTracks(prevSource, mediaStreams, trackOptions, user.Configuration.RememberAudioSelections, user.Configuration.RememberSubtitleSelections);
if (trackOptions.DefaultAudioStreamIndex != null) {
options.audioStreamIndex = trackOptions.DefaultAudioStreamIndex;
}
if (trackOptions.DefaultSubtitleStreamIndex != null) {
options.subtitleStreamIndex = trackOptions.DefaultSubtitleStreamIndex;
}
return getPlaybackMediaSource(player, apiClient, deviceProfile, item, mediaSourceId, options).then(async (mediaSource) => {
const user = await apiClient.getCurrentUser();
autoSetNextTracks(prevSource, mediaSource, user.Configuration.RememberAudioSelections, user.Configuration.RememberSubtitleSelections);
if (trackOptions.DefaultSecondarySubtitleStreamIndex != null) {
mediaSource.DefaultSecondarySubtitleStreamIndex = trackOptions.DefaultSecondarySubtitleStreamIndex;
}
if (mediaSource.DefaultSubtitleStreamIndex == null || mediaSource.DefaultSubtitleStreamIndex < 0) {
mediaSource.DefaultSubtitleStreamIndex = mediaSource.DefaultSecondarySubtitleStreamIndex;