Merge branch 'v4' into feat-urls-quicksearch

This commit is contained in:
mrjvs 2023-06-29 19:52:41 +02:00 committed by GitHub
commit 9d0878c5f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 61 deletions

View File

@ -29,10 +29,11 @@ Your proxy is now hosted on cloudflare. Note the url of your worker. you will ne
1. Download the file `movie-web.zip` from the latest release: [https://github.com/movie-web/movie-web/releases/latest](https://github.com/movie-web/movie-web/releases/latest) 1. Download the file `movie-web.zip` from the latest release: [https://github.com/movie-web/movie-web/releases/latest](https://github.com/movie-web/movie-web/releases/latest)
2. Extract the zip file so you can edit the files. 2. Extract the zip file so you can edit the files.
3. Open `config.js` in notepad, VScode or similar. 3. Open `config.js` in notepad, VScode or similar.
4. Put your cloudflare proxy URL inbetween the double qoutes of `VITE_CORS_PROXY_URL: "",`. Make sure to not have a slash at the end of your URL. 4. Put your cloudflare proxy URL inbetween the double qoutes of `VITE_CORS_PROXY_URL: ""`. Make sure to not have a slash at the end of your URL.
Example (THIS IS MINE, IT WONT WORK FOR YOU): `VITE_CORS_PROXY_URL: "https://test-proxy.test.workers.dev",` Example (THIS IS MINE, IT WONT WORK FOR YOU): `VITE_CORS_PROXY_URL: "https://test-proxy.test.workers.dev"`
5. Save the file 5. Put your TMDB read access token inside the quotes of `VITE_TMDB_READ_API_KEY: ""`. You can generate it for free at [https://www.themoviedb.org/settings/api](https://www.themoviedb.org/settings/api).
6. Save the file
Your client has been prepared, you can now host it on any webhost. Your client has been prepared, you can now host it on any webhost.
It doesn't require php, its just a standard static page. It doesn't require php, its just a standard static page.

View File

@ -1,6 +1,3 @@
# make sure the cors proxy url does NOT have a slash at the end # make sure the cors proxy url does NOT have a slash at the end
VITE_CORS_PROXY_URL=... VITE_CORS_PROXY_URL=...
VITE_TMDB_READ_API_KEY=...
# the keys below are optional - defaults are provided
VITE_TMDB_API_KEY=...
VITE_OMDB_API_KEY=...

View File

@ -1,6 +1,5 @@
window.__CONFIG__ = { window.__CONFIG__ = {
// url must NOT end with a slash // url must NOT end with a slash
VITE_CORS_PROXY_URL: "", VITE_CORS_PROXY_URL: "",
VITE_TMDB_API_KEY: "b030404650f279792a8d3287232358e3", VITE_TMDB_READ_API_KEY: ""
VITE_OMDB_API_KEY: "aa0937c0",
}; };

View File

@ -74,7 +74,7 @@ export function formatTMDBMetaResult(
season_number: v.season_number, season_number: v.season_number,
title: v.name, title: v.name,
})), })),
poster: (details as TMDBMovieData).poster_path ?? undefined, poster: getMediaPoster(show.poster_path) ?? undefined,
original_release_year: new Date(show.first_air_date).getFullYear(), original_release_year: new Date(show.first_air_date).getFullYear(),
}; };
} }

View File

@ -109,7 +109,7 @@ const baseURL = "https://api.themoviedb.org/3";
const headers = { const headers = {
accept: "application/json", accept: "application/json",
Authorization: `Bearer ${conf().TMDB_API_KEY}`, Authorization: `Bearer ${conf().TMDB_READ_API_KEY}`,
}; };
async function get<T>(url: string, params?: object): Promise<T> { async function get<T>(url: string, params?: object): Promise<T> {

View File

@ -7,7 +7,7 @@ import { registerSW } from "virtual:pwa-register";
import { ErrorBoundary } from "@/components/layout/ErrorBoundary"; import { ErrorBoundary } from "@/components/layout/ErrorBoundary";
import App from "@/setup/App"; import App from "@/setup/App";
import { conf } from "@/setup/config"; import { assertConfig, conf } from "@/setup/config";
import i18n from "@/setup/i18n"; import i18n from "@/setup/i18n";
import "@/setup/ga"; import "@/setup/ga";
@ -30,6 +30,7 @@ registerSW({
}); });
const LazyLoadedApp = React.lazy(async () => { const LazyLoadedApp = React.lazy(async () => {
await assertConfig();
await initializeStores(); await initializeStores();
i18n.changeLanguage(SettingsStore.get().language ?? "en"); i18n.changeLanguage(SettingsStore.get().language ?? "en");
return { return {

View File

@ -4,8 +4,7 @@ interface Config {
APP_VERSION: string; APP_VERSION: string;
GITHUB_LINK: string; GITHUB_LINK: string;
DISCORD_LINK: string; DISCORD_LINK: string;
OMDB_API_KEY: string; TMDB_READ_API_KEY: string;
TMDB_API_KEY: string;
CORS_PROXY_URL: string; CORS_PROXY_URL: string;
NORMAL_ROUTER: boolean; NORMAL_ROUTER: boolean;
} }
@ -14,15 +13,13 @@ export interface RuntimeConfig {
APP_VERSION: string; APP_VERSION: string;
GITHUB_LINK: string; GITHUB_LINK: string;
DISCORD_LINK: string; DISCORD_LINK: string;
OMDB_API_KEY: string; TMDB_READ_API_KEY: string;
TMDB_API_KEY: string;
NORMAL_ROUTER: boolean; NORMAL_ROUTER: boolean;
PROXY_URLS: string[]; PROXY_URLS: string[];
} }
const env: Record<keyof Config, undefined | string> = { const env: Record<keyof Config, undefined | string> = {
OMDB_API_KEY: import.meta.env.VITE_OMDB_API_KEY, TMDB_READ_API_KEY: import.meta.env.VITE_TMDB_READ_API_KEY,
TMDB_API_KEY: import.meta.env.VITE_TMDB_API_KEY,
APP_VERSION: undefined, APP_VERSION: undefined,
GITHUB_LINK: undefined, GITHUB_LINK: undefined,
DISCORD_LINK: undefined, DISCORD_LINK: undefined,
@ -30,25 +27,28 @@ const env: Record<keyof Config, undefined | string> = {
NORMAL_ROUTER: import.meta.env.VITE_NORMAL_ROUTER, NORMAL_ROUTER: import.meta.env.VITE_NORMAL_ROUTER,
}; };
const alerts = [] as string[];
// loads from different locations, in order: environment (VITE_{KEY}), window (public/config.js) // loads from different locations, in order: environment (VITE_{KEY}), window (public/config.js)
function getKey(key: keyof Config, defaultString?: string): string { function getKeyValue(key: keyof Config): string | undefined {
let windowValue = (window as any)?.__CONFIG__?.[`VITE_${key}`]; let windowValue = (window as any)?.__CONFIG__?.[`VITE_${key}`];
if (windowValue !== undefined && windowValue.length === 0) if (windowValue !== undefined && windowValue.length === 0)
windowValue = undefined; windowValue = undefined;
const value = env[key] ?? windowValue ?? undefined; return env[key] ?? windowValue ?? undefined;
if (value === undefined) {
if (defaultString) return defaultString;
if (!alerts.includes(key)) {
// eslint-disable-next-line no-alert
window.alert(`Misconfigured instance, missing key: ${key}`);
alerts.push(key);
}
return "";
} }
return value; function getKey(key: keyof Config, defaultString?: string): string {
return getKeyValue(key) ?? defaultString ?? "";
}
export function assertConfig() {
const keys: Array<keyof Config> = ["TMDB_READ_API_KEY", "CORS_PROXY_URL"];
const values = keys.map((key) => {
const val = getKeyValue(key);
if (val) return val;
// eslint-disable-next-line no-alert
window.alert(`Misconfigured instance, missing key: ${key}`);
return val;
});
if (values.includes(undefined)) throw new Error("Misconfigured instance");
} }
export function conf(): RuntimeConfig { export function conf(): RuntimeConfig {
@ -56,8 +56,7 @@ export function conf(): RuntimeConfig {
APP_VERSION, APP_VERSION,
GITHUB_LINK, GITHUB_LINK,
DISCORD_LINK, DISCORD_LINK,
OMDB_API_KEY: getKey("OMDB_API_KEY"), TMDB_READ_API_KEY: getKey("TMDB_READ_API_KEY"),
TMDB_API_KEY: getKey("TMDB_API_KEY"),
PROXY_URLS: getKey("CORS_PROXY_URL") PROXY_URLS: getKey("CORS_PROXY_URL")
.split(",") .split(",")
.map((v) => v.trim()), .map((v) => v.trim()),

View File

@ -1,29 +1,21 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { MWCaption } from "@/backend/helpers/streams";
import { DetailedMeta } from "@/backend/metadata/getmeta";
import { useVideoPlayerDescriptor } from "@/video/state/hooks"; import { useVideoPlayerDescriptor } from "@/video/state/hooks";
import {
VideoMediaPlayingEvent,
useMediaPlaying,
} from "@/video/state/logic/mediaplaying";
import { useMeta } from "@/video/state/logic/meta"; import { useMeta } from "@/video/state/logic/meta";
import { useProgress } from "@/video/state/logic/progress"; import { VideoProgressEvent, useProgress } from "@/video/state/logic/progress";
import { VideoPlayerMeta } from "@/video/state/types";
export type WindowMeta = { export type WindowMeta = {
meta: DetailedMeta; media: VideoPlayerMeta;
captions: MWCaption[]; state: {
episode?: { mediaPlaying: VideoMediaPlayingEvent;
episodeId: string; progress: VideoProgressEvent;
seasonId: string;
}; };
seasons?: {
id: string;
number: number;
title: string;
episodes?: { id: string; number: number; title: string }[];
}[];
progress: {
time: number;
duration: number;
}; };
} | null;
declare global { declare global {
interface Window { interface Window {
@ -35,18 +27,16 @@ export function MetaAction() {
const descriptor = useVideoPlayerDescriptor(); const descriptor = useVideoPlayerDescriptor();
const meta = useMeta(descriptor); const meta = useMeta(descriptor);
const progress = useProgress(descriptor); const progress = useProgress(descriptor);
const mediaPlaying = useMediaPlaying(descriptor);
useEffect(() => { useEffect(() => {
if (!window.meta) window.meta = {}; if (!window.meta) window.meta = {};
if (meta) { if (meta) {
window.meta[descriptor] = { window.meta[descriptor] = {
meta: meta.meta, media: meta,
captions: meta.captions, state: {
seasons: meta.seasons, mediaPlaying,
episode: meta.episode, progress,
progress: {
time: progress.time,
duration: progress.duration,
}, },
}; };
} }
@ -54,7 +44,7 @@ export function MetaAction() {
return () => { return () => {
if (window.meta) delete window.meta[descriptor]; if (window.meta) delete window.meta[descriptor];
}; };
}, [meta, descriptor, progress]); }, [meta, descriptor, mediaPlaying, progress]);
return null; return null;
} }