From d077860fbc74671ae18dd98e1b71aae493d1faf6 Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Thu, 18 Jul 2024 21:30:02 +0530 Subject: [PATCH] feat: add intro-skipper --- README.md | 1 + src/components/buttons/playButton.tsx | 54 +++++++++++++++++--------- src/components/settingOption/index.tsx | 43 ++++++++++++++++++++ src/components/settings/index.tsx | 25 ++---------- src/routes/_api/player/index.tsx | 35 ++++++++++++++++- src/routes/_api/series/$id.tsx | 2 +- src/utils/storage/settings.ts | 31 +++++++++++++++ src/utils/store/playback.ts | 8 +++- src/utils/types/introMediaInfo.ts | 10 +++++ src/utils/types/playResult.ts | 2 + 10 files changed, 166 insertions(+), 45 deletions(-) create mode 100644 src/components/settingOption/index.tsx create mode 100644 src/utils/storage/settings.ts create mode 100644 src/utils/types/introMediaInfo.ts diff --git a/README.md b/README.md index 5ea8c74..4e07c2c 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ - Mediainfo recognition (DolbyVision, DolbyAtoms, Dts, Hdr10+, and more...) - Sort/Filter library items - Queue playback support +- Intro Skip button using [jumoog/Intro-Skipper](https://github.com/jumoog/intro-skipper) plugin ## 📷 Screenshots diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index 63de15a..bd48a86 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -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; let mediaSource: undefined | AxiosResponse; + let introInfo: undefined | AxiosResponse; 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" /> - {itemUserData.PlaybackPositionTicks && ( + {itemUserData.PlaybackPositionTicks > 0 && ( { + const [settingVal, setSettingVal] = useState( + async () => (await getSetting(setting.key)) ?? false, + ); + return ( + { + setSetting(setting.key, e.target.checked); + setSettingVal(e.target.checked); + }} + name={setting.name} + /> + } + label={ +
+ + {setting.name} + + + {setting.description} + +
+ } + labelPlacement="start" + className="settings-option" + /> + ); +}; + +export default SettingOption; \ No newline at end of file diff --git a/src/components/settings/index.tsx b/src/components/settings/index.tsx index 01b077d..a8fb8db 100644 --- a/src/components/settings/index.tsx +++ b/src/components/settings/index.tsx @@ -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 && (
- {Array.from(new Array(10)).map((i) => ( - } - label={ -
- - Some dummy setting - - - this a test - -
- } - labelPlacement="start" - className="settings-option" - /> + {allSettings.general.map((setting) => ( + ))}
)} diff --git a/src/routes/_api/player/index.tsx b/src/routes/_api/player/index.tsx index 8baaa39..416c0cc 100644 --- a/src/routes/_api/player/index.tsx +++ b/src/routes/_api/player/index.tsx @@ -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 (
@@ -303,6 +318,22 @@ function VideoPlayer() { )} + {showSkipIntroButton && ( + + )} { + 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", + }, + ], +}; \ No newline at end of file diff --git a/src/utils/store/playback.ts b/src/utils/store/playback.ts index 08e8999..69dce2d 100644 --- a/src/utils/store/playback.ts +++ b/src/utils/store/playback.ts @@ -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(() => ({ @@ -53,6 +53,7 @@ export const usePlaybackStore = create(() => ({ 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); }; diff --git a/src/utils/types/introMediaInfo.ts b/src/utils/types/introMediaInfo.ts new file mode 100644 index 0000000..a6cd7fd --- /dev/null +++ b/src/utils/types/introMediaInfo.ts @@ -0,0 +1,10 @@ +type IntroMediaInfo = { + EpisodeId: string; + Valid: true; + IntroStart: number; + IntroEnd: number; + ShowSkipPromptAt: number; + HideSkipPromptAt: number; +}; + +export default IntroMediaInfo \ No newline at end of file diff --git a/src/utils/types/playResult.ts b/src/utils/types/playResult.ts index eb0423c..4fb2484 100644 --- a/src/utils/types/playResult.ts +++ b/src/utils/types/playResult.ts @@ -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; \ No newline at end of file