refactor: support vtt and ass subtitles
This commit is contained in:
17 files changed
+726
-452
No files matched your search
+7
-4
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.5.0/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/1.8.0/schema.json",
|
||||
"organizeImports": {
|
||||
"enabled": true
|
||||
},
|
||||
@@ -8,13 +8,16 @@
|
||||
"rules": {
|
||||
"recommended": true,
|
||||
"style": {
|
||||
"noNonNullAssertion": "off"
|
||||
"noNonNullAssertion": "off",
|
||||
"useEnumInitializers": "off"
|
||||
},
|
||||
"a11y": {
|
||||
"useKeyWithClickEvents": "off"
|
||||
"useKeyWithClickEvents": "off",
|
||||
"useMediaCaption": "off"
|
||||
},
|
||||
"correctness": {
|
||||
"useExhaustiveDependencies": "off"
|
||||
"useExhaustiveDependencies": "off",
|
||||
"noUnusedImports": "off"
|
||||
},
|
||||
"suspicious": {
|
||||
"noExplicitAny": "off"
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"blurhash": "^2.0.5",
|
||||
"events": "^3.3.0",
|
||||
"framer-motion": "^11.3.0",
|
||||
"hls.js": "^1.5.13",
|
||||
"jassub": "^1.7.15",
|
||||
"lodash": "^4.17.21",
|
||||
"material-symbols": "^0.21.0",
|
||||
|
||||
Generated
+8
@@ -92,6 +92,9 @@ importers:
|
||||
framer-motion:
|
||||
specifier: ^11.3.0
|
||||
version: 11.3.0(@emotion/is-prop-valid@1.2.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
hls.js:
|
||||
specifier: ^1.5.13
|
||||
version: 1.5.13
|
||||
jassub:
|
||||
specifier: ^1.7.15
|
||||
version: 1.7.15
|
||||
@@ -1753,6 +1756,9 @@ packages:
|
||||
hermes-parser@0.21.1:
|
||||
resolution: {integrity: sha512-ANsRSBqQHzca7AXbsuwKApSQhAdljPip63MgqLebSVzNUI+A3NDzfiH9Ny4df4fA7Ndso3kPR1V/x1YEc7BYxA==}
|
||||
|
||||
hls.js@1.5.13:
|
||||
resolution: {integrity: sha512-xRgKo84nsC7clEvSfIdgn/Tc0NOT+d7vdiL/wvkLO+0k0juc26NRBPPG1SfB8pd5bHXIjMW/F5VM8VYYkOYYdw==}
|
||||
|
||||
hoist-non-react-statics@3.3.2:
|
||||
resolution: {integrity: sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==}
|
||||
|
||||
@@ -4138,6 +4144,8 @@ snapshots:
|
||||
dependencies:
|
||||
hermes-estree: 0.21.1
|
||||
|
||||
hls.js@1.5.13: {}
|
||||
|
||||
hoist-non-react-statics@3.3.2:
|
||||
dependencies:
|
||||
react-is: 16.13.1
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
"store:allow-keys",
|
||||
"store:allow-load",
|
||||
"updater:allow-check",
|
||||
"updater:allow-download-and-install"
|
||||
"updater:allow-download-and-install",
|
||||
"window:default",
|
||||
"window:allow-set-fullscreen"
|
||||
]
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
{"main-capabilities":{"identifier":"main-capabilities","description":"Capability for desktop window","local":true,"windows":["main"],"permissions":["store:allow-get","store:allow-set","store:allow-save","store:allow-clear","store:allow-delete","store:allow-keys","store:allow-load","updater:allow-check","updater:allow-download-and-install"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default"]}}
|
||||
{"main-capabilities":{"identifier":"main-capabilities","description":"Capability for desktop window","local":true,"windows":["main"],"permissions":["store:allow-get","store:allow-set","store:allow-save","store:allow-clear","store:allow-delete","store:allow-keys","store:allow-load","updater:allow-check","updater:allow-download-and-install","window:default","window:allow-set-fullscreen"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default"]}}
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg width="39" height="14" viewBox="0 0 39 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M4 0H34.69C36.8991 0 38.69 1.79086 38.69 4V10C38.69 12.2091 36.8991 14 34.69 14H4.00001C1.79087 14 0 12.2091 0 10V4C0 1.79086 1.79086 0 4 0ZM6.7 9.395H4.4V3.525H3V10.505H6.7V9.395ZM10.7798 8.075L13.1398 3.525H11.5798L10.0898 6.715L8.58984 3.525H7.00984L9.37984 8.075V10.505H10.7798V8.075ZM16.0073 7.785L17.5473 10.505H19.1673L17.4973 7.675C18.0239 7.535 18.4206 7.28167 18.6873 6.915C18.9539 6.54167 19.0873 6.125 19.0873 5.665C19.0873 5.265 18.9906 4.905 18.7973 4.585C18.6106 4.25833 18.3273 4.00167 17.9473 3.815C17.5673 3.62167 17.1073 3.525 16.5673 3.525H13.9473V10.505H15.3473V7.785H16.0073ZM21.7535 10.505V3.525H20.3535V10.505H21.7535ZM23.2567 5.165C22.9501 5.705 22.7967 6.31833 22.7967 7.005C22.7967 7.69167 22.9501 8.305 23.2567 8.845C23.5701 9.385 23.9934 9.80833 24.5267 10.115C25.0667 10.415 25.6701 10.565 26.3367 10.565C27.1234 10.565 27.8067 10.3683 28.3867 9.975C28.9734 9.575 29.3834 9.01833 29.6167 8.305H28.0067C27.8467 8.63833 27.6201 8.89167 27.3267 9.065C27.0401 9.23167 26.7067 9.315 26.3267 9.315C25.9201 9.315 25.5567 9.22167 25.2367 9.035C24.9234 8.84167 24.6767 8.57167 24.4967 8.225C24.3234 7.87167 24.2367 7.465 24.2367 7.005C24.2367 6.53833 24.3234 6.13167 24.4967 5.785C24.6767 5.43833 24.9234 5.17167 25.2367 4.985C25.5567 4.79167 25.9201 4.695 26.3267 4.695C26.7067 4.695 27.0401 4.77833 27.3267 4.945C27.6201 5.11167 27.8467 5.36167 28.0067 5.695H29.6167C29.3834 4.98833 28.9734 4.435 28.3867 4.035C27.8001 3.635 27.1167 3.435 26.3367 3.435C25.6701 3.435 25.0667 3.58833 24.5267 3.895C23.9934 4.195 23.5701 4.61833 23.2567 5.165ZM31.9025 10.325C32.2958 10.4917 32.7358 10.575 33.2225 10.575C33.7358 10.575 34.1792 10.4817 34.5525 10.295C34.9258 10.1017 35.2092 9.845 35.4025 9.525C35.5958 9.205 35.6925 8.85833 35.6925 8.485C35.6925 8.05167 35.5892 7.70167 35.3825 7.435C35.1758 7.16833 34.9292 6.96833 34.6425 6.835C34.3558 6.70167 33.9858 6.56833 33.5325 6.435C33.1992 6.335 32.9392 6.24833 32.7525 6.175C32.5725 6.095 32.4192 5.995 32.2925 5.875C32.1725 5.74833 32.1125 5.59167 32.1125 5.405C32.1125 5.13833 32.1925 4.935 32.3525 4.795C32.5192 4.655 32.7392 4.585 33.0125 4.585C33.3258 4.585 33.5758 4.665 33.7625 4.825C33.9558 4.97833 34.0592 5.175 34.0725 5.415H35.6125C35.5658 4.78833 35.3158 4.30167 34.8625 3.955C34.4158 3.60167 33.8325 3.425 33.1125 3.425C32.6325 3.425 32.2058 3.50833 31.8325 3.675C31.4592 3.835 31.1692 4.06833 30.9625 4.375C30.7558 4.68167 30.6525 5.04167 30.6525 5.455C30.6525 5.895 30.7525 6.24833 30.9525 6.515C31.1592 6.775 31.4025 6.97167 31.6825 7.105C31.9692 7.23167 32.3392 7.36167 32.7925 7.495C33.1258 7.58833 33.3858 7.675 33.5725 7.755C33.7658 7.82833 33.9258 7.93167 34.0525 8.065C34.1792 8.19833 34.2425 8.36833 34.2425 8.575C34.2425 8.82833 34.1492 9.035 33.9625 9.195C33.7758 9.34833 33.5192 9.425 33.1925 9.425C32.8725 9.425 32.6192 9.34167 32.4325 9.175C32.2525 9.00833 32.1525 8.78167 32.1325 8.495H30.6325C30.6392 8.92167 30.7558 9.29167 30.9825 9.605C31.2092 9.91833 31.5158 10.1583 31.9025 10.325Z" fill="white"/>
|
||||
<path d="M15.3473 6.735H16.5173C16.8973 6.735 17.1806 6.645 17.3673 6.465C17.5539 6.27833 17.6473 6.02167 17.6473 5.695C17.6473 5.375 17.5539 5.12833 17.3673 4.955C17.1806 4.775 16.8973 4.685 16.5173 4.685H15.3473V6.735Z" fill="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.3 KiB |
@@ -15,6 +15,7 @@ import {
|
||||
type BaseItemDtoQueryResult,
|
||||
BaseItemKind,
|
||||
ItemFields,
|
||||
MediaProtocol,
|
||||
type PlaybackInfoResponse,
|
||||
SortOrder,
|
||||
type UserItemDataDto,
|
||||
@@ -33,6 +34,7 @@ import { playItem, usePlaybackDataLoadStore } from "@/utils/store/playback";
|
||||
|
||||
import type PlayResult from "@//utils/types/playResult";
|
||||
import { getRuntimeCompact } from "@/utils/date/time";
|
||||
import getSubtitle from "@/utils/methods/getSubtitles";
|
||||
import playbackProfile from "@/utils/playback-profiles";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
@@ -112,11 +114,11 @@ const PlayButton = ({
|
||||
audioStreamIndex: currentAudioTrack,
|
||||
subtitleStreamIndex:
|
||||
currentSubTrack === "nosub" ? -1 : currentSubTrack,
|
||||
itemId: result.data.Items[0].Id,
|
||||
itemId: result.data.Items?.[0].Id,
|
||||
startTimeTicks:
|
||||
result.data.Items[0].UserData?.PlaybackPositionTicks,
|
||||
result.data.Items?.[0].UserData?.PlaybackPositionTicks,
|
||||
userId: userId,
|
||||
mediaSourceId: result.data.Items[0].MediaSources[0].Id,
|
||||
mediaSourceId: result.data.Items?.[0].MediaSources?.[0].Id,
|
||||
playbackInfoDto: {
|
||||
DeviceProfile: playbackProfile,
|
||||
},
|
||||
@@ -192,9 +194,9 @@ const PlayButton = ({
|
||||
currentSubTrack === "nosub" ? -1 : currentSubTrack,
|
||||
itemId: itemId,
|
||||
startTimeTicks:
|
||||
result.data.Items[0].UserData.PlaybackPositionTicks,
|
||||
result.data.Items?.[0].UserData?.PlaybackPositionTicks,
|
||||
userId: userId,
|
||||
mediaSourceId: result.data.Items[0].MediaSources[0].Id,
|
||||
mediaSourceId: result.data.Items?.[0].MediaSources?.[0].Id,
|
||||
playbackInfoDto: {
|
||||
DeviceProfile: playbackProfile,
|
||||
},
|
||||
@@ -223,61 +225,64 @@ const PlayButton = ({
|
||||
} else {
|
||||
// Creates a queue containing all Episodes for a particular season(series) or collection of movies
|
||||
const queue = result?.item.Items;
|
||||
|
||||
let itemName = item.Name;
|
||||
let episodeTitle = "";
|
||||
if (result?.item.Items[0].SeriesId) {
|
||||
if (result?.item.Items?.[0].SeriesId) {
|
||||
itemName = result?.item.Items[0].SeriesName;
|
||||
episodeTitle = `S${result?.item.Items[0].ParentIndexNumber ?? 0}:E${
|
||||
result?.item.Items[0].IndexNumber ?? 0
|
||||
} ${result?.item.Items[0].Name}`;
|
||||
}
|
||||
|
||||
// Select correct subtitle track, this is useful if item is played with playbutton from card since that does not provide coorect default subtitle track index.
|
||||
let selectedSubtitleTrack: number | "nosub" | undefined =
|
||||
currentSubTrack;
|
||||
const subtitles =
|
||||
result?.mediaSource.MediaSources[0].MediaStreams?.filter(
|
||||
(value) => value.Type === "Subtitle",
|
||||
);
|
||||
let enableSubtitles = true;
|
||||
if (currentSubTrack === "nosub") {
|
||||
enableSubtitles = false;
|
||||
selectedSubtitleTrack = "nosub";
|
||||
} else if (!currentSubTrack && subtitles?.length > 0) {
|
||||
selectedSubtitleTrack = subtitles[0].Index;
|
||||
} else {
|
||||
enableSubtitles = false;
|
||||
}
|
||||
|
||||
// Subtitle
|
||||
const subtitle = getSubtitle(
|
||||
currentSubTrack,
|
||||
result?.mediaSource.MediaSources?.[0].MediaStreams,
|
||||
);
|
||||
console.log(subtitle);
|
||||
// URL generation
|
||||
const urlOptions = {
|
||||
Static: true,
|
||||
tag: result?.mediaSource.MediaSources[0].ETag,
|
||||
mediaSourceId: result?.mediaSource.MediaSources[0].Id,
|
||||
tag: result?.mediaSource.MediaSources?.[0].ETag,
|
||||
mediaSourceId: result?.mediaSource.MediaSources?.[0].Id,
|
||||
deviceId: api?.deviceInfo.id,
|
||||
api_key: api?.accessToken,
|
||||
};
|
||||
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
let playbackUrl = `${api?.basePath}/Videos/${result?.mediaSource.MediaSources[0].Id}/stream.${result?.mediaSource.MediaSources[0].Container}?${urlParams}`;
|
||||
|
||||
let playbackUrl = `${api?.basePath}/Videos/${result?.mediaSource.MediaSources?.[0].Id}/stream.${result?.mediaSource.MediaSources?.[0].Container}?${urlParams}`;
|
||||
if (
|
||||
result?.mediaSource.MediaSources[0].SupportsTranscoding &&
|
||||
result?.mediaSource.MediaSources[0].TranscodingUrl
|
||||
result?.mediaSource.MediaSources?.[0].SupportsTranscoding &&
|
||||
result?.mediaSource.MediaSources?.[0].TranscodingUrl
|
||||
) {
|
||||
playbackUrl = `${api.basePath}${result.mediaSource.MediaSources[0].TranscodingUrl}`;
|
||||
} else if (result?.mediaSource.MediaSources[0].hlsStream) {
|
||||
playbackUrl = result.mediaSource.MediaSources[0].hlsStream;
|
||||
}
|
||||
|
||||
let isDirectPlay = true;
|
||||
let isDirectStream = false;
|
||||
let isTranscode = false;
|
||||
if (result?.mediaSource.MediaSources?.[0].SupportsDirectPlay) {
|
||||
isDirectPlay = true;
|
||||
}
|
||||
if (
|
||||
result?.mediaSource.MediaSources?.[0].SupportsDirectStream &&
|
||||
result?.mediaSource.MediaSources?.[0]
|
||||
) {
|
||||
isDirectStream = true;
|
||||
}
|
||||
if (
|
||||
result?.mediaSource.MediaSources?.[0].SupportsTranscoding &&
|
||||
result?.mediaSource.MediaSources?.[0].TranscodingUrl
|
||||
) {
|
||||
isTranscode = true;
|
||||
}
|
||||
|
||||
playItem(
|
||||
itemName,
|
||||
episodeTitle,
|
||||
currentVideoTrack,
|
||||
currentAudioTrack,
|
||||
selectedSubtitleTrack,
|
||||
currentSubTrack,
|
||||
result?.mediaSource?.MediaSources[0].Container ?? "mkv",
|
||||
enableSubtitles,
|
||||
false,
|
||||
playbackUrl,
|
||||
userId,
|
||||
item.UserData?.PlaybackPositionTicks,
|
||||
@@ -285,9 +290,14 @@ const PlayButton = ({
|
||||
item,
|
||||
queue,
|
||||
0,
|
||||
subtitles,
|
||||
[],
|
||||
result?.mediaSource.MediaSources[0].Id,
|
||||
result?.mediaSource.PlaySessionId,
|
||||
subtitle,
|
||||
isDirectPlay,
|
||||
isDirectStream,
|
||||
isTranscode,
|
||||
result?.mediaSource.MediaSources?.[0].Protocol,
|
||||
);
|
||||
navigate({ to: "/player" });
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ export const Card = ({
|
||||
userId={userId}
|
||||
itemType={item.Type}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
currentVideoTrack={0}
|
||||
className="card-play-button"
|
||||
iconProps={{
|
||||
|
||||
@@ -7,7 +7,9 @@ import PlayButton from "../buttons/playButton";
|
||||
import TextLink from "../textLink";
|
||||
import "./musicTrack.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import type { QueryKey } from "@tanstack/react-query";
|
||||
import lyrics_icon from "../../assets/icons/lyrics.svg";
|
||||
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
@@ -33,6 +35,14 @@ const MusicTrack = ({
|
||||
playlistItemId,
|
||||
trackIndex,
|
||||
className = "",
|
||||
}: {
|
||||
item: BaseItemDto;
|
||||
queryKey: QueryKey;
|
||||
userId: string | undefined;
|
||||
playlistItem: boolean;
|
||||
playlistItemId: string;
|
||||
trackIndex: number;
|
||||
className: string;
|
||||
}) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const [currentTrackItem] = useAudioPlayback((state) => [state.item]);
|
||||
@@ -100,13 +110,24 @@ const MusicTrack = ({
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
{item.ArtistItems.map((artist, index) => (
|
||||
{item.HasLyrics && (
|
||||
<img
|
||||
src={lyrics_icon}
|
||||
alt="Lyrics"
|
||||
className="music-track-info-lyrics"
|
||||
/>
|
||||
)}
|
||||
{item.ArtistItems?.map((artist, index) => (
|
||||
<>
|
||||
<TextLink
|
||||
key={index}
|
||||
variant={"subtitle2"}
|
||||
location={`/artist/${artist.Id}`}
|
||||
otherProps={{
|
||||
fontWeight: 400,
|
||||
style: {
|
||||
textDecoration: "none",
|
||||
},
|
||||
}}
|
||||
>
|
||||
{artist.Name}
|
||||
@@ -6,6 +6,7 @@
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
&-icon {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
@@ -20,7 +21,7 @@
|
||||
}
|
||||
&-image {
|
||||
margin: 0.4em;
|
||||
border-radius: $border-radius-default;
|
||||
border-radius: $border-radius_04;
|
||||
overflow: hidden;
|
||||
aspect-ratio: 1;
|
||||
position: relative;
|
||||
@@ -43,6 +44,9 @@
|
||||
}
|
||||
&-info {
|
||||
justify-self: start;
|
||||
&-lyrics {
|
||||
margin-right: 0.4em;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
|
||||
@@ -58,9 +58,6 @@ type ApiContext = {
|
||||
};
|
||||
|
||||
export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
errorComponent: (error) => {
|
||||
console.error(error.error);
|
||||
},
|
||||
component: () => {
|
||||
const isQueryFetching = useIsFetching();
|
||||
const isMutating = useIsMutating();
|
||||
|
||||
+399
-296
@@ -159,6 +159,34 @@ function LibraryView() {
|
||||
case CollectionType.Boxsets:
|
||||
result = [{ title: "Collection", value: BaseItemKind.BoxSet }];
|
||||
break;
|
||||
case CollectionType.Music:
|
||||
result = [
|
||||
{
|
||||
title: "Albums",
|
||||
value: BaseItemKind.MusicAlbum,
|
||||
},
|
||||
{
|
||||
title: "Album Artist",
|
||||
value: BaseItemKind.MusicArtist,
|
||||
},
|
||||
{
|
||||
title: "Artist",
|
||||
value: "Artist",
|
||||
},
|
||||
{
|
||||
title: "Playlist",
|
||||
value: BaseItemKind.Playlist,
|
||||
},
|
||||
{
|
||||
title: "Songs",
|
||||
value: BaseItemKind.Audio,
|
||||
},
|
||||
{
|
||||
title: "Genre",
|
||||
value: BaseItemKind.Genre,
|
||||
},
|
||||
];
|
||||
break;
|
||||
default:
|
||||
result = [];
|
||||
}
|
||||
@@ -177,16 +205,57 @@ function LibraryView() {
|
||||
|
||||
const [sortBy, setSortBy] = useState<ItemSortBy>("Name");
|
||||
const [sortAscending, setSortAscending] = useState(true);
|
||||
const disableSort = useMemo(() => {
|
||||
switch (currentViewType) {
|
||||
case BaseItemKind.Genre:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}, [currentViewType]);
|
||||
const sortByOptions: SortByObject[] = useMemo(() => {
|
||||
let result: SortByObject[] = undefined!;
|
||||
switch (currentViewType) {
|
||||
case BaseItemKind.Audio:
|
||||
result = [
|
||||
{
|
||||
title: "Track Name",
|
||||
value: ItemSortBy.Name,
|
||||
},
|
||||
{
|
||||
title: "Album",
|
||||
value: ItemSortBy.Album,
|
||||
},
|
||||
{
|
||||
title: "Album Artist",
|
||||
value: ItemSortBy.AlbumArtist,
|
||||
},
|
||||
{
|
||||
title: "Artist",
|
||||
value: ItemSortBy.Artist,
|
||||
},
|
||||
{
|
||||
title: "Date Added",
|
||||
value: ItemSortBy.DateCreated,
|
||||
},
|
||||
{
|
||||
title: "Date Played",
|
||||
value: ItemSortBy.DatePlayed,
|
||||
},
|
||||
{
|
||||
title: "Play Count",
|
||||
value: ItemSortBy.PlayCount,
|
||||
},
|
||||
{
|
||||
title: "Release Date",
|
||||
value: ItemSortBy.PremiereDate,
|
||||
},
|
||||
{
|
||||
title: "Runtime",
|
||||
value: ItemSortBy.Runtime,
|
||||
},
|
||||
{
|
||||
title: "Random",
|
||||
value: ItemSortBy.Random,
|
||||
},
|
||||
];
|
||||
break;
|
||||
default:
|
||||
result = [];
|
||||
break;
|
||||
}
|
||||
switch (currentLib.data?.CollectionType) {
|
||||
case CollectionType.Movies:
|
||||
result = [
|
||||
@@ -312,13 +381,10 @@ function LibraryView() {
|
||||
},
|
||||
];
|
||||
break;
|
||||
default:
|
||||
result = [];
|
||||
break;
|
||||
}
|
||||
setSortBy(result?.[0]?.value);
|
||||
return result;
|
||||
}, [currentLib.data?.CollectionType]);
|
||||
}, [currentLib.data?.CollectionType, currentViewType]);
|
||||
useLayoutEffect(() => {}, [sortByOptions]);
|
||||
|
||||
const [filters, setFilters] = useState<Record<string, undefined | boolean>>({
|
||||
@@ -361,6 +427,11 @@ function LibraryView() {
|
||||
userId: user.data?.Id,
|
||||
parentId: id,
|
||||
});
|
||||
} else if (currentViewType === "Artist") {
|
||||
result = await getArtistsApi(api).getArtists({
|
||||
userId: user.data?.Id,
|
||||
parentId: id,
|
||||
});
|
||||
} else if (currentViewType === "Person") {
|
||||
result = await getPersonsApi(api).getPersons({
|
||||
userId: user.data?.Id,
|
||||
@@ -460,6 +531,33 @@ function LibraryView() {
|
||||
// gcTime: 0,
|
||||
});
|
||||
|
||||
const disableSort = useMemo(() => {
|
||||
if (items.data?.TotalRecordCount === 0) {
|
||||
return true; // Hide sorting options if library is empty
|
||||
}
|
||||
switch (currentViewType) {
|
||||
case BaseItemKind.MusicArtist:
|
||||
case BaseItemKind.Person:
|
||||
case BaseItemKind.MusicGenre:
|
||||
case BaseItemKind.Genre:
|
||||
case "Artist":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}, [currentViewType, items.isSuccess]);
|
||||
const disableFilters = useMemo(() => {
|
||||
switch (currentViewType) {
|
||||
case BaseItemKind.Movie:
|
||||
case BaseItemKind.Audio:
|
||||
case BaseItemKind.Series:
|
||||
case BaseItemKind.BoxSet:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}, [currentViewType]);
|
||||
|
||||
const cardSize = useMemo(
|
||||
() =>
|
||||
items.data?.Items?.[0]?.Type === BaseItemKind.MusicAlbum ||
|
||||
@@ -487,23 +585,15 @@ function LibraryView() {
|
||||
const virtualizer = useWindowVirtualizer({
|
||||
count,
|
||||
estimateSize: () => cardSize,
|
||||
overscan: 7,
|
||||
overscan: 1,
|
||||
});
|
||||
|
||||
const disabledSortViews = [
|
||||
"MusicArtist",
|
||||
"Person",
|
||||
"Genre",
|
||||
"MusicGenre",
|
||||
"Studio",
|
||||
];
|
||||
const allowedFilterViews: allowedFilters = [
|
||||
CollectionType.Movies,
|
||||
CollectionType.Tvshows,
|
||||
CollectionType.Music,
|
||||
CollectionType.Books,
|
||||
];
|
||||
const onlyStatusFilterViews = ["books", "music"];
|
||||
const rowVirtualizer = useWindowVirtualizer({
|
||||
count: items.data?.TotalRecordCount ?? 1,
|
||||
estimateSize: () => 80,
|
||||
overscan: 4,
|
||||
});
|
||||
// const onlyStatusFilterViews = ["books", "music"];
|
||||
|
||||
const [filterButtonAnchorEl, setFilterButtonAnchorEl] =
|
||||
useState<HTMLButtonElement | null>(null);
|
||||
@@ -523,26 +613,20 @@ function LibraryView() {
|
||||
threshold: 20,
|
||||
});
|
||||
|
||||
const [backdropItems, setBackdropItems] = useState<BaseItemDto[] | undefined>(
|
||||
[],
|
||||
);
|
||||
useEffect(() => {
|
||||
// Filter all items having backdrop images for library backdrop
|
||||
const backdropItems = useMemo(() => {
|
||||
if (items.isSuccess) {
|
||||
const backdropItemsTemp = items.data.Items?.filter(
|
||||
const temp = items.data.Items?.filter(
|
||||
(item) => item.BackdropImageTags?.length,
|
||||
);
|
||||
const backdropItem = backdropItemsTemp?.[0];
|
||||
// enqueueSnackbar("Running");
|
||||
setBackdrop(
|
||||
api?.getItemImageUrl(backdropItem?.Id ?? "", "Backdrop", {
|
||||
tag: backdropItem?.BackdropImageTags?.[0],
|
||||
api.getItemImageUrl(temp?.[0]?.Id, "Backdrop", {
|
||||
tag: temp?.[0]?.BackdropImageTags?.[0],
|
||||
}),
|
||||
backdropItem?.BackdropImageTags?.[0] ?? "none",
|
||||
temp?.[0]?.BackdropImageTags?.[0] ?? "none",
|
||||
);
|
||||
setBackdropItems(backdropItemsTemp);
|
||||
return temp;
|
||||
}
|
||||
}, [items.isSuccess]);
|
||||
}, [items]);
|
||||
|
||||
useEffect(() => {
|
||||
if (backdropItems?.length) {
|
||||
@@ -657,7 +741,7 @@ function LibraryView() {
|
||||
</IconButton>
|
||||
<TextField
|
||||
select
|
||||
value={sortBy}
|
||||
value={sortBy ?? "Name"}
|
||||
size="small"
|
||||
onChange={(e: ChangeEvent<HTMLSelectElement>) =>
|
||||
setSortBy(e.target.value)
|
||||
@@ -687,232 +771,236 @@ function LibraryView() {
|
||||
))}
|
||||
</TextField>
|
||||
)}
|
||||
<>
|
||||
<Button
|
||||
startIcon={
|
||||
<span className="material-symbols-rounded">
|
||||
filter_list
|
||||
</span>
|
||||
}
|
||||
size="large"
|
||||
color="white"
|
||||
onClick={handleFilterDropdown}
|
||||
>
|
||||
Filter
|
||||
</Button>
|
||||
<Menu
|
||||
open={filterMenuOpen}
|
||||
anchorEl={filterButtonAnchorEl}
|
||||
onClose={() => setFilterButtonAnchorEl(null)}
|
||||
slotProps={{
|
||||
paper: {
|
||||
style: {
|
||||
width: "28em",
|
||||
maxHeight: "32em",
|
||||
{!disableFilters && (
|
||||
<>
|
||||
<Button
|
||||
startIcon={
|
||||
<span className="material-symbols-rounded">
|
||||
filter_list
|
||||
</span>
|
||||
}
|
||||
size="large"
|
||||
color="white"
|
||||
onClick={handleFilterDropdown}
|
||||
>
|
||||
Filter
|
||||
</Button>
|
||||
<Menu
|
||||
open={filterMenuOpen}
|
||||
anchorEl={filterButtonAnchorEl}
|
||||
onClose={() => setFilterButtonAnchorEl(null)}
|
||||
slotProps={{
|
||||
paper: {
|
||||
style: {
|
||||
width: "28em",
|
||||
maxHeight: "32em",
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="h6"
|
||||
fontWeight={600}
|
||||
mx="0.4em"
|
||||
mb={0.5}
|
||||
>
|
||||
Filters
|
||||
</Typography>
|
||||
<FormControl
|
||||
style={{
|
||||
background: "rgb(0 0 0 / 0.4)",
|
||||
width: "100%",
|
||||
padding: "0.4em 1em",
|
||||
borderRadius: "6px",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isPlayed} />}
|
||||
label="Played"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isPlayed: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isUnPlayed} />}
|
||||
label="Unplayed"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isUnPlayed: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isResumable} />}
|
||||
label="Resumable"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isResumable: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isFavorite} />}
|
||||
label="Favorites"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isFavorite: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<Typography
|
||||
variant="h6"
|
||||
fontWeight={600}
|
||||
mx="0.4em"
|
||||
mb={0.5}
|
||||
>
|
||||
Features
|
||||
</Typography>
|
||||
<FormControl
|
||||
style={{
|
||||
background: "rgb(0 0 0 / 0.4)",
|
||||
width: "100%",
|
||||
padding: "0.4em 1em",
|
||||
borderRadius: "6px",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasSubtitles} />}
|
||||
label="Subtitles"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasSubtitles: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasTrailer} />}
|
||||
label="Trailer"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasTrailer: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox checked={filters.hasSpecialFeature} />
|
||||
}
|
||||
label="Special Features"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasSpecialFeature: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasThemeSong} />}
|
||||
label="Theme Song"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasThemeSong: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasThemeVideo} />}
|
||||
label="Theme Video"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasThemeVideo: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<Typography
|
||||
variant="h6"
|
||||
fontWeight={600}
|
||||
mx="0.4em"
|
||||
mb={0.5}
|
||||
>
|
||||
Video Types
|
||||
</Typography>
|
||||
<FormControl
|
||||
style={{
|
||||
background: "rgb(0 0 0 / 0.4)",
|
||||
width: "100%",
|
||||
padding: "0.4em 1em",
|
||||
borderRadius: "6px",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={videoTypesState.BluRay} />}
|
||||
label="BluRay"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setVideoTypesState((s) => ({
|
||||
...s,
|
||||
BluRay: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={videoTypesState.Dvd} />}
|
||||
label="DVD"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setVideoTypesState((s) => ({
|
||||
...s,
|
||||
Dvd: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isHD} />}
|
||||
label="HD"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isHD: e.target.checked,
|
||||
}));
|
||||
<Typography
|
||||
variant="h6"
|
||||
fontWeight={600}
|
||||
mx="0.4em"
|
||||
mb={0.5}
|
||||
>
|
||||
Filters
|
||||
</Typography>
|
||||
<FormControl
|
||||
style={{
|
||||
background: "rgb(0 0 0 / 0.4)",
|
||||
width: "100%",
|
||||
padding: "0.4em 1em",
|
||||
borderRadius: "6px",
|
||||
}}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.is4K} />}
|
||||
label="4k"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
is4K: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={false} />}
|
||||
label="SD"
|
||||
disabled
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox value={filters.is3D} />}
|
||||
label="3D"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
is3D: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
</Menu>
|
||||
</>
|
||||
>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isPlayed} />}
|
||||
label="Played"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isPlayed: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isUnPlayed} />}
|
||||
label="Unplayed"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isUnPlayed: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isResumable} />}
|
||||
label="Resumable"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isResumable: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isFavorite} />}
|
||||
label="Favorites"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isFavorite: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<Typography
|
||||
variant="h6"
|
||||
fontWeight={600}
|
||||
mx="0.4em"
|
||||
mb={0.5}
|
||||
>
|
||||
Features
|
||||
</Typography>
|
||||
<FormControl
|
||||
style={{
|
||||
background: "rgb(0 0 0 / 0.4)",
|
||||
width: "100%",
|
||||
padding: "0.4em 1em",
|
||||
borderRadius: "6px",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasSubtitles} />}
|
||||
label="Subtitles"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasSubtitles: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasTrailer} />}
|
||||
label="Trailer"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasTrailer: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox checked={filters.hasSpecialFeature} />
|
||||
}
|
||||
label="Special Features"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasSpecialFeature: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasThemeSong} />}
|
||||
label="Theme Song"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasThemeSong: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.hasThemeVideo} />}
|
||||
label="Theme Video"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
hasThemeVideo: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<Typography
|
||||
variant="h6"
|
||||
fontWeight={600}
|
||||
mx="0.4em"
|
||||
mb={0.5}
|
||||
>
|
||||
Video Types
|
||||
</Typography>
|
||||
<FormControl
|
||||
style={{
|
||||
background: "rgb(0 0 0 / 0.4)",
|
||||
width: "100%",
|
||||
padding: "0.4em 1em",
|
||||
borderRadius: "6px",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox checked={videoTypesState.BluRay} />
|
||||
}
|
||||
label="BluRay"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setVideoTypesState((s) => ({
|
||||
...s,
|
||||
BluRay: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={videoTypesState.Dvd} />}
|
||||
label="DVD"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setVideoTypesState((s) => ({
|
||||
...s,
|
||||
Dvd: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.isHD} />}
|
||||
label="HD"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
isHD: e.target.checked,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={filters.is4K} />}
|
||||
label="4k"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
is4K: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={false} />}
|
||||
label="SD"
|
||||
disabled
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={<Checkbox value={filters.is3D} />}
|
||||
label="3D"
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
setFilters((s) => ({
|
||||
...s,
|
||||
is3D: e.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
</Menu>
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</div>
|
||||
)}
|
||||
@@ -1036,41 +1124,56 @@ function LibraryView() {
|
||||
) : (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
height: `${rowVirtualizer.getTotalSize()}px`,
|
||||
width: "100%",
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
{items.data.Items.map((item) => (
|
||||
<MusicTrack
|
||||
item={item}
|
||||
key={item.Id}
|
||||
// queryKey={[
|
||||
// "libraryView",
|
||||
// "currentLibItems",
|
||||
// id,
|
||||
// {
|
||||
// currentViewType: currentViewType,
|
||||
// sortAscending: sortAscending,
|
||||
// sortBy: sortBy,
|
||||
// extraFilters: {
|
||||
// hasSubtitles: hasSubtitles,
|
||||
// hasTrailer: hasTrailer,
|
||||
// hasSpecialFeature: hasSpecialFeature,
|
||||
// hasThemeSong: hasThemeSong,
|
||||
// hasThemeVideo: hasThemeVideo,
|
||||
// },
|
||||
// qualityFilters: {
|
||||
// isBluRay: isBluRay,
|
||||
// isDVD: isDVD,
|
||||
// isHD: isHD,
|
||||
// is4K: is4K,
|
||||
// is3D: is3D,
|
||||
// },
|
||||
// },
|
||||
// ]}
|
||||
userId={user.data.Id}
|
||||
/>
|
||||
))}
|
||||
{rowVirtualizer.getVirtualItems().map((virtualRow) => {
|
||||
const item = items.data?.Items?.[virtualRow.index];
|
||||
return (
|
||||
<div
|
||||
key={item.Id}
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: "100%",
|
||||
height: `${virtualRow.size}px`,
|
||||
transform: `translateY(${virtualRow.start}px)`,
|
||||
}}
|
||||
>
|
||||
<MusicTrack
|
||||
item={item}
|
||||
// queryKey={[
|
||||
// "libraryView",
|
||||
// "currentLibItems",
|
||||
// id,
|
||||
// {
|
||||
// currentViewType: currentViewType,
|
||||
// sortAscending: sortAscending,
|
||||
// sortBy: sortBy,
|
||||
// extraFilters: {
|
||||
// hasSubtitles: hasSubtitles,
|
||||
// hasTrailer: hasTrailer,
|
||||
// hasSpecialFeature: hasSpecialFeature,
|
||||
// hasThemeSong: hasThemeSong,
|
||||
// hasThemeVideo: hasThemeVideo,
|
||||
// },
|
||||
// qualityFilters: {
|
||||
// isBluRay: isBluRay,
|
||||
// isDVD: isDVD,
|
||||
// isHD: isHD,
|
||||
// is4K: is4K,
|
||||
// is3D: is3D,
|
||||
// },
|
||||
// },
|
||||
// ]}
|
||||
userId={user.data?.Id}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,55 +1,42 @@
|
||||
import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import React, { useLayoutEffect } from "react";
|
||||
import type React from "react";
|
||||
import { useLayoutEffect, useMemo } from "react";
|
||||
|
||||
import Backdrop from "@mui/material/Backdrop";
|
||||
import Box from "@mui/material/Box";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Menu from "@mui/material/Menu";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import Slider from "@mui/material/Slider";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import ReactPlayer from "react-player";
|
||||
|
||||
import { usePlaybackStore } from "@/utils/store/playback";
|
||||
import { changeSubtitleTrack, usePlaybackStore } from "@/utils/store/playback";
|
||||
|
||||
import { getRuntimeMusic, secToTicks, ticksToSec } from "@/utils/date/time";
|
||||
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Navigate, useNavigate } from "react-router-dom";
|
||||
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
|
||||
|
||||
import "./videoPlayer.scss";
|
||||
|
||||
import { endsAt } from "@/utils/date/time";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
ItemFields,
|
||||
LocationType,
|
||||
PlayMethod,
|
||||
RepeatMode,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { PlayMethod, RepeatMode } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
|
||||
import { setBackdrop } from "@/utils/store/backdrop";
|
||||
|
||||
import { FormControl, TextField } from "@mui/material";
|
||||
import type JASSUB from "jassub";
|
||||
import { TextField } from "@mui/material";
|
||||
import JASSUB from "jassub";
|
||||
import workerUrl from "jassub/dist/jassub-worker.js?url";
|
||||
import wasmUrl from "jassub/dist/jassub-worker.wasm?url";
|
||||
|
||||
import PlayNextButton from "@/components/buttons/playNextButton";
|
||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||
import QueueButton from "@/components/buttons/queueButton";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
||||
import type { OnProgressProps } from "react-player/base";
|
||||
import subtitleFont from "./Noto-Sans-Indosphere.ttf";
|
||||
|
||||
const ticksDisplay = (ticks: number) => {
|
||||
@@ -84,7 +71,7 @@ function VideoPlayer() {
|
||||
const [hoveringOsd, setHoveringOsd] = useState(false);
|
||||
|
||||
const [
|
||||
hlsStream,
|
||||
playbackStream,
|
||||
item,
|
||||
itemName,
|
||||
itemDuration,
|
||||
@@ -94,7 +81,7 @@ function VideoPlayer() {
|
||||
enableSubtitle,
|
||||
playsessionId,
|
||||
] = usePlaybackStore((state) => [
|
||||
state.hlsStream,
|
||||
state.playbackStream,
|
||||
state.item,
|
||||
state.itemName,
|
||||
state.itemDuration,
|
||||
@@ -126,22 +113,10 @@ function VideoPlayer() {
|
||||
|
||||
useEffect(() => setBackdrop("", ""), []);
|
||||
|
||||
const [subtitleRenderer, setSubtitleRenderer] = useState<JASSUB>(null);
|
||||
|
||||
const handleReady = async () => {
|
||||
console.log("isReady");
|
||||
if (!isReady) {
|
||||
if (selectedSubtitle !== "nosub") {
|
||||
const font = await fetch(subtitleFont).then((r) => r.arrayBuffer());
|
||||
const uint8 = new Uint8Array(font);
|
||||
// const subtitleRendererRaw = new JASSUB({
|
||||
// video: player.current.getInternalPlayer(),
|
||||
// subUrl: `${api.basePath}/Videos/${item.Id}/${item.Id}/Subtitles/${mediaSource.subtitleTrack}/Stream.ass?api_key=${api.accessToken}`,
|
||||
// workerUrl,
|
||||
// wasmUrl,
|
||||
// availableFonts: { "noto sans": uint8 },
|
||||
// fallbackFont: "Noto Sans",
|
||||
// });
|
||||
// setSubtitleRenderer(subtitleRendererRaw);
|
||||
}
|
||||
|
||||
player.current?.seekTo(ticksToSec(startPosition), "seconds");
|
||||
@@ -167,7 +142,8 @@ function VideoPlayer() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleProgress = async (event) => {
|
||||
const handleProgress = async (event: OnProgressProps) => {
|
||||
setProgress(secToTicks(event.playedSeconds));
|
||||
// Report Jellyfin server: Playback progress
|
||||
getPlaystateApi(api).reportPlaybackProgress({
|
||||
playbackProgressInfo: {
|
||||
@@ -180,7 +156,7 @@ function VideoPlayer() {
|
||||
PlayMethod: PlayMethod.DirectPlay,
|
||||
PlaySessionId: playsessionId,
|
||||
PlaybackStartTimeTicks: startPosition,
|
||||
PositionTicks: progress,
|
||||
PositionTicks: secToTicks(event.playedSeconds),
|
||||
RepeatMode: RepeatMode.RepeatNone,
|
||||
VolumeLevel: volume * 100,
|
||||
},
|
||||
@@ -189,9 +165,7 @@ function VideoPlayer() {
|
||||
|
||||
const handleExitPlayer = async () => {
|
||||
appWindow.getCurrent().setFullscreen(false);
|
||||
if (subtitleRenderer) {
|
||||
subtitleRenderer.destroy();
|
||||
}
|
||||
|
||||
history.back();
|
||||
// Report Jellyfin server: Playback has ended/stopped
|
||||
getPlaystateApi(api).reportPlaybackStopped({
|
||||
@@ -206,7 +180,8 @@ function VideoPlayer() {
|
||||
usePlaybackStore.setState(usePlaybackStore.getInitialState());
|
||||
};
|
||||
|
||||
const player = useRef(null);
|
||||
const player = useRef<ReactPlayer | null>(null);
|
||||
const hlsPlayer = player.current?.getInternalPlayer("hls");
|
||||
|
||||
const handleShowOsd = () => {
|
||||
let timer = null;
|
||||
@@ -268,44 +243,86 @@ function VideoPlayer() {
|
||||
};
|
||||
}, [handleKeyPress]);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchFonts() {
|
||||
const font = await fetch(subtitleFont).then((r) => r.arrayBuffer());
|
||||
const uint8 = new Uint8Array(font);
|
||||
return uint8;
|
||||
}
|
||||
if (subtitleRenderer)
|
||||
if (showSubtitles) {
|
||||
subtitleRenderer.setTrackByUrl(
|
||||
`${api.basePath}/Videos/${item?.Id}/${item?.Id}/Subtitles/${selectedSubtitle}/Stream.ass?api_key=${api.accessToken}`,
|
||||
);
|
||||
} else {
|
||||
subtitleRenderer.freeTrack();
|
||||
}
|
||||
else if (
|
||||
!subtitleRenderer &&
|
||||
selectedSubtitle !== "nosub" &&
|
||||
showSubtitles
|
||||
) {
|
||||
// fetchFonts().then((uint8) => {
|
||||
// const subtitleRendererRaw = new JASSUB({
|
||||
// video: player.current.getInternalPlayer(),
|
||||
// subUrl: `${api.basePath}/Videos/${item?.Id}/${item?.Id}/Subtitles/${selectedSubtitle}/Stream.ass?api_key=${api.accessToken}`,
|
||||
// workerUrl,
|
||||
// wasmUrl,
|
||||
// availableFonts: { "noto sans": uint8 },
|
||||
// fallbackFont: "Noto Sans",
|
||||
// });
|
||||
// setSubtitleRenderer(subtitleRendererRaw);
|
||||
// });
|
||||
}
|
||||
}, [showSubtitles, selectedSubtitle]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setPlaying(true);
|
||||
setIsReady(false);
|
||||
}, [item?.Id]);
|
||||
|
||||
// const [reactPlayerCaptions, setReactPlayerCaptions] = useState<
|
||||
// ReactPlayerCaption[]
|
||||
// >([]);
|
||||
// useEffect(() => {
|
||||
// switch (mediaSource.subtitle.format) {
|
||||
// case "subrip":
|
||||
// case "vtt":
|
||||
// setReactPlayerCaptions([
|
||||
// {
|
||||
// kind: "subtitles",
|
||||
// src: mediaSource.subtitle.track,
|
||||
// srcLang: "en",
|
||||
// default: true,
|
||||
// },
|
||||
// ]);
|
||||
// break;
|
||||
// }
|
||||
// }, [mediaSource.subtitle.track]);
|
||||
|
||||
const reactPlayerCaptions = useMemo(() => {
|
||||
if (
|
||||
mediaSource.subtitle.format === "vtt" ||
|
||||
mediaSource.subtitle.format === "subrip"
|
||||
) {
|
||||
return [
|
||||
{
|
||||
kind: "subtitles",
|
||||
src: `${api.basePath}${mediaSource.subtitle.url}`,
|
||||
srcLang: "en",
|
||||
default: true,
|
||||
label: mediaSource.subtitle.url,
|
||||
},
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}, [mediaSource.subtitle.track]);
|
||||
|
||||
const handleSubtitleChange = (
|
||||
e: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>,
|
||||
) => {
|
||||
changeSubtitleTrack(e.target.value, mediaSource.subtitle.allTracks);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
async function createJASSUB() {
|
||||
if (player.current?.getInternalPlayer()) {
|
||||
const font = await fetch(subtitleFont).then((r) => r.arrayBuffer());
|
||||
const uint8 = new Uint8Array(font);
|
||||
const subtitleRendererRaw = new JASSUB({
|
||||
video: player.current.getInternalPlayer(),
|
||||
subUrl: `${api.basePath}${mediaSource.subtitle.url}`,
|
||||
workerUrl,
|
||||
wasmUrl,
|
||||
availableFonts: { "noto sans": uint8 },
|
||||
fallbackFont: "Noto Sans",
|
||||
});
|
||||
// setJassubRenderer(subtitleRendererRaw);
|
||||
}
|
||||
}
|
||||
if (player.current?.getInternalPlayer()) {
|
||||
if (
|
||||
mediaSource.subtitle.format === "ass" ||
|
||||
mediaSource.subtitle.format === "ssa"
|
||||
) {
|
||||
const jassubRenderer = new JASSUB({
|
||||
video: player.current?.getInternalPlayer(),
|
||||
workerUrl,
|
||||
wasmUrl,
|
||||
subUrl: `${api.basePath}${mediaSource.subtitle.url}`,
|
||||
});
|
||||
return () => jassubRenderer.destroy(); // Remove JASSUB renderer when track changes to fix duplicate renders
|
||||
}
|
||||
}
|
||||
}, [mediaSource.subtitle.track, player.current?.getInternalPlayer()]);
|
||||
|
||||
return (
|
||||
<div className="video-player">
|
||||
<AnimatePresence>
|
||||
@@ -383,14 +400,15 @@ function VideoPlayer() {
|
||||
select
|
||||
label="Subtitles"
|
||||
variant="outlined"
|
||||
value={selectedSubtitle}
|
||||
onChange={(e) => setSelectedSubtitle(e.target.value)}
|
||||
value={mediaSource.subtitle.track}
|
||||
onChange={handleSubtitleChange}
|
||||
fullWidth
|
||||
disabled={mediaSource.subtitle.track === -2}
|
||||
>
|
||||
<MenuItem key={-1} value={"nosub"}>
|
||||
<MenuItem key={-1} value={-1}>
|
||||
No Subtitle
|
||||
</MenuItem>
|
||||
{mediaSource.availableSubtitleTracks.map((sub) => (
|
||||
{mediaSource.subtitle.allTracks?.map((sub) => (
|
||||
<MenuItem key={sub.Index} value={sub.Index}>
|
||||
{sub.DisplayTitle}
|
||||
</MenuItem>
|
||||
@@ -536,7 +554,10 @@ function VideoPlayer() {
|
||||
</span>
|
||||
</IconButton>
|
||||
<QueueButton />
|
||||
<IconButton onClick={() => setShowSubtitles((state) => !state)}>
|
||||
<IconButton
|
||||
disabled={mediaSource.subtitle.track === -2}
|
||||
onClick={() => setShowSubtitles((state) => !state)}
|
||||
>
|
||||
<span className={"material-symbols-rounded"}>
|
||||
{showSubtitles
|
||||
? "closed_caption"
|
||||
@@ -564,7 +585,7 @@ function VideoPlayer() {
|
||||
<ReactPlayer
|
||||
key={item?.Id}
|
||||
playing={playing}
|
||||
url={hlsStream}
|
||||
url={playbackStream}
|
||||
ref={player}
|
||||
onProgress={handleProgress}
|
||||
onError={(error, data, hls, hlsG) => {
|
||||
@@ -579,9 +600,14 @@ function VideoPlayer() {
|
||||
position: "fixed",
|
||||
zIndex: 1,
|
||||
}}
|
||||
// onReady={(playerRef) => {
|
||||
// playerRef.seekTo(ticksToSec(startPosition));
|
||||
// }}
|
||||
config={{
|
||||
file: {
|
||||
attributes: {
|
||||
crossOrigin: "true",
|
||||
},
|
||||
tracks: reactPlayerCaptions,
|
||||
},
|
||||
}}
|
||||
volume={muted ? 0 : volume}
|
||||
onReady={handleReady}
|
||||
onBuffer={() => setLoading(true)}
|
||||
|
||||
@@ -200,7 +200,7 @@ function SeriesTitlePage() {
|
||||
});
|
||||
|
||||
const episodes = useQuery({
|
||||
queryKey: ["item", id, `season ${currentSeason + 1}`, "episodes"],
|
||||
queryKey: ["item", id, "season", currentSeason, "episodes"],
|
||||
queryFn: async () => {
|
||||
const result = await getTvShowsApi(api).getEpisodes({
|
||||
userId: user.data.Id,
|
||||
@@ -284,50 +284,53 @@ function SeriesTitlePage() {
|
||||
sessionStorage.setItem(
|
||||
`backdrop-${item.data?.Id}`,
|
||||
api.getItemImageUrl(currentSeasonItem.data.Id, "Backdrop", {
|
||||
tag: currentSeasonItem.data.BackdropImageTags[0],
|
||||
tag: currentSeasonItem.data.BackdropImageTags?.[0],
|
||||
}),
|
||||
);
|
||||
sessionStorage.setItem(
|
||||
`backdrop-${item.data?.Id}-key`,
|
||||
currentSeasonItem.data.BackdropImageTags[0],
|
||||
currentSeasonItem.data.BackdropImageTags?.[0],
|
||||
);
|
||||
setBackdropImage({
|
||||
url: api.getItemImageUrl(item.data?.Id, "Backdrop", {
|
||||
tag: item.data?.BackdropImageTags[0],
|
||||
url: api.getItemImageUrl(currentSeasonItem.data.Id, "Backdrop", {
|
||||
tag: currentSeasonItem.data.BackdropImageTags?.[0],
|
||||
}),
|
||||
key: item.data?.BackdropImageTags[0],
|
||||
key: currentSeasonItem.data.BackdropImageTags?.[0],
|
||||
});
|
||||
setBackdrop(
|
||||
api.getItemImageUrl(currentSeasonItem.data.Id, "Backdrop", {
|
||||
tag: currentSeasonItem.data.BackdropImageTags[0],
|
||||
tag: currentSeasonItem.data.BackdropImageTags?.[0],
|
||||
}),
|
||||
currentSeasonItem.data.Id,
|
||||
currentSeasonItem.data.BackdropImageTags?.[0],
|
||||
);
|
||||
setBackdropImageLoaded(false);
|
||||
} else if (item.isSuccess && item.data?.BackdropImageTags?.length > 0) {
|
||||
sessionStorage.setItem(
|
||||
`backdrop-${item.data?.Id}`,
|
||||
api.getItemImageUrl(item.data.Id, "Backdrop", {
|
||||
tag: item.data.BackdropImageTags[0],
|
||||
tag: item.data.BackdropImageTags?.[0],
|
||||
}),
|
||||
);
|
||||
sessionStorage.setItem(
|
||||
`backdrop-${item.data?.Id}-key`,
|
||||
currentSeasonItem.data.BackdropImageTags[0],
|
||||
item.data?.BackdropImageTags?.[0],
|
||||
);
|
||||
if (backdropImage.key !== item.data?.BackdropImageTags?.[0]) {
|
||||
setBackdropImageLoaded(false); // Reset Backdrop image load status if previous image is diff then new image
|
||||
}
|
||||
setBackdropImage({
|
||||
url: api.getItemImageUrl(item.data?.Id, "Backdrop", {
|
||||
tag: item.data?.BackdropImageTags[0],
|
||||
tag: item.data?.BackdropImageTags?.[0],
|
||||
}),
|
||||
key: item.data?.BackdropImageTags[0],
|
||||
key: item.data?.BackdropImageTags?.[0],
|
||||
});
|
||||
setBackdrop(
|
||||
api.getItemImageUrl(item.data.Id, "Backdrop", {
|
||||
tag: item.data.BackdropImageTags[0],
|
||||
tag: item.data.BackdropImageTags?.[0],
|
||||
}),
|
||||
item.data.Id,
|
||||
item.data.BackdropImageTags?.[0],
|
||||
);
|
||||
setBackdropImageLoaded(false);
|
||||
// setBackdropImageLoaded(false);
|
||||
}
|
||||
}, [currentSeasonItem.dataUpdatedAt]);
|
||||
|
||||
@@ -386,6 +389,7 @@ function SeriesTitlePage() {
|
||||
opacity: 0,
|
||||
}}
|
||||
onLoad={() => {
|
||||
console.info("Image Loaded");
|
||||
setBackdropImageLoaded(true);
|
||||
}}
|
||||
animate={{
|
||||
@@ -589,7 +593,7 @@ function SeriesTitlePage() {
|
||||
itemUserData={item.data.UserData}
|
||||
currentAudioTrack={0}
|
||||
currentVideoTrack={0}
|
||||
currentSubTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
userId={user.data.Id}
|
||||
buttonProps={{
|
||||
fullWidth: true,
|
||||
@@ -1021,7 +1025,7 @@ function SeriesTitlePage() {
|
||||
userId={user.data.Id}
|
||||
currentAudioTrack={0}
|
||||
currentVideoTrack={0}
|
||||
currentSubTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
size="medium"
|
||||
buttonProps={{
|
||||
color: "white",
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { MediaStream } from "@jellyfin/sdk/lib/generated-client";
|
||||
import type subtitlePlaybackInfo from "../types/subtitlePlaybackInfo";
|
||||
|
||||
export default function getSubtitle(
|
||||
track: number | "nosub",
|
||||
mediaStreams: MediaStream[] | undefined | null,
|
||||
): subtitlePlaybackInfo {
|
||||
const availableSubtitles = mediaStreams?.filter(
|
||||
(stream) => stream.Type === "Subtitle",
|
||||
);
|
||||
if (availableSubtitles?.length === 0)
|
||||
return { track: -2, enable: false, format: "vtt" };
|
||||
if (track === "nosub") return { track: -1, enable: false, format: "vtt" };
|
||||
const requiredSubtitle = availableSubtitles?.filter(
|
||||
(stream) => stream.Index === track,
|
||||
);
|
||||
const url = requiredSubtitle?.[0]?.DeliveryUrl;
|
||||
console.log(track);
|
||||
if (track === "nosub") {
|
||||
return {
|
||||
track,
|
||||
enable: false,
|
||||
format: null,
|
||||
allTracks: availableSubtitles,
|
||||
url: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
track,
|
||||
enable: true,
|
||||
format: requiredSubtitle?.[0]?.Codec,
|
||||
allTracks: availableSubtitles,
|
||||
url,
|
||||
};
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import type {
|
||||
BaseItemDto,
|
||||
BaseItemKind,
|
||||
MediaProtocol,
|
||||
MediaStream,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { create } from "zustand";
|
||||
import playbackProfile from "../playback-profiles";
|
||||
import type subtitlePlaybackInfo from "../types/subtitlePlaybackInfo";
|
||||
import { useApiInContext } from "./api";
|
||||
import { playAudio } from "./audioPlayback";
|
||||
import useQueue, { setQueue, setTrackIndex } from "./queue";
|
||||
@@ -20,9 +22,14 @@ type PlaybackStore = {
|
||||
container: string;
|
||||
availableSubtitleTracks: MediaStream[];
|
||||
id: string | undefined;
|
||||
subtitle: subtitlePlaybackInfo;
|
||||
isDirectPlay: boolean;
|
||||
isDirectStream: boolean;
|
||||
isTranscode: boolean;
|
||||
playbackProtocol: MediaProtocol;
|
||||
};
|
||||
enableSubtitle: boolean;
|
||||
hlsStream: string;
|
||||
playbackStream: string;
|
||||
userId: string;
|
||||
startPosition: number;
|
||||
itemDuration: number;
|
||||
@@ -40,9 +47,20 @@ export const usePlaybackStore = create<PlaybackStore>(() => ({
|
||||
container: "",
|
||||
availableSubtitleTracks: [],
|
||||
id: undefined,
|
||||
subtitle: {
|
||||
enable: false,
|
||||
track: undefined!,
|
||||
format: "ass",
|
||||
allTracks: undefined,
|
||||
url: undefined,
|
||||
},
|
||||
isDirectPlay: true,
|
||||
isDirectStream: false,
|
||||
isTranscode: false,
|
||||
playbackProtocol: undefined!,
|
||||
},
|
||||
enableSubtitle: true,
|
||||
hlsStream: "",
|
||||
playbackStream: "",
|
||||
userId: "",
|
||||
startPosition: 0,
|
||||
itemDuration: 0,
|
||||
@@ -58,7 +76,7 @@ export const playItem = (
|
||||
subtitleTrack,
|
||||
container,
|
||||
enableSubtitle,
|
||||
hlsStream,
|
||||
playbackStream,
|
||||
userId,
|
||||
startPosition,
|
||||
itemDuration,
|
||||
@@ -68,6 +86,11 @@ export const playItem = (
|
||||
availableSubtitleTracks,
|
||||
mediaSourceId,
|
||||
playsessionId,
|
||||
subtitle,
|
||||
isDirectPlay,
|
||||
isDirectStream,
|
||||
isTranscode,
|
||||
playbackProtocol,
|
||||
) => {
|
||||
console.log({
|
||||
itemName,
|
||||
@@ -79,9 +102,10 @@ export const playItem = (
|
||||
container,
|
||||
availableSubtitleTracks,
|
||||
id: mediaSourceId,
|
||||
subtitle,
|
||||
},
|
||||
enableSubtitle,
|
||||
hlsStream,
|
||||
playbackStream,
|
||||
userId,
|
||||
startPosition,
|
||||
itemDuration,
|
||||
@@ -98,9 +122,14 @@ export const playItem = (
|
||||
container,
|
||||
availableSubtitleTracks,
|
||||
id: mediaSourceId,
|
||||
subtitle,
|
||||
isDirectPlay,
|
||||
isDirectStream,
|
||||
isTranscode,
|
||||
playbackProtocol,
|
||||
},
|
||||
enableSubtitle,
|
||||
hlsStream,
|
||||
playbackStream,
|
||||
userId,
|
||||
startPosition,
|
||||
itemDuration,
|
||||
@@ -234,3 +263,21 @@ export const usePlaybackDataLoadStore = create<PlaybackDataLoadState>(
|
||||
})),
|
||||
}),
|
||||
);
|
||||
|
||||
export const changeSubtitleTrack = (
|
||||
trackIndex: number,
|
||||
allTracks: MediaStream[],
|
||||
) => {
|
||||
const requiredSubtitle = allTracks.filter(
|
||||
(track) => track.Index === trackIndex,
|
||||
);
|
||||
const prevState = usePlaybackStore.getState();
|
||||
prevState.mediaSource.subtitle = {
|
||||
url: requiredSubtitle?.[0].DeliveryUrl,
|
||||
track: trackIndex,
|
||||
format: requiredSubtitle?.[0].Codec,
|
||||
allTracks,
|
||||
enable: true,
|
||||
};
|
||||
usePlaybackStore.setState(prevState);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { MediaStream } from "@jellyfin/sdk/lib/generated-client";
|
||||
|
||||
export default interface subtitlePlaybackInfo {
|
||||
enable: boolean;
|
||||
track: number;
|
||||
format: "vtt" | "ass" | "ssa" | "subrip";
|
||||
allTracks: undefined | MediaStream[];
|
||||
url: string;
|
||||
}
|
||||
Reference in new issue
Block a user