mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-01 16:37:39 +01:00
scrape styling and attempt at centering
Co-authored-by: William Oldham <github@binaryoverload.co.uk>
This commit is contained in:
parent
2d106ec7ca
commit
faff7ee7e0
5 changed files with 202 additions and 70 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import classNames from "classnames";
|
||||||
import { memo, useEffect, useRef } from "react";
|
import { memo, useEffect, useRef } from "react";
|
||||||
|
|
||||||
export enum Icons {
|
export enum Icons {
|
||||||
|
@ -113,7 +114,7 @@ export const Icon = memo((props: IconProps) => {
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
dangerouslySetInnerHTML={{ __html: iconList[props.icon] }} // eslint-disable-line react/no-danger
|
dangerouslySetInnerHTML={{ __html: iconList[props.icon] }} // eslint-disable-line react/no-danger
|
||||||
className={props.className}
|
className={classNames(props.className, "inline-block")}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
65
src/components/player/internals/ScrapeCard.tsx
Normal file
65
src/components/player/internals/ScrapeCard.tsx
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
import classNames from "classnames";
|
||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
import { StatusCircle } from "@/components/player/internals/StatusCircle";
|
||||||
|
import { Transition } from "@/components/Transition";
|
||||||
|
|
||||||
|
export interface ScrapeItemProps {
|
||||||
|
status: "failure" | "pending" | "notfound" | "success" | "waiting";
|
||||||
|
name: string;
|
||||||
|
id?: string;
|
||||||
|
percentage?: number;
|
||||||
|
children?: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ScrapeCardProps extends ScrapeItemProps {
|
||||||
|
hasChildren?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusTextMap: Partial<Record<ScrapeCardProps["status"], string>> = {
|
||||||
|
notfound: "Doesn't have the video",
|
||||||
|
failure: "Error occured",
|
||||||
|
pending: "Checking for videos...",
|
||||||
|
};
|
||||||
|
|
||||||
|
const statusMap: Record<ScrapeCardProps["status"], StatusCircle["type"]> = {
|
||||||
|
failure: "error",
|
||||||
|
notfound: "noresult",
|
||||||
|
pending: "loading",
|
||||||
|
success: "success",
|
||||||
|
waiting: "waiting",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function ScrapeItem(props: ScrapeItemProps) {
|
||||||
|
const text = statusTextMap[props.status];
|
||||||
|
const status = statusMap[props.status];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid gap-6 grid-cols-[auto,1fr]" data-source-id={props.id}>
|
||||||
|
<StatusCircle type={status} percentage={props.percentage ?? 0} />
|
||||||
|
<div>
|
||||||
|
<p className="font-bold text-white">{props.name}</p>
|
||||||
|
<div className="h-4">
|
||||||
|
<Transition animation="fade" show={!!text}>
|
||||||
|
<p>{text}</p>
|
||||||
|
</Transition>
|
||||||
|
</div>
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ScrapeCard(props: ScrapeCardProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-source-id={props.id}
|
||||||
|
className={classNames({
|
||||||
|
"!bg-opacity-100": props.hasChildren,
|
||||||
|
"w-72 rounded-md p-6 bg-video-scraping-card bg-opacity-0": true,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<ScrapeItem {...props} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,10 +1,15 @@
|
||||||
import { Icon, Icons } from "@/components/Icon";
|
import { a, to, useSpring } from "@react-spring/web";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
interface StatusCircle {
|
import { Icon, Icons } from "@/components/Icon";
|
||||||
type: "loading" | "done" | "error" | "pending" | "noresult";
|
import { Transition } from "@/components/Transition";
|
||||||
|
|
||||||
|
export interface StatusCircle {
|
||||||
|
type: "loading" | "success" | "error" | "noresult" | "waiting";
|
||||||
|
percentage?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StatusCircleLoading extends StatusCircle {
|
export interface StatusCircleLoading extends StatusCircle {
|
||||||
type: "loading";
|
type: "loading";
|
||||||
percentage: number;
|
percentage: number;
|
||||||
}
|
}
|
||||||
|
@ -16,19 +21,27 @@ function statusIsLoading(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function StatusCircle(props: StatusCircle | StatusCircleLoading) {
|
export function StatusCircle(props: StatusCircle | StatusCircleLoading) {
|
||||||
let classes = "";
|
const [spring] = useSpring(
|
||||||
if (props.type === "loading") classes = "text-video-scraping-loading";
|
() => ({
|
||||||
if (props.type === "noresult")
|
percentage: statusIsLoading(props) ? props.percentage : 0,
|
||||||
classes = "text-video-scraping-noresult text-opacity-50";
|
}),
|
||||||
if (props.type === "error")
|
[props]
|
||||||
classes = "text-video-scraping-error bg-video-scraping-error";
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={[
|
className={classNames({
|
||||||
"p-0.5 border-current border-2 rounded-full h-6 w-6 relative",
|
"p-0.5 border-current border-2 rounded-full h-6 w-6 relative transition-colors":
|
||||||
classes || "",
|
true,
|
||||||
].join(" ")}
|
"text-video-scraping-loading": props.type === "loading",
|
||||||
|
"text-video-scraping-noresult text-opacity-50":
|
||||||
|
props.type === "waiting",
|
||||||
|
"text-video-scraping-error bg-video-scraping-error":
|
||||||
|
props.type === "error",
|
||||||
|
"text-green-500 bg-green-500": props.type === "success",
|
||||||
|
"text-video-scraping-noresult bg-video-scraping-noresult":
|
||||||
|
props.type === "noresult",
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
width="100%"
|
width="100%"
|
||||||
|
@ -37,21 +50,36 @@ export function StatusCircle(props: StatusCircle | StatusCircleLoading) {
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
className="rounded-full -rotate-90"
|
className="rounded-full -rotate-90"
|
||||||
>
|
>
|
||||||
{statusIsLoading(props) ? (
|
<Transition animation="fade" show={statusIsLoading(props)}>
|
||||||
<circle
|
<a.circle
|
||||||
strokeWidth="32"
|
strokeWidth="32"
|
||||||
strokeDasharray={`${props.percentage} 100`}
|
strokeDasharray={to(spring.percentage, (val) => `${val} 100`)}
|
||||||
r="25%"
|
r="25%"
|
||||||
cx="50%"
|
cx="50%"
|
||||||
cy="50%"
|
cy="50%"
|
||||||
fill="transparent"
|
fill="transparent"
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
|
className="transition-[strokeDasharray]"
|
||||||
/>
|
/>
|
||||||
) : null}
|
</Transition>
|
||||||
</svg>
|
</svg>
|
||||||
{props.type === "error" ? (
|
<Transition animation="fade" show={props.type === "error"}>
|
||||||
<Icon className="absolute inset-0 text-white" icon={Icons.X} />
|
<Icon
|
||||||
) : null}
|
className="absolute inset-0 flex items-center justify-center text-white"
|
||||||
|
icon={Icons.X}
|
||||||
|
/>
|
||||||
|
</Transition>
|
||||||
|
<Transition animation="fade" show={props.type === "success"}>
|
||||||
|
<Icon
|
||||||
|
className="absolute inset-0 flex items-center text-xs justify-center text-white"
|
||||||
|
icon={Icons.CHECKMARK}
|
||||||
|
/>
|
||||||
|
</Transition>
|
||||||
|
<Transition animation="fade" show={props.type === "noresult"}>
|
||||||
|
<div className="absolute inset-0 flex items-center">
|
||||||
|
<div className="h-[3px] flex-1 mx-1 rounded-full bg-background-main" />
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { MWStreamType } from "@/backend/helpers/streams";
|
import { MWStreamType } from "@/backend/helpers/streams";
|
||||||
import { BrandPill } from "@/components/layout/BrandPill";
|
import { BrandPill } from "@/components/layout/BrandPill";
|
||||||
import { Player } from "@/components/player";
|
import { Player } from "@/components/player";
|
||||||
import { AutoPlayStart } from "@/components/player/atoms";
|
import { AutoPlayStart } from "@/components/player/atoms";
|
||||||
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
||||||
import { useShouldShowControls } from "@/components/player/hooks/useShouldShowControls";
|
import { useShouldShowControls } from "@/components/player/hooks/useShouldShowControls";
|
||||||
|
import { StatusCircle } from "@/components/player/internals/StatusCircle";
|
||||||
import { ScrapingPart } from "@/pages/parts/player/ScrapingPart";
|
import { ScrapingPart } from "@/pages/parts/player/ScrapingPart";
|
||||||
import { playerStatus } from "@/stores/player/slices/source";
|
import { playerStatus } from "@/stores/player/slices/source";
|
||||||
|
|
||||||
|
@ -11,13 +14,19 @@ export function PlayerView() {
|
||||||
const { status, setScrapeStatus, playMedia } = usePlayer();
|
const { status, setScrapeStatus, playMedia } = usePlayer();
|
||||||
const desktopControlsVisible = useShouldShowControls();
|
const desktopControlsVisible = useShouldShowControls();
|
||||||
|
|
||||||
|
const [a, setA] = useState(0);
|
||||||
|
useEffect(() => {
|
||||||
|
const dsf = setInterval(() => setA(Math.floor(Math.random() * 100)), 1000);
|
||||||
|
return () => clearInterval(dsf);
|
||||||
|
}, [setA]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Player.Container onLoad={setScrapeStatus}>
|
<Player.Container onLoad={setScrapeStatus}>
|
||||||
{status === playerStatus.SCRAPING ? (
|
{status === playerStatus.SCRAPING ? (
|
||||||
<ScrapingPart
|
<ScrapingPart
|
||||||
media={{
|
media={{
|
||||||
type: "movie",
|
type: "movie",
|
||||||
title: "Everything Everywhere All At Once",
|
title: "Everything Everywhere All At OnceASFAFS",
|
||||||
tmdbId: "545611",
|
tmdbId: "545611",
|
||||||
releaseYear: 2022,
|
releaseYear: 2022,
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
import { ProviderControls, ScrapeMedia } from "@movie-web/providers";
|
import { ProviderControls, ScrapeMedia } from "@movie-web/providers";
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import type { AsyncReturnType } from "type-fest";
|
import type { AsyncReturnType } from "type-fest";
|
||||||
|
|
||||||
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
||||||
|
import {
|
||||||
|
ScrapeCard,
|
||||||
|
ScrapeItem,
|
||||||
|
} from "@/components/player/internals/ScrapeCard";
|
||||||
import { StatusCircle } from "@/components/player/internals/StatusCircle";
|
import { StatusCircle } from "@/components/player/internals/StatusCircle";
|
||||||
import { providers } from "@/utils/providers";
|
import { providers } from "@/utils/providers";
|
||||||
|
|
||||||
|
@ -27,6 +31,7 @@ export interface ScrapingItems {
|
||||||
function useScrape() {
|
function useScrape() {
|
||||||
const [sources, setSources] = useState<Record<string, ScrapingSegment>>({});
|
const [sources, setSources] = useState<Record<string, ScrapingSegment>>({});
|
||||||
const [sourceOrder, setSourceOrder] = useState<ScrapingItems[]>([]);
|
const [sourceOrder, setSourceOrder] = useState<ScrapingItems[]>([]);
|
||||||
|
const [currentSource, setCurrentSource] = useState<string>();
|
||||||
|
|
||||||
const startScraping = useCallback(
|
const startScraping = useCallback(
|
||||||
async (media: ScrapeMedia) => {
|
async (media: ScrapeMedia) => {
|
||||||
|
@ -60,6 +65,7 @@ function useScrape() {
|
||||||
if (s[id]) s[id].status = "pending";
|
if (s[id]) s[id].status = "pending";
|
||||||
return { ...s };
|
return { ...s };
|
||||||
});
|
});
|
||||||
|
setCurrentSource(id);
|
||||||
},
|
},
|
||||||
update(evt) {
|
update(evt) {
|
||||||
setSources((s) => {
|
setSources((s) => {
|
||||||
|
@ -105,12 +111,52 @@ function useScrape() {
|
||||||
startScraping,
|
startScraping,
|
||||||
sourceOrder,
|
sourceOrder,
|
||||||
sources,
|
sources,
|
||||||
|
currentSource,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ScrapingPart(props: ScrapingProps) {
|
export function ScrapingPart(props: ScrapingProps) {
|
||||||
const { playMedia } = usePlayer();
|
const { playMedia } = usePlayer();
|
||||||
const { startScraping, sourceOrder, sources } = useScrape();
|
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
|
||||||
|
|
||||||
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const listRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!containerRef.current) return;
|
||||||
|
if (!listRef.current) return;
|
||||||
|
|
||||||
|
const elements = [
|
||||||
|
...listRef.current.querySelectorAll("div[data-source-id]"),
|
||||||
|
] as HTMLDivElement[];
|
||||||
|
|
||||||
|
const currentIndex = elements.findIndex(
|
||||||
|
(e) => e.getAttribute("data-source-id") === currentSource
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentElement = elements[currentIndex];
|
||||||
|
|
||||||
|
if (!currentElement) return;
|
||||||
|
|
||||||
|
const containerWidth = containerRef.current.getBoundingClientRect().width;
|
||||||
|
const listWidth = listRef.current.getBoundingClientRect().width;
|
||||||
|
|
||||||
|
const containerHeight = containerRef.current.getBoundingClientRect().height;
|
||||||
|
const listHeight = listRef.current.getBoundingClientRect().height;
|
||||||
|
|
||||||
|
const listTop = listRef.current.getBoundingClientRect().top;
|
||||||
|
|
||||||
|
const currentTop = currentElement.getBoundingClientRect().top;
|
||||||
|
const currentHeight = currentElement.getBoundingClientRect().height;
|
||||||
|
|
||||||
|
const topDifference = currentTop - listTop;
|
||||||
|
|
||||||
|
const listNewLeft = containerWidth / 2 - listWidth / 2;
|
||||||
|
const listNewTop = containerHeight / 2 - topDifference + currentHeight / 2;
|
||||||
|
|
||||||
|
listRef.current.style.left = `${listNewLeft}px`;
|
||||||
|
listRef.current.style.top = `${listNewTop}px`;
|
||||||
|
}, [sourceOrder, currentSource]);
|
||||||
|
|
||||||
const started = useRef(false);
|
const started = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -123,52 +169,35 @@ export function ScrapingPart(props: ScrapingProps) {
|
||||||
}, [startScraping, props, playMedia]);
|
}, [startScraping, props, playMedia]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full w-full flex items-center justify-center flex-col">
|
<div className="h-full w-full relative" ref={containerRef}>
|
||||||
{sourceOrder.map((order) => {
|
<div className="absolute" ref={listRef}>
|
||||||
const source = sources[order.id];
|
{sourceOrder.map((order) => {
|
||||||
if (!source) return null;
|
const source = sources[order.id];
|
||||||
|
return (
|
||||||
// Progress circle
|
<ScrapeCard
|
||||||
let Circle = <StatusCircle type="pending" />;
|
id={order.id}
|
||||||
if (source.status === "pending")
|
name={source.name}
|
||||||
Circle = (
|
status={source.status}
|
||||||
<StatusCircle type="loading" percentage={source.percentage} />
|
hasChildren={order.children.length > 0}
|
||||||
|
percentage={source.percentage}
|
||||||
|
key={order.id}
|
||||||
|
>
|
||||||
|
{order.children.map((embedId) => {
|
||||||
|
const embed = sources[embedId];
|
||||||
|
return (
|
||||||
|
<ScrapeItem
|
||||||
|
id={embedId}
|
||||||
|
name={embed.name}
|
||||||
|
status={source.status}
|
||||||
|
percentage={embed.percentage}
|
||||||
|
key={embedId}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ScrapeCard>
|
||||||
);
|
);
|
||||||
if (source.status === "notfound")
|
})}
|
||||||
Circle = <StatusCircle type="error" />;
|
</div>
|
||||||
|
|
||||||
// Main thing
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={order.id}
|
|
||||||
className="bg-video-scraping-card w-72 rounded-md p-6"
|
|
||||||
>
|
|
||||||
<div className="grid gap-6 grid-cols-[auto,1fr]">
|
|
||||||
{Circle}
|
|
||||||
<div>
|
|
||||||
<p className="font-bold text-white">{source.name}</p>
|
|
||||||
<p>
|
|
||||||
status: {source.status} ({source.percentage}%)
|
|
||||||
</p>
|
|
||||||
<p>reason: {source.reason}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{order.children.map((embedId) => {
|
|
||||||
const embed = sources[embedId];
|
|
||||||
if (!embed) return null;
|
|
||||||
return (
|
|
||||||
<div key={embedId} className="border border-blue-300 rounded">
|
|
||||||
<p className="font-bold text-white">{embed.name}</p>
|
|
||||||
<p>
|
|
||||||
status: {embed.status} ({embed.percentage}%)
|
|
||||||
</p>
|
|
||||||
<p>reason: {embed.reason}</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue