2023-10-08 18:16:30 +02:00
|
|
|
import { useEffect, useMemo } from "react";
|
|
|
|
|
2023-10-05 22:12:25 +02:00
|
|
|
import { MWStreamType } from "@/backend/helpers/streams";
|
2023-10-02 21:04:40 +02:00
|
|
|
import { BrandPill } from "@/components/layout/BrandPill";
|
2023-07-23 15:00:08 +02:00
|
|
|
import { Player } from "@/components/player";
|
2023-10-05 22:12:25 +02:00
|
|
|
import { AutoPlayStart } from "@/components/player/atoms";
|
2023-09-30 20:57:00 +02:00
|
|
|
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
2023-10-02 21:04:40 +02:00
|
|
|
import { useShouldShowControls } from "@/components/player/hooks/useShouldShowControls";
|
2023-10-01 21:08:26 +02:00
|
|
|
import { ScrapingPart } from "@/pages/parts/player/ScrapingPart";
|
2023-10-08 18:16:30 +02:00
|
|
|
import {
|
|
|
|
PlayerMeta,
|
|
|
|
metaToScrapeMedia,
|
|
|
|
playerStatus,
|
|
|
|
} from "@/stores/player/slices/source";
|
2023-07-23 15:00:08 +02:00
|
|
|
|
|
|
|
export function PlayerView() {
|
2023-10-08 18:16:30 +02:00
|
|
|
const { status, setScrapeStatus, playMedia, setMeta } = usePlayer();
|
2023-10-11 23:36:46 +02:00
|
|
|
const { showTargets, showTouchTargets } = useShouldShowControls();
|
2023-10-11 23:04:41 +02:00
|
|
|
|
2023-10-08 18:16:30 +02:00
|
|
|
const meta = useMemo<PlayerMeta>(
|
|
|
|
() => ({
|
|
|
|
type: "show",
|
2023-10-11 22:09:28 +02:00
|
|
|
title: "Normal People",
|
|
|
|
releaseYear: 2020,
|
|
|
|
tmdbId: "89905",
|
|
|
|
episode: { number: 12, tmdbId: "2207576", title: "Episode 12" },
|
|
|
|
season: { number: 1, tmdbId: "125160", title: "Season 1" },
|
2023-10-08 18:16:30 +02:00
|
|
|
}),
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setMeta(meta);
|
|
|
|
}, [setMeta, meta]);
|
|
|
|
const scrapeMedia = useMemo(() => metaToScrapeMedia(meta), [meta]);
|
2023-10-01 17:34:37 +02:00
|
|
|
|
2023-07-23 15:00:08 +02:00
|
|
|
return (
|
2023-10-01 17:34:37 +02:00
|
|
|
<Player.Container onLoad={setScrapeStatus}>
|
2023-10-02 21:04:40 +02:00
|
|
|
{status === playerStatus.SCRAPING ? (
|
|
|
|
<ScrapingPart
|
2023-10-08 18:16:30 +02:00
|
|
|
media={scrapeMedia}
|
2023-10-05 22:12:25 +02:00
|
|
|
onGetStream={(out) => {
|
|
|
|
if (out?.stream.type !== "file") return;
|
2023-10-11 22:09:28 +02:00
|
|
|
console.log(out.stream.qualities);
|
|
|
|
const qualities = Object.keys(out.stream.qualities).sort(
|
|
|
|
(a, b) => Number(b) - Number(a)
|
2023-10-05 22:12:25 +02:00
|
|
|
) as (keyof typeof out.stream.qualities)[];
|
2023-10-11 22:09:28 +02:00
|
|
|
|
|
|
|
let file;
|
|
|
|
for (const quality of qualities) {
|
|
|
|
if (out.stream.qualities[quality]?.url) {
|
|
|
|
console.log(quality);
|
|
|
|
file = out.stream.qualities[quality];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-05 22:12:25 +02:00
|
|
|
if (!file) return;
|
2023-10-08 19:35:11 +02:00
|
|
|
|
2023-10-05 22:12:25 +02:00
|
|
|
playMedia({
|
|
|
|
type: MWStreamType.MP4,
|
|
|
|
url: file.url,
|
|
|
|
});
|
|
|
|
}}
|
2023-10-02 21:04:40 +02:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
|
2023-10-11 23:36:46 +02:00
|
|
|
<Player.BlackOverlay show={showTargets} />
|
2023-10-05 22:12:25 +02:00
|
|
|
|
|
|
|
<Player.CenterControls>
|
|
|
|
<Player.LoadingSpinner />
|
|
|
|
<AutoPlayStart />
|
|
|
|
</Player.CenterControls>
|
|
|
|
|
2023-10-11 23:04:41 +02:00
|
|
|
<Player.CenterMobileControls
|
|
|
|
className="text-white"
|
2023-10-11 23:36:46 +02:00
|
|
|
show={showTouchTargets}
|
2023-10-11 23:04:41 +02:00
|
|
|
>
|
|
|
|
<Player.SkipBackward iconSizeClass="text-3xl" />
|
|
|
|
<Player.Pause iconSizeClass="text-5xl" />
|
|
|
|
<Player.SkipForward iconSizeClass="text-3xl" />
|
|
|
|
</Player.CenterMobileControls>
|
|
|
|
|
2023-10-11 23:36:46 +02:00
|
|
|
<Player.TopControls show={showTargets}>
|
2023-10-02 21:04:40 +02:00
|
|
|
<div className="grid grid-cols-[1fr,auto] xl:grid-cols-3 items-center">
|
|
|
|
<div className="flex space-x-3 items-center">
|
|
|
|
<Player.BackLink />
|
2023-10-08 18:16:30 +02:00
|
|
|
<span className="text mx-3 text-type-secondary">/</span>
|
|
|
|
<Player.Title />
|
2023-10-02 21:04:40 +02:00
|
|
|
<Player.BookmarkButton />
|
|
|
|
</div>
|
|
|
|
<div className="text-center hidden xl:flex justify-center items-center">
|
2023-10-08 18:16:30 +02:00
|
|
|
<Player.EpisodeTitle />
|
2023-10-02 21:04:40 +02:00
|
|
|
</div>
|
|
|
|
<div className="flex items-center justify-end">
|
|
|
|
<BrandPill />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Player.TopControls>
|
2023-10-05 22:12:25 +02:00
|
|
|
|
2023-10-11 23:36:46 +02:00
|
|
|
<Player.BottomControls show={showTargets}>
|
2023-10-01 21:08:26 +02:00
|
|
|
<Player.ProgressBar />
|
|
|
|
<div className="flex justify-between">
|
2023-10-11 23:04:41 +02:00
|
|
|
<Player.LeftSideControls className="hidden lg:flex">
|
2023-10-01 21:08:26 +02:00
|
|
|
<Player.Pause />
|
|
|
|
<Player.SkipBackward />
|
|
|
|
<Player.SkipForward />
|
2023-10-08 17:48:48 +02:00
|
|
|
<Player.Volume />
|
2023-10-01 21:08:26 +02:00
|
|
|
<Player.Time />
|
2023-10-08 17:48:48 +02:00
|
|
|
</Player.LeftSideControls>
|
2023-10-11 23:04:41 +02:00
|
|
|
<Player.LeftSideControls className="flex lg:hidden">
|
|
|
|
{/* Do mobile controls here :) */}
|
|
|
|
<Player.Time />
|
|
|
|
</Player.LeftSideControls>
|
|
|
|
<div className="flex items-center">
|
|
|
|
<Player.Settings />
|
2023-10-01 21:08:26 +02:00
|
|
|
<Player.Fullscreen />
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-10-01 17:34:37 +02:00
|
|
|
</Player.BottomControls>
|
2023-07-23 15:00:08 +02:00
|
|
|
</Player.Container>
|
|
|
|
);
|
|
|
|
}
|