From 2d4b0d66b4f05e237e2a2bb4486ac5b6754d0bcb Mon Sep 17 00:00:00 2001 From: DavideSirico Date: Tue, 8 Jul 2025 17:54:11 +0200 Subject: [PATCH 1/3] fix: handle undefined redirect in validateSearch function --- src/routes/_api/login/manual.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/_api/login/manual.tsx b/src/routes/_api/login/manual.tsx index fff8fb0..b9c6d56 100644 --- a/src/routes/_api/login/manual.tsx +++ b/src/routes/_api/login/manual.tsx @@ -35,7 +35,7 @@ import { export const Route = createFileRoute("/_api/login/manual")({ component: UserLoginManual, validateSearch: (search): { redirect?: string } => { - return { redirect: String(search.redirect) }; + return { redirect: search.redirect ? String(search.redirect) : undefined }; }, }); From 65e5370dbf25dbb45be6774e5bc6b8be7c7a0e58 Mon Sep 17 00:00:00 2001 From: DavideSirico Date: Tue, 8 Jul 2025 17:54:28 +0200 Subject: [PATCH 2/3] feat: enhance PlayButton to fetch and display current episode data --- src/components/buttons/playButton.tsx | 153 ++++++++++++++++---------- 1 file changed, 95 insertions(+), 58 deletions(-) diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index 7cb2d2a..016afd6 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -629,6 +629,44 @@ const PlayButton = ({ e.stopPropagation(); itemQuery.mutate(currentEpisodeId); }; + const currentEpisode = useQuery({ + queryKey: ["playButton", "currentEpisode", item?.Id], + queryFn: async () => { + if (!api) { + throw new Error("API is not available"); + } + if (!userId) { + throw new Error("User ID is not available"); + } + if (!item.Id) { + throw new Error("Item ID is not available"); + } + let data: BaseItemDtoQueryResult | null = null; + const continueWatching = await getItemsApi(api).getResumeItems({ + userId: userId, + limit: 1, + mediaTypes: ["Video"], + parentId: item.Id, + enableUserData: true, + fields: [ItemFields.MediaStreams, ItemFields.MediaSources], + }); + const nextUp = await getTvShowsApi(api).getNextUp({ + userId: userId, + parentId: item.Id, + limit: 1, + }); + if ((continueWatching.data.Items?.length ?? 0) > 0) { + data = continueWatching.data; + } else if ((nextUp.data.Items?.length ?? 0) > 0) { + data = nextUp.data; + } else { + return null; + } + return data; + }, + // enabled: itemType === BaseItemKind.Series, + }); + if (iconOnly) { return ( //@ts-ignore @@ -636,11 +674,24 @@ const PlayButton = ({ color="primary" aria-label="Play" className={className} - onClick={(e) => - item.Type === "Episode" ? handleClick(e, item.Id) : handleClick(e) - } + onClick={(e) => { + if (item.Type === "Episode") { + handleClick(e, item.Id) + } else if (itemType === BaseItemKind.Series) { + handleClick(e, currentEpisode.data?.Items?.[0]?.Id) + } else { + handleClick(e) + } + }} sx={sx} size={size} + disabled={ + currentEpisode.isPending || + (itemType === BaseItemKind.Series && + (!currentEpisode.data || + !currentEpisode.data.Items || + currentEpisode.data.Items.length === 0)) + } {...buttonProps} >
{ - if (!api) { - throw new Error("API is not available"); - } - if (!userId) { - throw new Error("User ID is not available"); - } - if (!item.Id) { - throw new Error("Item ID is not available"); - } - let data: BaseItemDtoQueryResult | null = null; - const continueWatching = await getItemsApi(api).getResumeItems({ - userId: userId, - limit: 1, - mediaTypes: ["Video"], - parentId: item.Id, - enableUserData: true, - fields: [ItemFields.MediaStreams, ItemFields.MediaSources], - }); - const nextUp = await getTvShowsApi(api).getNextUp({ - userId: userId, - parentId: item.Id, - limit: 1, - }); - if ((continueWatching.data.Items?.length ?? 0) > 0) { - data = continueWatching.data; - } else if ((nextUp.data.Items?.length ?? 0) > 0) { - data = nextUp.data; - } else { - return null; - } - return data; - }, - // enabled: itemType === BaseItemKind.Series, - }); return (
handleClick(e, currentEpisode.data?.Items?.[0]?.Id)} + onClick={(e) => { + const episodeId = currentEpisode.data?.Items?.[0]?.Id; + if (episodeId) { + handleClick(e, episodeId); + } + }} startIcon={
- Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber ?? 1}E - {currentEpisode.data?.Items?.[0]?.IndexNumber ?? 1} - - (currentEpisode.data?.Items?.[0].UserData?.PlayedPercentage ?? - 100) && - (currentEpisode.data?.Items?.[0].UserData?.PlayedPercentage ?? - 0) > 0 - ? currentEpisode.data?.Items?.[0].UserData?.PlayedPercentage - : 0 - } - /> + {currentEpisode.isPending + ? "Loading..." + : !currentEpisode.data || + !currentEpisode.data.Items || + currentEpisode.data.Items.length === 0 + ? "No episodes to watch found" + : ( + <> + Watch S{currentEpisode.data.Items[0].ParentIndexNumber ?? 1}E + {currentEpisode.data.Items[0]?.IndexNumber ?? 1} + + (currentEpisode.data.Items[0].UserData?.PlayedPercentage ?? + 100) && + (currentEpisode.data.Items[0].UserData?.PlayedPercentage ?? + 0) > 0 + ? currentEpisode.data.Items[0].UserData?.PlayedPercentage + : 0 + } + /> + + ) + } - {(currentEpisode.data?.Items?.[0].UserData?.PlaybackPositionTicks ?? + {(currentEpisode.data?.Items?.[0]?.UserData?.PlaybackPositionTicks ?? 0) > 0 && ( {getRuntimeCompact( - (currentEpisode.data?.Items?.[0].RunTimeTicks ?? 0) - - (currentEpisode.data?.Items?.[0].UserData + (currentEpisode.data?.Items?.[0]?.RunTimeTicks ?? 0) - + (currentEpisode.data?.Items?.[0]?.UserData ?.PlaybackPositionTicks ?? 0), )}{" "} left From 37e898e4cf349bd68552a87fbda74b713feddbf7 Mon Sep 17 00:00:00 2001 From: DavideSirico Date: Wed, 9 Jul 2025 15:37:13 +0200 Subject: [PATCH 3/3] feat: add user language preference for subtitles and audio tracks in PlayButton --- src/components/buttons/playButton.tsx | 32 +++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index 016afd6..975d0a3 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -15,8 +15,8 @@ import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api"; import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api"; import { getPlaylistsApi } from "@jellyfin/sdk/lib/utils/api/playlists-api"; import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api"; +import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; -import { LoadingButton } from "@mui/lab"; import type { SxProps } from "@mui/material"; import Button, { type ButtonProps } from "@mui/material/Button"; import Fab from "@mui/material/Fab"; @@ -522,18 +522,36 @@ const PlayButton = ({ } // Subtitle + const userSubtitleLanguagePreference = (await getUserApi(api).getCurrentUser()).data.Configuration?.SubtitleLanguagePreference; + // Get all subtitle streams + const allSubtitles = result?.mediaSource?.MediaSources?.[0]?.MediaStreams?.filter( + (stream) => stream.Type === "Subtitle" + ); + // Find preferred subtitle based on user's language preference + const preferredSubtitle = + allSubtitles?.find(sub => sub.Language === userSubtitleLanguagePreference) + || null; + const subtitle = getSubtitle( - result.mediaSource.MediaSources?.[0].DefaultSubtitleStreamIndex ?? -1, + preferredSubtitle?.Index ?? result.mediaSource.MediaSources?.[0].DefaultSubtitleStreamIndex ?? -1, result?.mediaSource?.MediaSources?.[0]?.MediaStreams, ); // Audio + const userAudioLanguagePreference = (await getUserApi(api).getCurrentUser()).data.Configuration?.AudioLanguagePreference; + // Get all audio streams + const allAudioTracks = result.mediaSource.MediaSources?.[0].MediaStreams?.filter( + (value) => value.Type === "Audio", + ); + // Find preferred audio track based on user's language preference + const preferredAudioTrack = + allAudioTracks?.find(track => track.Language === userAudioLanguagePreference) + || allAudioTracks?.find(track => track.IsDefault) + || allAudioTracks?.[0]; + const audio = { - track: - result.mediaSource.MediaSources?.[0].DefaultAudioStreamIndex ?? 0, - allTracks: result.mediaSource.MediaSources?.[0].MediaStreams?.filter( - (value) => value.Type === "Audio", - ), + track: preferredAudioTrack?.Index ?? result.mediaSource.MediaSources?.[0].DefaultAudioStreamIndex ?? 0, + allTracks: allAudioTracks, }; // URL generation