2023-10-08 18:16:30 +02:00
|
|
|
import { ScrapeMedia } from "@movie-web/providers";
|
|
|
|
|
2023-07-23 16:30:22 +02:00
|
|
|
import { MWStreamType } from "@/backend/helpers/streams";
|
|
|
|
import { MakeSlice } from "@/stores/player/slices/types";
|
|
|
|
import { ValuesOf } from "@/utils/typeguard";
|
|
|
|
|
|
|
|
export const playerStatus = {
|
|
|
|
IDLE: "idle",
|
|
|
|
SCRAPING: "scraping",
|
|
|
|
PLAYING: "playing",
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export type PlayerStatus = ValuesOf<typeof playerStatus>;
|
|
|
|
|
2023-08-15 19:55:48 +02:00
|
|
|
export interface SourceSliceSource {
|
|
|
|
url: string;
|
|
|
|
type: MWStreamType;
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:16:30 +02:00
|
|
|
export interface PlayerMeta {
|
|
|
|
type: "movie" | "show";
|
|
|
|
title: string;
|
|
|
|
tmdbId: string;
|
|
|
|
imdbId?: string;
|
|
|
|
releaseYear: number;
|
|
|
|
episode?: {
|
|
|
|
number: number;
|
|
|
|
tmdbId: string;
|
|
|
|
title: string;
|
|
|
|
};
|
|
|
|
season?: {
|
|
|
|
number: number;
|
|
|
|
tmdbId: string;
|
|
|
|
title: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-23 16:30:22 +02:00
|
|
|
export interface SourceSlice {
|
|
|
|
status: PlayerStatus;
|
2023-08-15 19:55:48 +02:00
|
|
|
source: SourceSliceSource | null;
|
2023-10-08 18:16:30 +02:00
|
|
|
meta: PlayerMeta | null;
|
2023-07-23 16:30:22 +02:00
|
|
|
setStatus(status: PlayerStatus): void;
|
|
|
|
setSource(url: string, type: MWStreamType): void;
|
2023-10-08 18:16:30 +02:00
|
|
|
setMeta(meta: PlayerMeta): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function metaToScrapeMedia(meta: PlayerMeta): ScrapeMedia {
|
|
|
|
if (meta.type === "show") {
|
|
|
|
if (!meta.episode || !meta.season) throw new Error("missing show data");
|
|
|
|
return {
|
|
|
|
title: meta.title,
|
|
|
|
releaseYear: meta.releaseYear,
|
|
|
|
tmdbId: meta.tmdbId,
|
|
|
|
type: "show",
|
|
|
|
imdbId: meta.imdbId,
|
|
|
|
episode: meta.episode,
|
|
|
|
season: meta.season,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: meta.title,
|
|
|
|
releaseYear: meta.releaseYear,
|
|
|
|
tmdbId: meta.tmdbId,
|
|
|
|
type: "movie",
|
|
|
|
imdbId: meta.imdbId,
|
|
|
|
};
|
2023-07-23 16:30:22 +02:00
|
|
|
}
|
|
|
|
|
2023-10-01 17:34:37 +02:00
|
|
|
export const createSourceSlice: MakeSlice<SourceSlice> = (set) => ({
|
2023-07-23 16:30:22 +02:00
|
|
|
source: null,
|
|
|
|
status: playerStatus.IDLE,
|
2023-10-08 18:16:30 +02:00
|
|
|
meta: null,
|
2023-07-23 16:30:22 +02:00
|
|
|
setStatus(status: PlayerStatus) {
|
|
|
|
set((s) => {
|
|
|
|
s.status = status;
|
|
|
|
});
|
|
|
|
},
|
2023-10-08 18:16:30 +02:00
|
|
|
setMeta(meta) {
|
|
|
|
set((s) => {
|
|
|
|
s.meta = meta;
|
|
|
|
});
|
|
|
|
},
|
2023-07-23 16:30:22 +02:00
|
|
|
setSource(url: string, type: MWStreamType) {
|
|
|
|
set((s) => {
|
|
|
|
s.source = {
|
|
|
|
type,
|
|
|
|
url,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|