From 9c1195e131839a5e1920c17ea82f3679626a3aba Mon Sep 17 00:00:00 2001 From: mrjvs Date: Mon, 20 Nov 2023 20:09:50 +0100 Subject: [PATCH] Add premid support back (in different format) --- src/components/player/base/Container.tsx | 2 + .../player/internals/MetaReporter.tsx | 88 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/components/player/internals/MetaReporter.tsx diff --git a/src/components/player/base/Container.tsx b/src/components/player/base/Container.tsx index 5c05a923..8584c63a 100644 --- a/src/components/player/base/Container.tsx +++ b/src/components/player/base/Container.tsx @@ -4,6 +4,7 @@ import { OverlayDisplay } from "@/components/overlays/OverlayDisplay"; import { CastingInternal } from "@/components/player/internals/CastingInternal"; import { HeadUpdater } from "@/components/player/internals/HeadUpdater"; import { KeyboardEvents } from "@/components/player/internals/KeyboardEvents"; +import { MetaReporter } from "@/components/player/internals/MetaReporter"; import { ProgressSaver } from "@/components/player/internals/ProgressSaver"; import { ThumbnailScraper } from "@/components/player/internals/ThumbnailScraper"; import { VideoClickTarget } from "@/components/player/internals/VideoClickTarget"; @@ -84,6 +85,7 @@ export function Container(props: PlayerProps) { return (
+ diff --git a/src/components/player/internals/MetaReporter.tsx b/src/components/player/internals/MetaReporter.tsx new file mode 100644 index 00000000..a9fd3b69 --- /dev/null +++ b/src/components/player/internals/MetaReporter.tsx @@ -0,0 +1,88 @@ +import { useEffect } from "react"; + +import { usePlayerStore } from "@/stores/player/store"; + +export type WindowMeta = { + meta: { + type: "show" | "movie"; + tmdbId: string; + title: string; + year: number; + poster?: string; + }; + episode?: { + number: number; + tmdbId: string; + title: string; + }; + season?: { + number: number; + tmdbId: string; + title: string; + }; + progress: { + time: number; + duration: number; + }; + controls: { + isPlaying: boolean; + isLoading: boolean; + }; +}; + +declare global { + interface Window { + meta?: { + player?: WindowMeta; + }; + } +} + +export function MetaReporter() { + const meta = usePlayerStore((s) => s.meta); + const progress = usePlayerStore((s) => s.progress); + const mediaPlaying = usePlayerStore((s) => s.mediaPlaying); + + useEffect(() => { + if (!window.meta) window.meta = {}; + if (meta) { + window.meta.player = { + meta: { + title: meta.title, + type: meta.type, + tmdbId: meta.tmdbId, + year: meta.releaseYear, + poster: meta.poster, + }, + controls: { + isPlaying: mediaPlaying.isPlaying, + isLoading: mediaPlaying.isLoading, + }, + season: meta.season + ? { + number: meta.season.number, + tmdbId: meta.season.tmdbId, + title: meta.season.title, + } + : undefined, + episode: meta.episode + ? { + number: meta.episode.number, + tmdbId: meta.episode.tmdbId, + title: meta.episode.title, + } + : undefined, + progress: { + time: progress.time, + duration: progress.duration, + }, + }; + } + + return () => { + if (window.meta) delete window.meta.player; + }; + }, [meta, progress, mediaPlaying]); + + return null; +}