fix: episode and series not playing if episode is not present in nextUp and continueWatching
This commit is contained in:
6 files changed
+66
-40
No files matched your search
@@ -20,7 +20,7 @@ export default function LikeButton({
|
|||||||
isFavorite: boolean | undefined;
|
isFavorite: boolean | undefined;
|
||||||
queryKey: string[] | undefined;
|
queryKey: string[] | undefined;
|
||||||
userId: string | undefined;
|
userId: string | undefined;
|
||||||
itemName: string | undefined;
|
itemName?: string | null;
|
||||||
}) {
|
}) {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default function MarkPlayedButton({
|
|||||||
isPlayed?: boolean;
|
isPlayed?: boolean;
|
||||||
queryKey?: string[];
|
queryKey?: string[];
|
||||||
userId?: string;
|
userId?: string;
|
||||||
itemName?: string;
|
itemName?: string | null;
|
||||||
}) {
|
}) {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,15 @@ const PlayButton = ({
|
|||||||
seasonId: item.SeasonId,
|
seasonId: item.SeasonId,
|
||||||
// startItemId: item.Id,
|
// startItemId: item.Id,
|
||||||
});
|
});
|
||||||
index = result.data.Items?.map((i) => i.Id).indexOf(item.Id) ?? 0;
|
if (
|
||||||
|
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) &&
|
||||||
|
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) >
|
||||||
|
-1
|
||||||
|
) {
|
||||||
|
index = result.data.Items?.map((i) => i.Id).indexOf(
|
||||||
|
currentEpisodeId,
|
||||||
|
);
|
||||||
|
}
|
||||||
mediaSource = await getMediaInfoApi(api).getPostedPlaybackInfo({
|
mediaSource = await getMediaInfoApi(api).getPostedPlaybackInfo({
|
||||||
audioStreamIndex: currentAudioTrack,
|
audioStreamIndex: currentAudioTrack,
|
||||||
subtitleStreamIndex:
|
subtitleStreamIndex:
|
||||||
@@ -180,11 +188,14 @@ const PlayButton = ({
|
|||||||
enableUserData: true,
|
enableUserData: true,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
});
|
});
|
||||||
index =
|
if (
|
||||||
result.data.Items?.map((i) => i.Id).indexOf(
|
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) &&
|
||||||
currentEpisodeId ?? "",
|
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) > -1
|
||||||
) ?? 0;
|
) {
|
||||||
|
index = result.data.Items?.map((i) => i.Id).indexOf(
|
||||||
|
currentEpisodeId,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
result.data.Items?.[index]?.Id &&
|
result.data.Items?.[index]?.Id &&
|
||||||
result.data.Items?.[index].MediaSources?.[0]?.Id
|
result.data.Items?.[index].MediaSources?.[0]?.Id
|
||||||
@@ -475,7 +486,7 @@ const PlayButton = ({
|
|||||||
if (!item.Id) {
|
if (!item.Id) {
|
||||||
throw new Error("Item ID is not available");
|
throw new Error("Item ID is not available");
|
||||||
}
|
}
|
||||||
let data: BaseItemDtoQueryResult | undefined;
|
let data: BaseItemDtoQueryResult | null = null;
|
||||||
const continueWatching = await getItemsApi(api).getResumeItems({
|
const continueWatching = await getItemsApi(api).getResumeItems({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
@@ -493,10 +504,12 @@ const PlayButton = ({
|
|||||||
data = continueWatching.data;
|
data = continueWatching.data;
|
||||||
} else if ((nextUp.data.Items?.length ?? 0) > 0) {
|
} else if ((nextUp.data.Items?.length ?? 0) > 0) {
|
||||||
data = nextUp.data;
|
data = nextUp.data;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
enabled: itemType === BaseItemKind.Series,
|
// enabled: itemType === BaseItemKind.Series,
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -531,7 +544,7 @@ const PlayButton = ({
|
|||||||
color="white"
|
color="white"
|
||||||
size={size}
|
size={size}
|
||||||
>
|
>
|
||||||
Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber}E
|
Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber ?? 1}E
|
||||||
{currentEpisode.data?.Items?.[0]?.IndexNumber ?? 1}
|
{currentEpisode.data?.Items?.[0]?.IndexNumber ?? 1}
|
||||||
<MemoizedLinearProgress
|
<MemoizedLinearProgress
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { motion } from "framer-motion";
|
|||||||
|
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import Chip from "@mui/material/Chip";
|
import Chip from "@mui/material/Chip";
|
||||||
import Paper from "@mui/material/Paper";
|
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
@@ -17,6 +16,7 @@ import { getTypeIcon } from "../utils/iconsCollection";
|
|||||||
|
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
import { useCarouselStore } from "@/utils/store/carousel";
|
import { useCarouselStore } from "@/utils/store/carousel";
|
||||||
|
import { useCentralStore } from "@/utils/store/central";
|
||||||
import {
|
import {
|
||||||
type BaseItemDto,
|
type BaseItemDto,
|
||||||
BaseItemKind,
|
BaseItemKind,
|
||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
import LikeButton from "../buttons/likeButton";
|
import LikeButton from "../buttons/likeButton";
|
||||||
import MarkPlayedButton from "../buttons/markPlayedButton";
|
import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||||
import PlayButton from "../buttons/playButton";
|
import PlayButton from "../buttons/playButton";
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
|
||||||
|
|
||||||
const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
@@ -74,20 +73,20 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
className="hero-carousel-background-image"
|
className="hero-carousel-background-image"
|
||||||
src={
|
src={
|
||||||
item.ParentBackdropItemId
|
item.ParentBackdropItemId
|
||||||
? `${api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
? `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
||||||
: `${api.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
: `${api?.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
||||||
}
|
}
|
||||||
style={{
|
style={{
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
}}
|
}}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.target.style.opacity = 1;
|
e.currentTarget.style.opacity = "1";
|
||||||
}}
|
}}
|
||||||
loading="eager"
|
loading="eager"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="hero-carousel-background-icon-container">
|
<div className="hero-carousel-background-icon-container">
|
||||||
{getTypeIcon(item.Type)}
|
{getTypeIcon(item.Type ?? "Movie")}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -129,16 +128,16 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
item.Name
|
item.Name
|
||||||
) : (
|
) : (
|
||||||
<img
|
<img
|
||||||
alt={item.Name}
|
alt={item.Name ?? "Item"}
|
||||||
className="hero-carousel-text-logo"
|
className="hero-carousel-text-logo"
|
||||||
src={`${api.basePath}/Items/${item.Id}/Images/Logo?quality=90&tag=${item.ImageTags.Logo}`}
|
src={`${api?.basePath}/Items/${item.Id}/Images/Logo?quality=90&tag=${item.ImageTags.Logo}`}
|
||||||
style={{
|
style={{
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
transition: "opacity 0.2s",
|
transition: "opacity 0.2s",
|
||||||
objectFit: "contain",
|
objectFit: "contain",
|
||||||
}}
|
}}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.target.style.opacity = 1;
|
e.currentTarget.style.opacity = "1";
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -240,15 +239,21 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{item.RunTimeTicks && (
|
{item.RunTimeTicks ? (
|
||||||
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
||||||
{getRuntime(item.RunTimeTicks)}
|
{getRuntime(item.RunTimeTicks)}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
)}
|
)}
|
||||||
{item.RunTimeTicks && (
|
{item.RunTimeTicks ? (
|
||||||
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
||||||
{endsAt(item.RunTimeTicks - item.UserData.PlaybackPositionTicks)}
|
{endsAt(
|
||||||
|
item.RunTimeTicks - (item.UserData?.PlaybackPositionTicks ?? 0),
|
||||||
|
)}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
)}
|
)}
|
||||||
<Typography variant="subtitle2" style={{ opacity: 0.8 }}>
|
<Typography variant="subtitle2" style={{ opacity: 0.8 }}>
|
||||||
{item.Genres?.slice(0, 4).join(" / ")}
|
{item.Genres?.slice(0, 4).join(" / ")}
|
||||||
@@ -305,16 +310,14 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
>
|
>
|
||||||
<PlayButton
|
<PlayButton
|
||||||
item={item}
|
item={item}
|
||||||
itemId={item.Id}
|
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
itemType={item.Type}
|
itemType={item.Type ?? "Movie"}
|
||||||
currentAudioTrack={0}
|
currentAudioTrack={0}
|
||||||
currentSubTrack={0}
|
currentSubTrack={0}
|
||||||
currentVideoTrack={0}
|
currentVideoTrack={0}
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
size: "large",
|
size: "large",
|
||||||
}}
|
}}
|
||||||
itemUserData={item.UserData}
|
|
||||||
audio={
|
audio={
|
||||||
item.Type === BaseItemKind.MusicAlbum ||
|
item.Type === BaseItemKind.MusicAlbum ||
|
||||||
item.Type === BaseItemKind.Audio ||
|
item.Type === BaseItemKind.Audio ||
|
||||||
@@ -327,6 +330,7 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="large"
|
size="large"
|
||||||
|
//@ts-ignore
|
||||||
color="white"
|
color="white"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
endIcon={
|
endIcon={
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
|||||||
<AudioPlayer />
|
<AudioPlayer />
|
||||||
<Outlet />
|
<Outlet />
|
||||||
<ReactQueryDevtools />
|
<ReactQueryDevtools />
|
||||||
<TanStackRouterDevtools />
|
{/* <TanStackRouterDevtools /> */}
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|||||||
@@ -45,18 +45,20 @@ function Home() {
|
|||||||
const libraries = useQuery({
|
const libraries = useQuery({
|
||||||
queryKey: ["libraries"],
|
queryKey: ["libraries"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
if (!api) return;
|
||||||
const libs = await getUserViewsApi(api).getUserViews({
|
const libs = await getUserViewsApi(api).getUserViews({
|
||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
});
|
});
|
||||||
return libs.data;
|
return libs.data;
|
||||||
},
|
},
|
||||||
enabled: !!user?.Id && !!api.accessToken,
|
enabled: !!user?.Id && !!api?.accessToken,
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
const latestMedia = useQuery({
|
const latestMedia = useQuery({
|
||||||
queryKey: ["home", "latestMedia"],
|
queryKey: ["home", "latestMedia"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
if (!api) return;
|
||||||
const media = await getUserLibraryApi(api).getLatestMedia({
|
const media = await getUserLibraryApi(api).getLatestMedia({
|
||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
fields: [
|
fields: [
|
||||||
@@ -83,6 +85,7 @@ function Home() {
|
|||||||
const resumeItemsVideo = useQuery({
|
const resumeItemsVideo = useQuery({
|
||||||
queryKey: ["home", "resume", "video"],
|
queryKey: ["home", "resume", "video"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
if (!api) return;
|
||||||
const resumeItems = await getItemsApi(api).getResumeItems({
|
const resumeItems = await getItemsApi(api).getResumeItems({
|
||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@@ -99,6 +102,7 @@ function Home() {
|
|||||||
const resumeItemsAudio = useQuery({
|
const resumeItemsAudio = useQuery({
|
||||||
queryKey: ["home", "resume", "audio"],
|
queryKey: ["home", "resume", "audio"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
if (!api) return;
|
||||||
const resumeItems = await getItemsApi(api).getResumeItems({
|
const resumeItems = await getItemsApi(api).getResumeItems({
|
||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@@ -114,6 +118,7 @@ function Home() {
|
|||||||
const upNextItems = useQuery({
|
const upNextItems = useQuery({
|
||||||
queryKey: ["home", "upNext"],
|
queryKey: ["home", "upNext"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
if (!api) return;
|
||||||
const upNext = await getTvShowsApi(api).getNextUp({
|
const upNext = await getTvShowsApi(api).getNextUp({
|
||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
fields: [
|
fields: [
|
||||||
@@ -144,7 +149,7 @@ function Home() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (libraries.isSuccess) {
|
if (libraries.isSuccess) {
|
||||||
const latestMediaLibsTemp = libraries.data.Items?.reduce(
|
const latestMediaLibsTemp = libraries.data?.Items?.reduce(
|
||||||
(filteredItems: BaseItemDto[], currentItem) => {
|
(filteredItems: BaseItemDto[], currentItem) => {
|
||||||
if (currentItem.Type && !excludeTypes.has(currentItem.Type)) {
|
if (currentItem.Type && !excludeTypes.has(currentItem.Type)) {
|
||||||
filteredItems.push(currentItem);
|
filteredItems.push(currentItem);
|
||||||
@@ -174,11 +179,15 @@ function Home() {
|
|||||||
<Carousel
|
<Carousel
|
||||||
content={latestMedia.data}
|
content={latestMedia.data}
|
||||||
onChange={(now: number) => {
|
onChange={(now: number) => {
|
||||||
if (latestMedia.isSuccess && latestMedia.data.length > 0) {
|
if (
|
||||||
if (latestMedia.data[now]?.ParentBackdropImageTags) {
|
api &&
|
||||||
|
latestMedia.isSuccess &&
|
||||||
|
(latestMedia.data?.length ?? 0) > 0
|
||||||
|
) {
|
||||||
|
if (latestMedia.data?.[now]?.ParentBackdropImageTags) {
|
||||||
setBackdrop(
|
setBackdrop(
|
||||||
getImageUrlsApi(api).getItemImageUrlById(
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
latestMedia.data[now].Id,
|
latestMedia.data[now].Id ?? "",
|
||||||
"Backdrop",
|
"Backdrop",
|
||||||
{
|
{
|
||||||
tag: latestMedia.data[now]
|
tag: latestMedia.data[now]
|
||||||
@@ -191,14 +200,14 @@ function Home() {
|
|||||||
} else {
|
} else {
|
||||||
setBackdrop(
|
setBackdrop(
|
||||||
getImageUrlsApi(api).getItemImageUrlById(
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
latestMedia.data[now].Id,
|
latestMedia.data?.[now].Id ?? "",
|
||||||
"Backdrop",
|
"Backdrop",
|
||||||
{
|
{
|
||||||
tag: latestMedia.data[now].BackdropImageTags[0],
|
tag: latestMedia.data?.[now].BackdropImageTags?.[0],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
latestMedia.data[now]?.BackdropImageTags[0] ??
|
latestMedia.data?.[now]?.BackdropImageTags?.[0] ??
|
||||||
latestMedia.data[now].Id,
|
latestMedia.data?.[now].Id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +229,7 @@ function Home() {
|
|||||||
) : (
|
) : (
|
||||||
<CardScroller displayCards={4} title="Libraries">
|
<CardScroller displayCards={4} title="Libraries">
|
||||||
{libraries.status === "success" &&
|
{libraries.status === "success" &&
|
||||||
libraries.data.Items?.map((item) => {
|
libraries.data?.Items?.map((item) => {
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
@@ -253,7 +262,7 @@ function Home() {
|
|||||||
>
|
>
|
||||||
{upNextItems.isPending ? (
|
{upNextItems.isPending ? (
|
||||||
<CardsSkeleton />
|
<CardsSkeleton />
|
||||||
) : upNextItems.isSuccess && !upNextItems.data.TotalRecordCount ? (
|
) : upNextItems.isSuccess && !upNextItems.data?.TotalRecordCount ? (
|
||||||
<></>
|
<></>
|
||||||
) : (
|
) : (
|
||||||
<CardScroller displayCards={4} title="Up Next">
|
<CardScroller displayCards={4} title="Up Next">
|
||||||
@@ -310,7 +319,7 @@ function Home() {
|
|||||||
{resumeItemsVideo.isPending ? (
|
{resumeItemsVideo.isPending ? (
|
||||||
<CardsSkeleton />
|
<CardsSkeleton />
|
||||||
) : resumeItemsVideo.isSuccess &&
|
) : resumeItemsVideo.isSuccess &&
|
||||||
!resumeItemsVideo.data.TotalRecordCount ? (
|
!resumeItemsVideo.data?.TotalRecordCount ? (
|
||||||
<></>
|
<></>
|
||||||
) : (
|
) : (
|
||||||
<CardScroller displayCards={4} title="Continue Watching">
|
<CardScroller displayCards={4} title="Continue Watching">
|
||||||
@@ -363,7 +372,7 @@ function Home() {
|
|||||||
{resumeItemsAudio.isPending ? (
|
{resumeItemsAudio.isPending ? (
|
||||||
<CardsSkeleton />
|
<CardsSkeleton />
|
||||||
) : resumeItemsAudio.isSuccess &&
|
) : resumeItemsAudio.isSuccess &&
|
||||||
!resumeItemsAudio.data.TotalRecordCount ? (
|
!resumeItemsAudio.data?.TotalRecordCount ? (
|
||||||
<></>
|
<></>
|
||||||
) : (
|
) : (
|
||||||
<CardScroller displayCards={4} title="Continue Listening">
|
<CardScroller displayCards={4} title="Continue Listening">
|
||||||
|
|||||||
Reference in new issue
Block a user