diff --git a/package.json b/package.json index fa2368d..5ce3101 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "framer-motion": "^12.4.5", "immer": "^10.1.1", "jassub": "^1.7.17", + "libpgs": "^0.8.1", "lodash": "^4.17.21", "material-symbols": "^0.28.2", "million": "^3.1.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 20dc1ae..a991ef5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -122,6 +122,9 @@ importers: jassub: specifier: ^1.7.17 version: 1.7.17 + libpgs: + specifier: ^0.8.1 + version: 0.8.1 lodash: specifier: ^4.17.21 version: 4.17.21 @@ -2471,6 +2474,9 @@ packages: resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} engines: {node: '>=6'} + libpgs@0.8.1: + resolution: {integrity: sha512-Z8WCvHRYr37QjU8b2WqiJpCvnoojbYPtoE4FktwdI+m+b1QkNIKqrYQrlPKG1xvYyQWgV1j+16xjFOhun4nBUA==} + lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} @@ -5421,6 +5427,8 @@ snapshots: kleur@4.1.5: {} + libpgs@0.8.1: {} + lines-and-columns@1.2.4: {} load-script@1.0.0: {} diff --git a/src/routes/_api/player/index.tsx b/src/routes/_api/player/index.tsx index 13b8e3c..7d56350 100644 --- a/src/routes/_api/player/index.tsx +++ b/src/routes/_api/player/index.tsx @@ -54,6 +54,10 @@ import workerUrl from "jassub/dist/jassub-worker.js?url"; //@ts-ignore import wasmUrl from "jassub/dist/jassub-worker.wasm?url"; +import { PgsRenderer } from "libpgs"; +//@ts-ignore +import pgsWorkerUrl from "libpgs/dist/libpgs.worker.js?url"; + import PlayNextButton from "@/components/buttons/playNextButton"; import PlayPreviousButton from "@/components/buttons/playPreviousButtom"; import QueueButton from "@/components/buttons/queueButton"; @@ -148,7 +152,7 @@ function VideoPlayer() { const api = useApiInContext((s) => s.api); const { history } = useRouter(); const [hoveringOsd, setHoveringOsd] = useState(false); - const player = useRef(null); + const player = useRef(null); const user = useCentralStore((s) => s.currentUser); @@ -376,9 +380,11 @@ function VideoPlayer() { setIsReady(false); }, [item?.Id]); + // Manage Subtitle playback useEffect(() => { if (player.current?.getInternalPlayer() && mediaSource.subtitle.enable) { let jassubRenderer: JASSUB | undefined; + let pgsRenderer: PgsRenderer | undefined; if ( mediaSource.subtitle.format === "ass" || mediaSource.subtitle.format === "ssa" @@ -404,11 +410,20 @@ function VideoPlayer() { mediaSource.subtitle, api?.basePath ?? "", ); + } else if (mediaSource.subtitle.format === "PGSSUB") { + pgsRenderer = new PgsRenderer({ + workerUrl: pgsWorkerUrl, + video: player.current?.getInternalPlayer() as any, + subUrl: `${api?.basePath}${mediaSource.subtitle.url}`, + }); } return () => { if (jassubRenderer) { jassubRenderer.destroy(); } // Remove JASSUB renderer when track changes to fix duplicate renders + if (pgsRenderer) { + pgsRenderer.dispose(); + } }; } if ( diff --git a/src/utils/playback-profiles/subtitle-profile.ts b/src/utils/playback-profiles/subtitle-profile.ts index fa9b87b..c6ba306 100644 --- a/src/utils/playback-profiles/subtitle-profile.ts +++ b/src/utils/playback-profiles/subtitle-profile.ts @@ -28,6 +28,10 @@ export function getSubtitleProfiles(): SubtitleProfile[] { Format: "ssa", Method: SubtitleDeliveryMethod.External, }, + { + Format: "pgssub", + Method: SubtitleDeliveryMethod.External, + }, ); return SubtitleProfiles;