refactor: support vtt and ass subtitles
This commit is contained in:
17 files changed
+726
-452
No files matched your search
+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",
|
||||
|
||||
Reference in new issue
Block a user