feat: add intro-skipper
This commit is contained in:
10 files changed
+166
-45
No files matched your search
@@ -36,7 +36,8 @@ 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 { axiosClient, useApiInContext } from "@/utils/store/api";
|
||||
import type IntroMediaInfo from "@/utils/types/introMediaInfo";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import type { SxProps } from "@mui/material";
|
||||
import type { AxiosResponse } from "axios";
|
||||
@@ -95,6 +96,7 @@ const PlayButton = ({
|
||||
setPlaybackDataLoading(true);
|
||||
let result: undefined | AxiosResponse<BaseItemDtoQueryResult, any>;
|
||||
let mediaSource: undefined | AxiosResponse<PlaybackInfoResponse, any>;
|
||||
let introInfo: undefined | AxiosResponse<IntroMediaInfo, any>;
|
||||
if (playlistItem) {
|
||||
result = await getPlaylistsApi(api).getPlaylistItems({
|
||||
userId: userId,
|
||||
@@ -123,6 +125,20 @@ const PlayButton = ({
|
||||
DeviceProfile: playbackProfile,
|
||||
},
|
||||
});
|
||||
try {
|
||||
introInfo = (
|
||||
await axiosClient.get(
|
||||
`${api.basePath}/Episode/${result.data.Items?.[0]?.Id}/IntroTimestamps`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `MediaBrowser Token=${api.accessToken}`,
|
||||
},
|
||||
},
|
||||
)
|
||||
)?.data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
result = await getTvShowsApi(api).getEpisodes({
|
||||
@@ -144,6 +160,20 @@ const PlayButton = ({
|
||||
DeviceProfile: playbackProfile,
|
||||
},
|
||||
});
|
||||
try {
|
||||
introInfo = (
|
||||
await axiosClient.get(
|
||||
`${api.basePath}/Episode/${result.data.Items?.[0]?.Id}/IntroTimestamps`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `MediaBrowser Token=${api.accessToken}`,
|
||||
},
|
||||
},
|
||||
)
|
||||
)?.data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
result = await getPlaylistsApi(api).getPlaylistItems({
|
||||
@@ -204,7 +234,7 @@ const PlayButton = ({
|
||||
break;
|
||||
}
|
||||
}
|
||||
return { item: result?.data, mediaSource: mediaSource?.data };
|
||||
return { item: result?.data, mediaSource: mediaSource?.data, introInfo };
|
||||
},
|
||||
onSuccess: (result: PlayResult | null) => {
|
||||
if (trackIndex) {
|
||||
@@ -255,7 +285,7 @@ const PlayButton = ({
|
||||
) {
|
||||
playbackUrl = `${api.basePath}${result.mediaSource.MediaSources[0].TranscodingUrl}`;
|
||||
}
|
||||
|
||||
|
||||
playItem(
|
||||
itemName,
|
||||
episodeTitle,
|
||||
@@ -272,6 +302,7 @@ const PlayButton = ({
|
||||
result?.mediaSource.MediaSources?.[0]?.Id,
|
||||
result?.mediaSource.PlaySessionId,
|
||||
subtitle,
|
||||
result?.introInfo,
|
||||
);
|
||||
navigate({ to: "/player" });
|
||||
}
|
||||
@@ -374,7 +405,7 @@ const PlayButton = ({
|
||||
color="white"
|
||||
/>
|
||||
</Button>
|
||||
{itemUserData.PlaybackPositionTicks && (
|
||||
{itemUserData.PlaybackPositionTicks > 0 && (
|
||||
<Typography
|
||||
sx={{
|
||||
opacity: 0.8,
|
||||
@@ -396,18 +427,3 @@ const PlayButton = ({
|
||||
};
|
||||
|
||||
export default PlayButton;
|
||||
|
||||
PlayButton.propTypes = {
|
||||
itemId: PropTypes.string,
|
||||
itemUserData: PropTypes.object,
|
||||
userId: PropTypes.string,
|
||||
itemType: PropTypes.string,
|
||||
currentAudioTrack: PropTypes.number,
|
||||
currentSubTrack: PropTypes.number,
|
||||
currentVideoTrack: PropTypes.number,
|
||||
className: PropTypes.string,
|
||||
sx: PropTypes.any,
|
||||
iconProps: PropTypes.any,
|
||||
buttonProps: PropTypes.any,
|
||||
iconOnly: PropTypes.bool,
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
import { getSetting, setSetting } from "@/utils/storage/settings";
|
||||
import { FormControlLabel, Switch, Typography } from "@mui/material";
|
||||
import React, { useState } from "react";
|
||||
|
||||
const SettingOption = ({
|
||||
setting,
|
||||
}: { setting: { key: string; name: string; description: string } }) => {
|
||||
const [settingVal, setSettingVal] = useState(
|
||||
async () => (await getSetting(setting.key)) ?? false,
|
||||
);
|
||||
return (
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
color="primary"
|
||||
checked={settingVal}
|
||||
onChange={(e) => {
|
||||
setSetting(setting.key, e.target.checked);
|
||||
setSettingVal(e.target.checked);
|
||||
}}
|
||||
name={setting.name}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<div className="settings-option-info">
|
||||
<Typography variant="subtitle1" fontWeight={400}>
|
||||
{setting.name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
className="settings-option-info-caption"
|
||||
>
|
||||
{setting.description}
|
||||
</Typography>
|
||||
</div>
|
||||
}
|
||||
labelPlacement="start"
|
||||
className="settings-option"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingOption;
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
setDefaultServer,
|
||||
setServer,
|
||||
} from "@/utils/storage/servers";
|
||||
import { allSettings, getSetting, setSetting } from "@/utils/storage/settings";
|
||||
import { delUser } from "@/utils/storage/user";
|
||||
import type { RecommendedServerInfo } from "@jellyfin/sdk";
|
||||
import { LoadingButton } from "@mui/lab";
|
||||
@@ -49,6 +50,7 @@ import { useNavigate, useRouteContext } from "@tanstack/react-router";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { type Update, check } from "@tauri-apps/plugin-updater";
|
||||
import { useSnackbar } from "notistack";
|
||||
import SettingOption from "../settingOption";
|
||||
|
||||
const motionConfig = {
|
||||
initial: {
|
||||
@@ -261,27 +263,8 @@ const Settings = () => {
|
||||
{/* General */}
|
||||
{tabValue === 1 && (
|
||||
<div className="settings-container">
|
||||
{Array.from(new Array(10)).map((i) => (
|
||||
<FormControlLabel
|
||||
key={i}
|
||||
value="start"
|
||||
control={<Switch color="primary" />}
|
||||
label={
|
||||
<div className="settings-option-info">
|
||||
<Typography variant="subtitle1">
|
||||
Some dummy setting
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
className="settings-option-info-caption"
|
||||
>
|
||||
this a test
|
||||
</Typography>
|
||||
</div>
|
||||
}
|
||||
labelPlacement="start"
|
||||
className="settings-option"
|
||||
/>
|
||||
{allSettings.general.map((setting) => (
|
||||
<SettingOption key={setting.key} setting={setting} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import React, { type ChangeEventHandler } from "react";
|
||||
import React, { MouseEventHandler, type ChangeEventHandler } from "react";
|
||||
import { useLayoutEffect, useMemo } from "react";
|
||||
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
@@ -27,7 +27,7 @@ import { AnimatePresence, motion } from "framer-motion";
|
||||
|
||||
import { setBackdrop } from "@/utils/store/backdrop";
|
||||
|
||||
import { TextField } from "@mui/material";
|
||||
import { Button, 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";
|
||||
@@ -80,6 +80,7 @@ function VideoPlayer() {
|
||||
episodeTitle,
|
||||
mediaSource,
|
||||
playsessionId,
|
||||
introInfo,
|
||||
] = usePlaybackStore((state) => [
|
||||
state.playbackStream,
|
||||
state.item,
|
||||
@@ -89,6 +90,7 @@ function VideoPlayer() {
|
||||
state.episodeTitle,
|
||||
state.mediaSource,
|
||||
state.playsessionId,
|
||||
state.intro,
|
||||
]);
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -277,6 +279,19 @@ function VideoPlayer() {
|
||||
}
|
||||
}, [mediaSource.subtitle.track, player.current?.getInternalPlayer()]);
|
||||
|
||||
const showSkipIntroButton = useMemo(() => {
|
||||
if (
|
||||
ticksToSec(progress) >= introInfo?.ShowSkipPromptAt &&
|
||||
ticksToSec(progress) < introInfo?.HideSkipPromptAt
|
||||
)
|
||||
return true;
|
||||
return false;
|
||||
}, [progress]);
|
||||
|
||||
const handleSkipIntro = useCallback(() => {
|
||||
player.current?.seekTo(introInfo?.IntroEnd);
|
||||
}, [item?.Id]);
|
||||
|
||||
return (
|
||||
<div className="video-player">
|
||||
<AnimatePresence>
|
||||
@@ -303,6 +318,22 @@ function VideoPlayer() {
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
{showSkipIntroButton && (
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
color="white"
|
||||
style={{
|
||||
position: "absolute",
|
||||
bottom: "18vh",
|
||||
right: "2em",
|
||||
zIndex: 10000,
|
||||
}}
|
||||
onClick={handleSkipIntro}
|
||||
>
|
||||
Skip Intro
|
||||
</Button>
|
||||
)}
|
||||
<motion.div
|
||||
className={
|
||||
hoveringOsd || !playing || isSeeking
|
||||
|
||||
@@ -1020,7 +1020,7 @@ function SeriesTitlePage() {
|
||||
<PlayButton
|
||||
item={episode}
|
||||
itemId={episode.Id}
|
||||
itemType="Episode"
|
||||
itemType={BaseItemKind.Episode}
|
||||
itemUserData={episode.UserData}
|
||||
userId={user.data.Id}
|
||||
currentAudioTrack={0}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Store } from "@tauri-apps/plugin-store";
|
||||
|
||||
const SettingsStore = new Store(".settings.dat");
|
||||
|
||||
/**
|
||||
* settingKey should be of type:
|
||||
* 'settingDomain.settingKeyName'
|
||||
*/
|
||||
|
||||
export const setSetting = async (settingKey: string, value: boolean) => {
|
||||
await SettingsStore.set(settingKey, value);
|
||||
await SettingsStore.save();
|
||||
};
|
||||
|
||||
export const getSetting = async (settingKey: string) => {
|
||||
const value = await SettingsStore.get(settingKey);
|
||||
console.log(`${settingKey} - ${value}`);
|
||||
if (value) return value;
|
||||
return false;
|
||||
};
|
||||
|
||||
export const allSettings = {
|
||||
general: [
|
||||
{
|
||||
key: "general.enable_skip_intro_outro",
|
||||
name: "Enable Intro-Skipper plugin",
|
||||
description:
|
||||
"Shows a skip button for Intros and End Credit scenes in an episode. Note: this requires jumoog/intro-skipper plugin to be installed on server",
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,12 +1,11 @@
|
||||
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 IntroMediaInfo from "../types/introMediaInfo";
|
||||
import type subtitlePlaybackInfo from "../types/subtitlePlaybackInfo";
|
||||
import { useApiInContext } from "./api";
|
||||
import { playAudio } from "./audioPlayback";
|
||||
@@ -28,6 +27,7 @@ type PlaybackStore = {
|
||||
itemDuration: number;
|
||||
item: BaseItemDto | null;
|
||||
playsessionId: string | undefined | null;
|
||||
intro: IntroMediaInfo | undefined;
|
||||
};
|
||||
|
||||
export const usePlaybackStore = create<PlaybackStore>(() => ({
|
||||
@@ -53,6 +53,7 @@ export const usePlaybackStore = create<PlaybackStore>(() => ({
|
||||
itemDuration: 0,
|
||||
item: null,
|
||||
playsessionId: "",
|
||||
intro: undefined,
|
||||
}));
|
||||
|
||||
export const playItem = (
|
||||
@@ -71,6 +72,7 @@ export const playItem = (
|
||||
mediaSourceId: string | undefined | null,
|
||||
playsessionId: string | undefined | null,
|
||||
subtitle: subtitlePlaybackInfo,
|
||||
intro: IntroMediaInfo | undefined,
|
||||
) => {
|
||||
console.log({
|
||||
itemName,
|
||||
@@ -88,6 +90,7 @@ export const playItem = (
|
||||
itemDuration,
|
||||
item,
|
||||
playsessionId,
|
||||
intro,
|
||||
});
|
||||
usePlaybackStore.setState({
|
||||
itemName,
|
||||
@@ -105,6 +108,7 @@ export const playItem = (
|
||||
itemDuration,
|
||||
item,
|
||||
playsessionId,
|
||||
intro,
|
||||
});
|
||||
setQueue(queue, queueItemIndex);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
type IntroMediaInfo = {
|
||||
EpisodeId: string;
|
||||
Valid: true;
|
||||
IntroStart: number;
|
||||
IntroEnd: number;
|
||||
ShowSkipPromptAt: number;
|
||||
HideSkipPromptAt: number;
|
||||
};
|
||||
|
||||
export default IntroMediaInfo
|
||||
@@ -2,10 +2,12 @@ import type {
|
||||
BaseItemDtoQueryResult,
|
||||
PlaybackInfoResponse,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import type IntroMediaInfo from "./introMediaInfo";
|
||||
|
||||
interface PlayResult {
|
||||
item: BaseItemDtoQueryResult;
|
||||
mediaSource: PlaybackInfoResponse;
|
||||
introInfo: IntroMediaInfo | undefined;
|
||||
}
|
||||
|
||||
export default PlayResult;
|
||||
Reference in new issue
Block a user