fix: player throws error whenever settings panel is openned
This commit is contained in:
11 files changed
+113
-115
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Link, Typography } from "@mui/material";
|
||||
import { Link, Tooltip } from "@mui/material";
|
||||
import React, { memo } from "react";
|
||||
|
||||
import anidbIcon from "../../assets/icons/anidb.png";
|
||||
@@ -12,54 +12,49 @@ import tmdbIcon from "../../assets/icons/themoviedatabase.svg";
|
||||
import traktIcon from "../../assets/icons/trakt.svg";
|
||||
import tvMazeIcon from "../../assets/icons/tvmaze.png";
|
||||
|
||||
const knownIcons = [
|
||||
"imdb",
|
||||
"themoviedb",
|
||||
"trakt",
|
||||
"musicbrainz",
|
||||
"thetvdb",
|
||||
"anidb",
|
||||
"anilist",
|
||||
"tvmaze",
|
||||
"theaudiodb",
|
||||
"kitsu",
|
||||
/**
|
||||
* Provider icons keyed by the start of the normalized link name, so variants like
|
||||
* "TMDB"/"TheMovieDb", "TVDB"/"TheTVDB" or "MusicBrainz Artist" all match.
|
||||
*/
|
||||
const providerIcons: [prefixes: string[], icon: string][] = [
|
||||
[["imdb"], imdbIcon],
|
||||
[["tmdb", "themoviedb"], tmdbIcon],
|
||||
[["tvdb", "thetvdb"], tvDbIcon],
|
||||
[["trakt"], traktIcon],
|
||||
[["musicbrainz"], musicBrainzIcon],
|
||||
[["anidb"], anidbIcon],
|
||||
[["anilist"], anilistIcon],
|
||||
[["tvmaze"], tvMazeIcon],
|
||||
[["theaudiodb", "audiodb"], audioDBIcon],
|
||||
[["kitsu"], kitsuIcon],
|
||||
];
|
||||
|
||||
const getProviderIcon = (name: string) => {
|
||||
const normalized = name.toLocaleLowerCase().replace(/[^a-z0-9]/g, "");
|
||||
return providerIcons.find(([prefixes]) =>
|
||||
prefixes.some((prefix) => normalized.startsWith(prefix)),
|
||||
)?.[1];
|
||||
};
|
||||
|
||||
const IconLink = memo(({ name, url }: { name: string; url: string }) => {
|
||||
const icon = getProviderIcon(name);
|
||||
return (
|
||||
<Link target="_blank" href={url} className="item-detail-link">
|
||||
{name.toLocaleLowerCase() === "imdb" && <img src={imdbIcon} alt="IMDb" />}
|
||||
{name.toLocaleLowerCase() === "themoviedb" && (
|
||||
<img src={tmdbIcon} alt="TheMovieDb" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "trakt" && (
|
||||
<img src={traktIcon} alt="Trakt" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "musicbrainz" && (
|
||||
<img src={musicBrainzIcon} alt="MusicBrainz" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "thetvdb" && (
|
||||
<img src={tvDbIcon} alt="TheTVDB" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "anidb" && (
|
||||
<img src={anidbIcon} alt="AniDB" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "anilist" && (
|
||||
<img src={anilistIcon} alt="AniList" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "tvmaze" && (
|
||||
<img src={tvMazeIcon} alt="TVMaze" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "theaudiodb" && (
|
||||
<img src={audioDBIcon} alt="TheAudioDB" />
|
||||
)}
|
||||
{name.toLocaleLowerCase() === "kitsu" && (
|
||||
<img src={kitsuIcon} alt="Kitsu" />
|
||||
)}
|
||||
{!knownIcons.includes(name.toLocaleLowerCase()) && (
|
||||
<Typography>{name}</Typography>
|
||||
)}
|
||||
</Link>
|
||||
<Tooltip title={name}>
|
||||
<Link
|
||||
target="_blank"
|
||||
href={url}
|
||||
className="item-detail-link"
|
||||
aria-label={name}
|
||||
>
|
||||
{icon ? (
|
||||
<img src={icon} alt={name} />
|
||||
) : (
|
||||
<span className="material-symbols-rounded item-detail-link-generic">
|
||||
link
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
</Tooltip>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -208,6 +208,16 @@
|
||||
filter: brightness(0.5);
|
||||
transition: filter $transition-time-default;
|
||||
}
|
||||
&-generic {
|
||||
display: block;
|
||||
font-size: 2em !important;
|
||||
color: white;
|
||||
opacity: 0.5;
|
||||
transition: opacity $transition-time-default;
|
||||
}
|
||||
&:hover > &-generic {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.item {
|
||||
|
||||
@@ -31,15 +31,16 @@ export const ErrorNotice = ({ error }: { error?: Error }) => {
|
||||
</div>
|
||||
<Typography
|
||||
variant="h3"
|
||||
color="white"
|
||||
sx={{
|
||||
color: "white",
|
||||
fontWeight: 300,
|
||||
}}
|
||||
>
|
||||
Something went wrong.
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h5"
|
||||
variant="body2"
|
||||
component="pre"
|
||||
style={{
|
||||
padding: "0.5em",
|
||||
background: "rgb(0 0 0 / 1)",
|
||||
@@ -49,15 +50,16 @@ export const ErrorNotice = ({ error }: { error?: Error }) => {
|
||||
maxHeight: "20em",
|
||||
overflow: "auto",
|
||||
marginTop: "1em",
|
||||
// opacity: 0.6,
|
||||
whiteSpace: "pre-wrap",
|
||||
}}
|
||||
color="gray"
|
||||
sx={{
|
||||
color: "grey.400",
|
||||
fontFamily: "JetBrains Mono Variable",
|
||||
fontWeight: 100,
|
||||
}}
|
||||
>
|
||||
{JSON.stringify(error?.stack)}
|
||||
{error
|
||||
? error.stack || `${error.name}: ${error.message}`
|
||||
: "Unknown error"}
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -190,7 +190,7 @@ const BubbleSlider = () => {
|
||||
const backgroundOffsetY = -(imageOffsetY * trickplayResolution?.Height);
|
||||
|
||||
const imgUrlParamsObject: Record<string, string> = {
|
||||
api_key: String(api?.accessToken),
|
||||
ApiKey: String(api?.accessToken),
|
||||
MediaSourceId: mediaSource.id ?? "",
|
||||
};
|
||||
const imgUrlParams = new URLSearchParams(imgUrlParamsObject).toString();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
MenuItem,
|
||||
MenuList,
|
||||
Popover,
|
||||
Switch,
|
||||
TextField,
|
||||
@@ -144,16 +145,18 @@ const VideoPlayerSettingsMenu = ({
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
<MenuItem onClick={toggleShowStatsForNerds}>
|
||||
<Typography
|
||||
sx={{
|
||||
flexGrow: 1,
|
||||
}}
|
||||
>
|
||||
Stats for Nerds
|
||||
</Typography>
|
||||
<Switch checked={showStatsForNerds} />
|
||||
</MenuItem>
|
||||
<MenuList disablePadding>
|
||||
<MenuItem onClick={toggleShowStatsForNerds}>
|
||||
<Typography
|
||||
sx={{
|
||||
flexGrow: 1,
|
||||
}}
|
||||
>
|
||||
Stats for Nerds
|
||||
</Typography>
|
||||
<Switch checked={showStatsForNerds} />
|
||||
</MenuItem>
|
||||
</MenuList>
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useQueries, useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import React, { useCallback, useMemo } from "react";
|
||||
|
||||
import "./home.scss";
|
||||
@@ -24,25 +24,11 @@ import Carousel from "@/components/carousel";
|
||||
import CircularPageLoadingAnimation from "@/components/circularPageLoadingAnimation";
|
||||
import { LatestMediaSection } from "@/components/layouts/homeSection/latestMediaSection";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import {
|
||||
getLatestItemsQueryOptions,
|
||||
getLibraryLatestQueryOptions,
|
||||
} from "@/utils/queries/items";
|
||||
import { getLatestItemsQueryOptions } from "@/utils/queries/items";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
const heroItemTypes = new Set<string>([
|
||||
BaseItemKind.Movie,
|
||||
BaseItemKind.Series,
|
||||
BaseItemKind.Episode,
|
||||
BaseItemKind.MusicAlbum,
|
||||
]);
|
||||
|
||||
const combineLibraryLatest = (
|
||||
results: { data?: BaseItemDto[] | null }[],
|
||||
): BaseItemDto[][] => results.map((result) => result.data ?? []);
|
||||
|
||||
export const Route = createFileRoute("/_api/home/")({
|
||||
component: Home,
|
||||
pendingComponent: () => <CircularPageLoadingAnimation />,
|
||||
@@ -141,28 +127,14 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
}
|
||||
}, [libraries.data?.Items?.length]);
|
||||
|
||||
// The per-library "latest" rows; shares cache entries with LatestMediaSection.
|
||||
const libraryLatest = useQueries({
|
||||
queries: (latestMediaLibs ?? []).map((lib) =>
|
||||
getLibraryLatestQueryOptions(api, user.Id, lib.Id),
|
||||
),
|
||||
combine: combineLibraryLatest,
|
||||
});
|
||||
|
||||
// Some servers return nothing for the global /Items/Latest query, so fall back to
|
||||
// interleaving the per-library results (each already newest-first).
|
||||
const heroItems = useMemo(() => {
|
||||
if (latestMedia.data?.length) return latestMedia.data;
|
||||
const items: BaseItemDto[] = [];
|
||||
const longest = Math.max(0, ...libraryLatest.map((list) => list.length));
|
||||
for (let index = 0; index < longest; index++) {
|
||||
for (const list of libraryLatest) {
|
||||
const item = list[index];
|
||||
if (item?.Type && heroItemTypes.has(item.Type)) items.push(item);
|
||||
}
|
||||
}
|
||||
return items.slice(0, 16);
|
||||
}, [latestMedia.data, libraryLatest]);
|
||||
const heroItems = useMemo(
|
||||
() =>
|
||||
latestMedia.data?.filter(
|
||||
(item) =>
|
||||
item.Type === BaseItemKind.Movie || item.Type === BaseItemKind.Series,
|
||||
) ?? [],
|
||||
[latestMedia.data],
|
||||
);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ function addSubtitleTrackToReactPlayer(
|
||||
|
||||
const track = document.createElement("track");
|
||||
const separator = subtitleTracks.url.includes("?") ? "&" : "?";
|
||||
const urlParams = apiKey ? `${separator}api_key=${apiKey}` : "";
|
||||
const urlParams = apiKey ? `${separator}ApiKey=${apiKey}` : "";
|
||||
track.src = `${baseUrl}${subtitleTracks.url}${urlParams}`;
|
||||
track.kind = "subtitles";
|
||||
track.srclang = reqSubTrack.Language ?? "en";
|
||||
@@ -458,7 +458,7 @@ export function VideoPlayer() {
|
||||
let pgsRenderer: PgsRenderer | undefined;
|
||||
const apiKey = api?.accessToken;
|
||||
const separator = mediaSource.subtitle.url?.includes("?") ? "&" : "?";
|
||||
const urlParams = apiKey ? `${separator}api_key=${apiKey}` : "";
|
||||
const urlParams = apiKey ? `${separator}ApiKey=${apiKey}` : "";
|
||||
|
||||
if (
|
||||
mediaSource.subtitle.format === "ass" ||
|
||||
|
||||
@@ -105,7 +105,7 @@ function PhotosPlayer() {
|
||||
|
||||
if (pathToSave) {
|
||||
download(
|
||||
`${api?.basePath}/Items/${currentPhoto?.Id}/Download?api_key=${api?.accessToken}`,
|
||||
`${api?.basePath}/Items/${currentPhoto?.Id}/Download?ApiKey=${api?.accessToken}`,
|
||||
pathToSave,
|
||||
);
|
||||
enqueueSnackbar("Image download queued.", { variant: "info" });
|
||||
@@ -122,7 +122,7 @@ function PhotosPlayer() {
|
||||
key={currentPhoto?.Id ?? "noPhoto"}
|
||||
src={
|
||||
currentPhoto
|
||||
? `${api?.basePath}/Items/${currentPhoto.Id}/Download?api_key=${api?.accessToken}`
|
||||
? `${api?.basePath}/Items/${currentPhoto.Id}/Download?ApiKey=${api?.accessToken}`
|
||||
: brokenImage
|
||||
}
|
||||
alt="Item"
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
|
||||
import {
|
||||
BaseItemKind,
|
||||
ItemFields,
|
||||
ItemSortBy,
|
||||
LocationType,
|
||||
SortOrder,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
|
||||
@@ -51,7 +57,7 @@ export const getLatestItemsQueryOptions = (
|
||||
if (!userId) {
|
||||
throw Error("User ID is not defined");
|
||||
}
|
||||
const media = await getLibraryApi(api).getLatestMedia({
|
||||
const request = {
|
||||
userId: userId,
|
||||
fields: [
|
||||
ItemFields.Overview,
|
||||
@@ -61,15 +67,25 @@ export const getLatestItemsQueryOptions = (
|
||||
ItemFields.MediaStreams,
|
||||
ItemFields.MediaSources,
|
||||
],
|
||||
includeItemTypes: [
|
||||
BaseItemKind.Movie,
|
||||
BaseItemKind.Series,
|
||||
BaseItemKind.MusicAlbum,
|
||||
],
|
||||
includeItemTypes: [BaseItemKind.Movie, BaseItemKind.Series],
|
||||
enableUserData: true,
|
||||
enableImages: true,
|
||||
};
|
||||
const media = await getLibraryApi(api).getLatestMedia(request);
|
||||
if (media.data.length > 0) {
|
||||
return media.data;
|
||||
}
|
||||
// Jellyfin 12 returns nothing for /Items/Latest without a parentId, so fall back
|
||||
// to the most recently added movies and series.
|
||||
const recent = await getLibraryApi(api).getItems({
|
||||
...request,
|
||||
recursive: true,
|
||||
sortBy: [ItemSortBy.DateCreated],
|
||||
sortOrder: [SortOrder.Descending],
|
||||
excludeLocationTypes: [LocationType.Virtual],
|
||||
limit: 16,
|
||||
});
|
||||
return media.data;
|
||||
return recent.data.Items ?? [];
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ export const generateAudioStreamUrl = (
|
||||
const urlOptions = {
|
||||
userId,
|
||||
deviceId,
|
||||
api_key,
|
||||
ApiKey: api_key,
|
||||
container: directPlayContainers,
|
||||
maxAudioChannels: transcodingProfile?.MaxAudioChannels,
|
||||
transcodingContainer: transcodingProfile?.Container,
|
||||
|
||||
@@ -788,7 +788,7 @@ export const initializePlayback = async (args: {
|
||||
tag: source.ETag,
|
||||
mediaSourceId: source.Id,
|
||||
deviceId: api.deviceInfo.id,
|
||||
api_key: api.accessToken,
|
||||
ApiKey: api.accessToken,
|
||||
};
|
||||
|
||||
let playMethod: PlayMethod = PlayMethod.Transcode;
|
||||
@@ -1045,7 +1045,7 @@ export const changeAudioTrack = async (trackIndex: number, api: Api) => {
|
||||
tag: mediaSource.MediaSources?.[0].ETag,
|
||||
mediaSourceId: mediaSource.MediaSources?.[0].Id,
|
||||
deviceId: api?.deviceInfo.id,
|
||||
api_key: api?.accessToken,
|
||||
ApiKey: api?.accessToken,
|
||||
};
|
||||
const urlParams = new URLSearchParams(urlOptions).toString();
|
||||
let playbackUrl = `${api?.basePath}/Videos/${mediaSource.MediaSources?.[0].Id}/stream.${mediaSource.MediaSources?.[0].Container}?${urlParams}`;
|
||||
|
||||
Reference in new issue
Block a user