selected providers + meta data on window object + fix dev dependencies

Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
This commit is contained in:
mrjvs 2023-03-13 21:25:28 +01:00
parent 80a9f1c91b
commit b36324d58e
17 changed files with 3705 additions and 3588 deletions

View File

@ -7,7 +7,6 @@
"@formkit/auto-animate": "^1.0.0-beta.5",
"@headlessui/react": "^1.5.0",
"@react-spring/web": "^9.7.1",
"@types/react-helmet": "^6.1.6",
"@use-gesture/react": "^10.2.24",
"crypto-js": "^4.1.1",
"fscreen": "^1.2.0",
@ -92,6 +91,7 @@
"vite-plugin-package-version": "^1.0.2",
"vite-plugin-pwa": "^0.14.4",
"vitest": "^0.28.5",
"workbox-window": "^6.5.4"
"workbox-window": "^6.5.4",
"@types/react-helmet": "^6.1.6"
}
}

View File

@ -10,6 +10,7 @@ registerEmbedScraper({
async getStream() {
// throw new Error("Oh well 2")
return {
embedId: "",
streamUrl: "",
quality: MWStreamQuality.Q1080P,
captions: [],

View File

@ -3,7 +3,7 @@ import { registerEmbedScraper } from "@/backend/helpers/register";
import {
MWStreamQuality,
MWStreamType,
MWStream,
MWEmbedStream,
} from "@/backend/helpers/streams";
import { proxiedFetch } from "@/backend/helpers/fetch";
@ -13,7 +13,7 @@ const URL_API = `${URL_BASE}/api`;
const URL_API_SOURCE = `${URL_API}/source`;
async function scrape(embed: string) {
const sources: MWStream[] = [];
const sources: MWEmbedStream[] = [];
const embedID = embed.split("/").pop();
@ -28,6 +28,7 @@ async function scrape(embed: string) {
for (const stream of streams) {
sources.push({
embedId: "",
streamUrl: stream.file as string,
quality: stream.label as MWStreamQuality,
type: stream.type as MWStreamType,

View File

@ -1,4 +1,4 @@
import { MWStream } from "./streams";
import { MWEmbedStream } from "./streams";
export enum MWEmbedType {
M4UFREE = "m4ufree",
@ -23,5 +23,5 @@ export type MWEmbedScraper = {
rank: number;
disabled?: boolean;
getStream(ctx: MWEmbedContext): Promise<MWStream>;
getStream(ctx: MWEmbedContext): Promise<MWEmbedStream>;
};

View File

@ -43,7 +43,13 @@ async function findBestEmbedStream(
providerId: string,
ctx: MWProviderRunContext
): Promise<MWStream | null> {
if (result.stream) return result.stream;
if (result.stream) {
return {
...result.stream,
providerId,
embedId: providerId,
};
}
let embedNum = 0;
for (const embed of result.embeds) {
@ -89,6 +95,7 @@ async function findBestEmbedStream(
type: "embed",
});
stream.providerId = providerId;
return stream;
}

View File

@ -27,5 +27,11 @@ export type MWStream = {
streamUrl: string;
type: MWStreamType;
quality: MWStreamQuality;
providerId?: string;
embedId?: string;
captions: MWCaption[];
};
export type MWEmbedStream = MWStream & {
embedId: string;
};

View File

@ -8,6 +8,7 @@ import {
useVideoPlayerDescriptor,
VideoPlayerContextProvider,
} from "../state/hooks";
import { MetaAction } from "./actions/MetaAction";
import { VideoElementInternal } from "./internal/VideoElementInternal";
export interface VideoPlayerBaseProps {
@ -44,6 +45,7 @@ function VideoPlayerBaseWithState(props: VideoPlayerBaseProps) {
: "",
].join(" ")}
>
<MetaAction />
<VideoElementInternal autoPlay={props.autoPlay} />
<CastingInternal />
<WrapperRegisterInternal wrapper={ref.current} />

View File

@ -0,0 +1,49 @@
import { MWCaption } from "@/backend/helpers/streams";
import { DetailedMeta } from "@/backend/metadata/getmeta";
import { useVideoPlayerDescriptor } from "@/video/state/hooks";
import { useMeta } from "@/video/state/logic/meta";
import { useEffect } from "react";
export type WindowMeta = {
meta: DetailedMeta;
captions: MWCaption[];
episode?: {
episodeId: string;
seasonId: string;
};
seasons?: {
id: string;
number: number;
title: string;
episodes?: { id: string; number: number; title: string }[];
}[];
} | null;
declare global {
interface Window {
meta?: Record<string, WindowMeta>;
}
}
export function MetaAction() {
const descriptor = useVideoPlayerDescriptor();
const meta = useMeta(descriptor);
useEffect(() => {
if (!window.meta) window.meta = {};
if (meta) {
window.meta[descriptor] = {
meta: meta.meta,
captions: meta.captions,
seasons: meta.seasons,
episode: meta.episode,
};
}
return () => {
if (window.meta) delete window.meta[descriptor];
};
}, [meta, descriptor]);
return null;
}

View File

@ -8,6 +8,8 @@ interface SourceControllerProps {
source: string;
type: MWStreamType;
quality: MWStreamQuality;
providerId?: string;
embedId?: string;
}
export function SourceController(props: SourceControllerProps) {

View File

@ -18,12 +18,14 @@ import { MWEmbed, MWEmbedType } from "@/backend/helpers/embed";
import { FloatingCardView } from "@/components/popout/FloatingCard";
import { FloatingView } from "@/components/popout/FloatingView";
import { useFloatingRouter } from "@/hooks/useFloatingRouter";
import { useSource } from "@/video/state/logic/source";
import { PopoutListEntry } from "./PopoutUtils";
interface EmbedEntryProps {
name: string;
type: MWEmbedType;
url: string;
active: boolean;
onSelect: (stream: MWStream) => void;
}
@ -43,6 +45,7 @@ export function EmbedEntry(props: EmbedEntryProps) {
isOnDarkBackground
loading={loading}
errored={!!error}
active={props.active}
onClick={() => {
scrapeEmbed();
}}
@ -61,6 +64,9 @@ export function SourceSelectionPopout(props: {
const descriptor = useVideoPlayerDescriptor();
const controls = useControls(descriptor);
const meta = useMeta(descriptor);
const { source } = useSource(descriptor);
const providerRef = useRef<string | null>(null);
const providers = useMemo(
() =>
meta
@ -96,6 +102,8 @@ export function SourceSelectionPopout(props: {
quality: stream.quality,
source: stream.streamUrl,
type: stream.type,
embedId: stream.embedId,
providerId: providerRef.current ?? undefined,
});
if (meta) {
controls.setMeta({
@ -106,7 +114,6 @@ export function SourceSelectionPopout(props: {
controls.closePopout();
}
const providerRef = useRef<string | null>(null);
const selectProvider = (providerId?: string) => {
if (!providerId) {
providerRef.current = null;
@ -188,6 +195,7 @@ export function SourceSelectionPopout(props: {
{providers.map((v) => (
<PopoutListEntry
key={v.id}
active={v.id === source?.providerId}
onClick={() => {
selectProvider(v.id);
}}
@ -234,6 +242,10 @@ export function SourceSelectionPopout(props: {
onClick={() => {
if (scrapeResult.stream) selectSource(scrapeResult.stream);
}}
active={
selectedProviderPopulated?.id === source?.providerId &&
selectedProviderPopulated?.id === source?.embedId
}
>
Native source
</PopoutListEntry>
@ -245,6 +257,7 @@ export function SourceSelectionPopout(props: {
name={v.displayName ?? ""}
key={v.url}
url={v.url}
active={false} // TODO add embed id extractor
onSelect={(stream) => {
selectSource(stream);
}}

View File

@ -9,6 +9,8 @@ export type VideoSourceEvent = {
quality: MWStreamQuality;
url: string;
type: MWStreamType;
providerId?: string;
embedId?: string;
caption: null | {
id: string;
url: string;

View File

@ -133,6 +133,8 @@ export function createCastingStateProvider(
type: source.type,
url: source.source,
caption: null,
embedId: source.embedId,
providerId: source.providerId,
};
resetStateForSource(descriptor, state);
updateSource(descriptor, state);
@ -224,6 +226,8 @@ export function createCastingStateProvider(
quality: state.source.quality,
source: state.source.url,
type: state.source.type,
embedId: state.source.embedId,
providerId: state.source.providerId,
});
return {

View File

@ -4,6 +4,8 @@ type VideoPlayerSource = {
source: string;
type: MWStreamType;
quality: MWStreamQuality;
providerId?: string;
embedId?: string;
} | null;
export type VideoPlayerStateController = {

View File

@ -189,6 +189,8 @@ export function createVideoStateProvider(
type: source.type,
url: source.source,
caption: null,
embedId: source.embedId,
providerId: source.providerId,
};
updateSource(descriptor, state);
},
@ -334,6 +336,8 @@ export function createVideoStateProvider(
quality: state.source.quality,
source: state.source.url,
type: state.source.type,
embedId: state.source.embedId,
providerId: state.source.providerId,
});
return {

View File

@ -58,6 +58,8 @@ export type VideoPlayerState = {
quality: MWStreamQuality;
url: string;
type: MWStreamType;
providerId?: string;
embedId?: string;
caption: null | {
url: string;
id: string;

View File

@ -146,6 +146,8 @@ export function MediaViewPlayer(props: MediaViewPlayerProps) {
source={props.stream.streamUrl}
type={props.stream.type}
quality={props.stream.quality}
embedId={props.stream.embedId}
providerId={props.stream.providerId}
/>
<ProgressListenerController
startAt={firstStartTime.current}
@ -181,6 +183,7 @@ export function MediaView() {
return getMetaFromId(data.type, data.id, seasonId);
}
);
// TODO get stream from someplace that actually gets updated
const [stream, setStream] = useState<MWStream | null>(null);
const lastSearchValue = useRef<(string | undefined)[] | null>(null);

7179
yarn.lock

File diff suppressed because it is too large Load Diff