From 2e8025a2418db27c019d9109777a536f7ea7eea7 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 27 Dec 2022 15:56:28 +0100 Subject: [PATCH 1/7] selfhosting guide --- README.md | 10 ++++++++-- SELFHOSTING.md | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 SELFHOSTING.md diff --git a/README.md b/README.md index 5b3e7d01..0f70d1b5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,13 @@ Features include: - No BS: just a search bar and a video player - No responsibility on the hoster, no databases or api's hosted by us, just a static site -## Self-hosting / running locally +## Self-hosting + +A simple guide has been written to assist in hosting your own instance of movie-web. + +Check it out here: [https://github.com/movie-web/movie-web/blob/dev/SELFHOSTING.md](https://github.com/movie-web/movie-web/blob/dev/SELFHOSTING.md) + +## Running locally for development To run this project locally for contributing or testing, run the following commands:
note: must use yarn to install packages and run NodeJS 16
@@ -39,7 +45,7 @@ yarn start To build production files, simply run `yarn build`. -You can also deploy the Cloudflare Worker (in worker.js) and update the proxy URL constant in `/src/mw-constants.ts`. +You'll need to deploy a cloudflare service worker as well. Check the [selfhosting guide](https://github.com/movie-web/movie-web/blob/dev/SELFHOSTING.md) on how to run the service worker. Afterwards update the proxy URL constant in `/src/mw-constants.ts` with your service worker.

Contributing - GitHub issues GitHub pull requests

diff --git a/SELFHOSTING.md b/SELFHOSTING.md new file mode 100644 index 00000000..21547b9f --- /dev/null +++ b/SELFHOSTING.md @@ -0,0 +1,33 @@ +# Selfhosting tutorial + +> **Note:** We do not provide support on how to selfhost, if you cant figure it out then tough luck. Please do not make Github issues or ask in our Discord server for support on how to selfhost. + +So you wanna selfhost. This app is made of two parts: + - The proxy + - The client + +## Hosting the proxy + +The proxy is made as a cloudflare worker, cloudflare has a generous free plan, so you don't need to pay anything unless you get hundreds of users. + +1. Create a cloudflare account at [https://dash.cloudflare.com](https://dash.cloudflare.com) +2. Navigate to `Workers`. +3. If it asks you, choose a subdomain +4. If it asks for a workers plan, press "Continue with free" +5. Create a new service with a name of your choice. Must be type `HTTP handler` +6. On the service page, Click `Quick edit` +7. Download the `worker.js` file from the latest release of the proxy: [https://github.com/movie-web/simple-proxy/releases/latest](https://github.com/movie-web/simple-proxy/releases/latest) +8. Open the downloaded `worker.js` file in notepad, VScode or similar. +9. Copy the text contents of the `worker.js` file. +10. Paste the text contents into the edit screen of the cloudflare service worker. +11. Click `Save and deploy` and confirm. + +Your proxy is now hosted on cloudflare. Note the url of your worker. you will need it later. + +## Hosting the client + +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. + +> Whoops, the rest of this guide hasn't been written yet. +Check back soon. From 388827b56f2c82ac2d45c8fee802936f7e3d7963 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 27 Dec 2022 16:44:36 +0100 Subject: [PATCH 2/7] new config system --- .eslintrc.js | 28 +++++++---- .gitignore | 5 +- README.md | 2 +- SELFHOSTING.md | 9 +++- example.env | 6 +++ index.html | 1 + public/config.js | 5 ++ src/components/layout/ErrorBoundary.tsx | 6 +-- src/components/layout/Navigation.tsx | 6 +-- src/config.ts | 50 +++++++++++++++++++ src/constants.ts | 3 ++ src/mw_constants.ts | 7 --- src/providers/list/flixhq/index.ts | 18 +++++-- src/providers/list/gdriveplayer/index.ts | 14 ++++-- src/providers/list/gomostream/index.ts | 16 +++--- src/providers/list/superstream/index.ts | 16 +++--- src/providers/list/theflix/index.ts | 14 ++++-- src/providers/list/theflix/portableToMedia.ts | 8 +-- src/providers/list/theflix/search.ts | 4 +- src/providers/list/xemovie/index.ts | 19 ++++--- 20 files changed, 168 insertions(+), 69 deletions(-) create mode 100644 example.env create mode 100644 public/config.js create mode 100644 src/config.ts create mode 100644 src/constants.ts delete mode 100644 src/mw_constants.ts diff --git a/.eslintrc.js b/.eslintrc.js index 6f5cb2dc..d45d17f9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,26 +1,32 @@ -const a11yOff = Object.keys(require('eslint-plugin-jsx-a11y').rules) - .reduce((acc, rule) => { acc[`jsx-a11y/${rule}`] = 'off'; return acc }, {}) +const a11yOff = Object.keys(require("eslint-plugin-jsx-a11y").rules).reduce( + (acc, rule) => { + acc[`jsx-a11y/${rule}`] = "off"; + return acc; + }, + {} +); module.exports = { extends: [ "airbnb", "airbnb/hooks", "plugin:@typescript-eslint/recommended", - "prettier", + "prettier" ], settings: { "import/resolver": { - typescript: {}, - }, + typescript: {} + } }, + ignorePatterns: ["public/*", "/*.js", "/*.ts"], parser: "@typescript-eslint/parser", parserOptions: { project: "./tsconfig.json", - tsconfigRootDir: "./", + tsconfigRootDir: "./" }, plugins: ["@typescript-eslint", "import"], env: { - browser: true, + browser: true }, rules: { "react/jsx-uses-react": "off", @@ -43,16 +49,16 @@ module.exports = { "no-await-in-loop": "off", "react/jsx-filename-extension": [ "error", - { extensions: [".js", ".tsx", ".jsx"] }, + { extensions: [".js", ".tsx", ".jsx"] } ], "import/extensions": [ "error", "ignorePackages", { ts: "never", - tsx: "never", - }, + tsx: "never" + } ], ...a11yOff - }, + } }; diff --git a/.gitignore b/.gitignore index ae1ad7d8..26059563 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -package-lock.json \ No newline at end of file +package-lock.json + +# config +.env diff --git a/README.md b/README.md index 0f70d1b5..683c374e 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ yarn start To build production files, simply run `yarn build`. -You'll need to deploy a cloudflare service worker as well. Check the [selfhosting guide](https://github.com/movie-web/movie-web/blob/dev/SELFHOSTING.md) on how to run the service worker. Afterwards update the proxy URL constant in `/src/mw-constants.ts` with your service worker. +You'll need to deploy a cloudflare service worker as well. Check the [selfhosting guide](https://github.com/movie-web/movie-web/blob/dev/SELFHOSTING.md) on how to run the service worker. Afterwards you can make a `.env` file and put in the URL. (see `example.env` for an example)

Contributing - GitHub issues GitHub pull requests

diff --git a/SELFHOSTING.md b/SELFHOSTING.md index 21547b9f..4718b9c0 100644 --- a/SELFHOSTING.md +++ b/SELFHOSTING.md @@ -28,6 +28,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) 2. Extract the zip file so you can edit the files. +3. Open `config.js` in notepad, VScode or similar. +4. Put your cloudflare proxy URL inbetween the double qoutes of `VITE_CORS_PROXY_URL: "",`. -> Whoops, the rest of this guide hasn't been written yet. -Check back soon. + Example (THIS IS MINE, IT WONT WORK FOR YOU): `VITE_CORS_PROXY_URL: "https://test-proxy.test.workers.dev/",` +5. Save the file + +Your client has been prepared, you can now host it on any webhost. +It doesn't require php, its just a standard static page. diff --git a/example.env b/example.env new file mode 100644 index 00000000..5416f0f1 --- /dev/null +++ b/example.env @@ -0,0 +1,6 @@ +# make sure the cors proxy url does NOT have a slash at the end +VITE_CORS_PROXY_URL=... + +# the keys below are optional - defaults are provided +VITE_TMDB_API_KEY=... +VITE_OMDB_API_KEY=... diff --git a/index.html b/index.html index 822f74f3..fb20650b 100644 --- a/index.html +++ b/index.html @@ -39,6 +39,7 @@ rel="stylesheet" /> + movie-web diff --git a/public/config.js b/public/config.js new file mode 100644 index 00000000..463fdd2c --- /dev/null +++ b/public/config.js @@ -0,0 +1,5 @@ +window.__CONFIG__ = { + VITE_CORS_PROXY_URL: "", + VITE_TMDB_API_KEY: "b030404650f279792a8d3287232358e3", + VITE_OMDB_API_KEY: "aa0937c0" +}; diff --git a/src/components/layout/ErrorBoundary.tsx b/src/components/layout/ErrorBoundary.tsx index 75aab1e1..b1803226 100644 --- a/src/components/layout/ErrorBoundary.tsx +++ b/src/components/layout/ErrorBoundary.tsx @@ -3,7 +3,7 @@ import { IconPatch } from "@/components/buttons/IconPatch"; import { Icons } from "@/components/Icon"; import { Link } from "@/components/text/Link"; import { Title } from "@/components/text/Title"; -import { DISCORD_LINK, GITHUB_LINK } from "@/mw_constants"; +import { conf } from "@/config"; interface ErrorBoundaryState { hasError: boolean; @@ -58,11 +58,11 @@ export class ErrorBoundary extends Component<

The app encountered an error and wasn't able to recover, please report it to the{" "} - + Discord server {" "} or on{" "} - + GitHub . diff --git a/src/components/layout/Navigation.tsx b/src/components/layout/Navigation.tsx index 0a255395..00fd2eb0 100644 --- a/src/components/layout/Navigation.tsx +++ b/src/components/layout/Navigation.tsx @@ -2,7 +2,7 @@ import { ReactNode } from "react"; import { Link } from "react-router-dom"; import { IconPatch } from "@/components/buttons/IconPatch"; import { Icons } from "@/components/Icon"; -import { DISCORD_LINK, GITHUB_LINK } from "@/mw_constants"; +import { conf } from "@/config"; import { BrandPill } from "./BrandPill"; export interface NavigationProps { @@ -26,7 +26,7 @@ export function Navigation(props: NavigationProps) { } flex-row gap-4`} > = { + OMDB_API_KEY: import.meta.env.VITE_OMDB_API_KEY, + TMDB_API_KEY: import.meta.env.VITE_TMDB_API_KEY, + APP_VERSION: undefined, + GITHUB_LINK: undefined, + DISCORD_LINK: undefined, + CORS_PROXY_URL: import.meta.env.VITE_CORS_PROXY_URL, +}; + +const alerts = [] as string[]; + +// loads from different locations, in order: environment (VITE_{KEY}), window (public/config.js) +function getKey(key: keyof Config): string { + let windowValue = (window as any)?.__CONFIG__?.[`VITE_${key}`]; + if (windowValue !== undefined && windowValue.length === 0) + windowValue = undefined; + const value = env[key] ?? windowValue ?? undefined; + if (value === undefined) { + if (!alerts.includes(key)) { + // eslint-disable-next-line no-alert + window.alert(`Misconfigured instance, missing key: ${key}`); + alerts.push(key); + } + return ""; + } + + return value; +} + +export function conf(): Config { + return { + APP_VERSION, + GITHUB_LINK, + DISCORD_LINK, + OMDB_API_KEY: getKey("OMDB_API_KEY"), + TMDB_API_KEY: getKey("TMDB_API_KEY"), + CORS_PROXY_URL: `${getKey("CORS_PROXY_URL")}/?destination=`, + }; +} diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 00000000..f9ac5da1 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,3 @@ +export const DISCORD_LINK = "https://discord.gg/Jhqt4Xzpfb"; +export const GITHUB_LINK = "https://github.com/JamesHawkinss/movie-web"; +export const APP_VERSION = "2.1.0"; diff --git a/src/mw_constants.ts b/src/mw_constants.ts deleted file mode 100644 index b7ced684..00000000 --- a/src/mw_constants.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const CORS_PROXY_URL = - "https://cors.squeezebox.dev/?destination="; -export const TMDB_API_KEY = "b030404650f279792a8d3287232358e3"; -export const OMDB_API_KEY = "aa0937c0"; -export const DISCORD_LINK = "https://discord.gg/Jhqt4Xzpfb"; -export const GITHUB_LINK = "https://github.com/JamesHawkinss/movie-web"; -export const APP_VERSION = "2.1.0"; diff --git a/src/providers/list/flixhq/index.ts b/src/providers/list/flixhq/index.ts index 452c7359..8fe6564d 100644 --- a/src/providers/list/flixhq/index.ts +++ b/src/providers/list/flixhq/index.ts @@ -7,7 +7,7 @@ import { MWProviderMediaResult, } from "@/providers/types"; -import { CORS_PROXY_URL } from "@/mw_constants"; +import { conf } from "@/config"; export const flixhqProvider: MWMediaProvider = { id: "flixhq", @@ -19,7 +19,9 @@ export const flixhqProvider: MWMediaProvider = { media: MWPortableMedia ): Promise { const searchRes = await fetch( - `${CORS_PROXY_URL}https://api.consumet.org/movies/flixhq/info?id=${encodeURIComponent( + `${ + conf().CORS_PROXY_URL + }https://api.consumet.org/movies/flixhq/info?id=${encodeURIComponent( media.mediaId )}` ).then((d) => d.json()); @@ -33,7 +35,9 @@ export const flixhqProvider: MWMediaProvider = { async searchForMedia(query: MWQuery): Promise { const searchRes = await fetch( - `${CORS_PROXY_URL}https://api.consumet.org/movies/flixhq/${encodeURIComponent( + `${ + conf().CORS_PROXY_URL + }https://api.consumet.org/movies/flixhq/${encodeURIComponent( query.searchQuery )}` ).then((d) => d.json()); @@ -52,7 +56,9 @@ export const flixhqProvider: MWMediaProvider = { async getStream(media: MWPortableMedia): Promise { const searchRes = await fetch( - `${CORS_PROXY_URL}https://api.consumet.org/movies/flixhq/info?id=${encodeURIComponent( + `${ + conf().CORS_PROXY_URL + }https://api.consumet.org/movies/flixhq/info?id=${encodeURIComponent( media.mediaId )}` ).then((d) => d.json()); @@ -63,7 +69,9 @@ export const flixhqProvider: MWMediaProvider = { }); const watchRes = await fetch( - `${CORS_PROXY_URL}https://api.consumet.org/movies/flixhq/watch?${encodeURIComponent( + `${ + conf().CORS_PROXY_URL + }https://api.consumet.org/movies/flixhq/watch?${encodeURIComponent( params.toString() )}` ).then((d) => d.json()); diff --git a/src/providers/list/gdriveplayer/index.ts b/src/providers/list/gdriveplayer/index.ts index 423a2ece..d13d2414 100644 --- a/src/providers/list/gdriveplayer/index.ts +++ b/src/providers/list/gdriveplayer/index.ts @@ -9,7 +9,7 @@ import { MWProviderMediaResult, } from "@/providers/types"; -import { CORS_PROXY_URL } from "@/mw_constants"; +import { conf } from "@/config"; const format = { stringify: (cipher: any) => { @@ -47,7 +47,9 @@ export const gDrivePlayerScraper: MWMediaProvider = { media: MWPortableMedia ): Promise { const res = await fetch( - `${CORS_PROXY_URL}https://api.gdriveplayer.us/v1/imdb/${media.mediaId}` + `${conf().CORS_PROXY_URL}https://api.gdriveplayer.us/v1/imdb/${ + media.mediaId + }` ).then((d) => d.json()); return { @@ -59,7 +61,9 @@ export const gDrivePlayerScraper: MWMediaProvider = { async searchForMedia(query: MWQuery): Promise { const searchRes = await fetch( - `${CORS_PROXY_URL}https://api.gdriveplayer.us/v1/movie/search?title=${query.searchQuery}` + `${ + conf().CORS_PROXY_URL + }https://api.gdriveplayer.us/v1/movie/search?title=${query.searchQuery}` ).then((d) => d.json()); const results: MWProviderMediaResult[] = (searchRes || []).map( @@ -75,7 +79,9 @@ export const gDrivePlayerScraper: MWMediaProvider = { async getStream(media: MWPortableMedia): Promise { const streamRes = await fetch( - `${CORS_PROXY_URL}https://database.gdriveplayer.us/player.php?imdb=${media.mediaId}` + `${ + conf().CORS_PROXY_URL + }https://database.gdriveplayer.us/player.php?imdb=${media.mediaId}` ).then((d) => d.text()); const page = new DOMParser().parseFromString(streamRes, "text/html"); diff --git a/src/providers/list/gomostream/index.ts b/src/providers/list/gomostream/index.ts index 50cb5dc3..092645d4 100644 --- a/src/providers/list/gomostream/index.ts +++ b/src/providers/list/gomostream/index.ts @@ -9,7 +9,7 @@ import { MWProviderMediaResult, } from "@/providers/types"; -import { CORS_PROXY_URL, OMDB_API_KEY } from "@/mw_constants"; +import { conf } from "@/config"; export const gomostreamScraper: MWMediaProvider = { id: "gomostream", @@ -21,13 +21,13 @@ export const gomostreamScraper: MWMediaProvider = { media: MWPortableMedia ): Promise { const params = new URLSearchParams({ - apikey: OMDB_API_KEY, + apikey: conf().OMDB_API_KEY, i: media.mediaId, type: media.mediaType, }); const res = await fetch( - `${CORS_PROXY_URL}http://www.omdbapi.com/?${encodeURIComponent( + `${conf().CORS_PROXY_URL}http://www.omdbapi.com/?${encodeURIComponent( params.toString() )}` ).then((d) => d.json()); @@ -43,12 +43,12 @@ export const gomostreamScraper: MWMediaProvider = { const term = query.searchQuery.toLowerCase(); const params = new URLSearchParams({ - apikey: OMDB_API_KEY, + apikey: conf().OMDB_API_KEY, s: term, type: query.type, }); const searchRes = await fetch( - `${CORS_PROXY_URL}http://www.omdbapi.com/?${encodeURIComponent( + `${conf().CORS_PROXY_URL}http://www.omdbapi.com/?${encodeURIComponent( params.toString() )}` ).then((d) => d.json()); @@ -69,7 +69,7 @@ export const gomostreamScraper: MWMediaProvider = { const type = media.mediaType === MWMediaType.SERIES ? "show" : media.mediaType; const res1 = await fetch( - `${CORS_PROXY_URL}https://gomo.to/${type}/${media.mediaId}` + `${conf().CORS_PROXY_URL}https://gomo.to/${type}/${media.mediaId}` ).then((d) => d.text()); if (res1 === "Movie not available." || res1 === "Episode not available.") throw new Error(res1); @@ -82,7 +82,7 @@ export const gomostreamScraper: MWMediaProvider = { fd.append("_token", _token); const src = await fetch( - `${CORS_PROXY_URL}https://gomo.to/decoding_v3.php`, + `${conf().CORS_PROXY_URL}https://gomo.to/decoding_v3.php`, { method: "POST", body: fd, @@ -95,7 +95,7 @@ export const gomostreamScraper: MWMediaProvider = { // maybe try all embeds in the future const embedUrl = embeds[1]; - const res2 = await fetch(`${CORS_PROXY_URL}${embedUrl}`).then((d) => + const res2 = await fetch(`${conf().CORS_PROXY_URL}${embedUrl}`).then((d) => d.text() ); diff --git a/src/providers/list/superstream/index.ts b/src/providers/list/superstream/index.ts index 72df7e98..3dc26e7b 100644 --- a/src/providers/list/superstream/index.ts +++ b/src/providers/list/superstream/index.ts @@ -4,7 +4,7 @@ import { customAlphabet } from "nanoid"; import toWebVTT from "srt-webvtt"; import CryptoJS from "crypto-js"; -import { CORS_PROXY_URL, TMDB_API_KEY } from "@/mw_constants"; +import { conf } from "@/config"; import { MWMediaProvider, MWMediaType, @@ -85,7 +85,7 @@ const get = (data: object, altApi = false) => { formatted.append("medium", "Website"); const requestUrl = altApi ? apiUrls[1] : apiUrls[0]; - return fetch(`${CORS_PROXY_URL}${requestUrl}`, { + return fetch(`${conf().CORS_PROXY_URL}${requestUrl}`, { method: "POST", headers: { Platform: "android", @@ -200,7 +200,7 @@ export const superStreamScraper: MWMediaProvider = { const mappedCaptions = await Promise.all( subtitleRes.list.map(async (subtitle: any) => { const captionBlob = await fetch( - `${CORS_PROXY_URL}${subtitle.subtitles[0].file_path}` + `${conf().CORS_PROXY_URL}${subtitle.subtitles[0].file_path}` ).then((captionRes) => captionRes.blob()); // cross-origin bypass const captionUrl = await toWebVTT(captionBlob); // convert to vtt so it's playable return { @@ -253,7 +253,7 @@ export const superStreamScraper: MWMediaProvider = { const mappedCaptions = await Promise.all( subtitleRes.list.map(async (subtitle: any) => { const captionBlob = await fetch( - `${CORS_PROXY_URL}${subtitle.subtitles[0].file_path}` + `${conf().CORS_PROXY_URL}${subtitle.subtitles[0].file_path}` ).then((captionRes) => captionRes.blob()); // cross-origin bypass const captionUrl = await toWebVTT(captionBlob); // convert to vtt so it's playable return { @@ -277,11 +277,15 @@ export const superStreamScraper: MWMediaProvider = { const detailRes = (await get(apiQuery, true).then((r) => r.json())).data; const firstSearchResult = ( await fetch( - `https://api.themoviedb.org/3/search/tv?api_key=${TMDB_API_KEY}&language=en-US&page=1&query=${detailRes.title}&include_adult=false` + `https://api.themoviedb.org/3/search/tv?api_key=${ + conf().TMDB_API_KEY + }&language=en-US&page=1&query=${detailRes.title}&include_adult=false` ).then((r) => r.json()) ).results[0]; const showDetails = await fetch( - `https://api.themoviedb.org/3/tv/${firstSearchResult.id}?api_key=${TMDB_API_KEY}` + `https://api.themoviedb.org/3/tv/${firstSearchResult.id}?api_key=${ + conf().TMDB_API_KEY + }` ).then((r) => r.json()); return { diff --git a/src/providers/list/theflix/index.ts b/src/providers/list/theflix/index.ts index cf41cc11..cdfe8e66 100644 --- a/src/providers/list/theflix/index.ts +++ b/src/providers/list/theflix/index.ts @@ -15,7 +15,7 @@ import { } from "@/providers/list/theflix/search"; import { getDataFromPortableSearch } from "@/providers/list/theflix/portableToMedia"; -import { CORS_PROXY_URL } from "@/mw_constants"; +import { conf } from "@/config"; export const theFlixScraper: MWMediaProvider = { id: "theflix", @@ -51,9 +51,13 @@ export const theFlixScraper: MWMediaProvider = { let url = ""; if (media.mediaType === MWMediaType.MOVIE) { - url = `${CORS_PROXY_URL}https://theflix.to/movie/${media.mediaId}?movieInfo=${media.mediaId}`; + url = `${conf().CORS_PROXY_URL}https://theflix.to/movie/${ + media.mediaId + }?movieInfo=${media.mediaId}`; } else if (media.mediaType === MWMediaType.SERIES) { - url = `${CORS_PROXY_URL}https://theflix.to/tv-show/${media.mediaId}/season-${media.seasonId}/episode-${media.episodeId}`; + url = `${conf().CORS_PROXY_URL}https://theflix.to/tv-show/${ + media.mediaId + }/season-${media.seasonId}/episode-${media.episodeId}`; } const res = await fetch(url).then((d) => d.text()); @@ -76,7 +80,9 @@ export const theFlixScraper: MWMediaProvider = { async getSeasonDataFromMedia( media: MWPortableMedia ): Promise { - const url = `${CORS_PROXY_URL}https://theflix.to/tv-show/${media.mediaId}/season-${media.seasonId}/episode-${media.episodeId}`; + const url = `${conf().CORS_PROXY_URL}https://theflix.to/tv-show/${ + media.mediaId + }/season-${media.seasonId}/episode-${media.episodeId}`; const res = await fetch(url).then((d) => d.text()); const node: Element = Array.from( diff --git a/src/providers/list/theflix/portableToMedia.ts b/src/providers/list/theflix/portableToMedia.ts index 4115e703..191e828c 100644 --- a/src/providers/list/theflix/portableToMedia.ts +++ b/src/providers/list/theflix/portableToMedia.ts @@ -1,4 +1,4 @@ -import { CORS_PROXY_URL } from "@/mw_constants"; +import { conf } from "@/config"; import { MWMediaType, MWPortableMedia } from "@/providers/types"; const getTheFlixUrl = (media: MWPortableMedia, params?: URLSearchParams) => { @@ -18,9 +18,9 @@ export async function getDataFromPortableSearch( const params = new URLSearchParams(); params.append("movieInfo", media.mediaId); - const res = await fetch(CORS_PROXY_URL + getTheFlixUrl(media, params)).then( - (d) => d.text() - ); + const res = await fetch( + conf().CORS_PROXY_URL + getTheFlixUrl(media, params) + ).then((d) => d.text()); const node: Element = Array.from( new DOMParser() diff --git a/src/providers/list/theflix/search.ts b/src/providers/list/theflix/search.ts index 661f2542..c0dded24 100644 --- a/src/providers/list/theflix/search.ts +++ b/src/providers/list/theflix/search.ts @@ -1,4 +1,4 @@ -import { CORS_PROXY_URL } from "@/mw_constants"; +import { conf } from "@/config"; import { MWMediaType, MWProviderMediaResult, MWQuery } from "@/providers"; const getTheFlixUrl = (type: "tv-shows" | "movies", params: URLSearchParams) => @@ -8,7 +8,7 @@ export function searchTheFlix(query: MWQuery): Promise { const params = new URLSearchParams(); params.append("search", query.searchQuery); return fetch( - CORS_PROXY_URL + + conf().CORS_PROXY_URL + getTheFlixUrl( query.type === MWMediaType.MOVIE ? "movies" : "tv-shows", params diff --git a/src/providers/list/xemovie/index.ts b/src/providers/list/xemovie/index.ts index 7f65f026..2d14e73b 100644 --- a/src/providers/list/xemovie/index.ts +++ b/src/providers/list/xemovie/index.ts @@ -8,7 +8,7 @@ import { MWMediaCaption, } from "@/providers/types"; -import { CORS_PROXY_URL } from "@/mw_constants"; +import { conf } from "@/config"; export const xemovieScraper: MWMediaProvider = { id: "xemovie", @@ -20,7 +20,7 @@ export const xemovieScraper: MWMediaProvider = { media: MWPortableMedia ): Promise { const res = await fetch( - `${CORS_PROXY_URL}https://xemovie.co/movies/${media.mediaId}/watch` + `${conf().CORS_PROXY_URL}https://xemovie.co/movies/${media.mediaId}/watch` ).then((d) => d.text()); const DOM = new DOMParser().parseFromString(res, "text/html"); @@ -42,9 +42,9 @@ export const xemovieScraper: MWMediaProvider = { async searchForMedia(query: MWQuery): Promise { const term = query.searchQuery.toLowerCase(); - const searchUrl = `${CORS_PROXY_URL}https://xemovie.co/search?q=${encodeURIComponent( - term - )}`; + const searchUrl = `${ + conf().CORS_PROXY_URL + }https://xemovie.co/search?q=${encodeURIComponent(term)}`; const searchRes = await fetch(searchUrl).then((d) => d.text()); const parser = new DOMParser(); @@ -81,7 +81,9 @@ export const xemovieScraper: MWMediaProvider = { if (media.mediaType !== MWMediaType.MOVIE) throw new Error("Incorrect type"); - const url = `${CORS_PROXY_URL}https://xemovie.co/movies/${media.mediaId}/watch`; + const url = `${conf().CORS_PROXY_URL}https://xemovie.co/movies/${ + media.mediaId + }/watch`; let streamUrl = ""; const subtitles: MWMediaCaption[] = []; @@ -100,7 +102,8 @@ export const xemovieScraper: MWMediaProvider = { const data = JSON.parse( JSON.stringify( eval( - `(${script.textContent.replace("const data = ", "").split("};")[0] + `(${ + script.textContent.replace("const data = ", "").split("};")[0] }})` ) ) @@ -112,7 +115,7 @@ export const xemovieScraper: MWMediaProvider = { subtitleTrack, ] of data.playlist[0].tracks.entries()) { const subtitleBlob = URL.createObjectURL( - await fetch(`${CORS_PROXY_URL}${subtitleTrack.file}`).then( + await fetch(`${conf().CORS_PROXY_URL}${subtitleTrack.file}`).then( (captionRes) => captionRes.blob() ) ); // do this so no need for CORS errors From c23c1feebc6b9f101bb485505385d8346206bdf0 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 27 Dec 2022 16:51:32 +0100 Subject: [PATCH 3/7] linting fixes --- .eslintrc.js | 2 +- .gitignore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d45d17f9..d7dcebbb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,7 +18,7 @@ module.exports = { typescript: {} } }, - ignorePatterns: ["public/*", "/*.js", "/*.ts"], + ignorePatterns: ["public/*", "dist/*", "/*.js", "/*.ts"], parser: "@typescript-eslint/parser", parserOptions: { project: "./tsconfig.json", diff --git a/.gitignore b/.gitignore index 26059563..24ee5531 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ node_modules /coverage # production -/build +/dist # misc .DS_Store From d73ee207da17fcf0f4aa4481462e81b0f8a532a4 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 27 Dec 2022 16:57:11 +0100 Subject: [PATCH 4/7] slash comments --- SELFHOSTING.md | 4 ++-- public/config.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SELFHOSTING.md b/SELFHOSTING.md index 4718b9c0..7137be1f 100644 --- a/SELFHOSTING.md +++ b/SELFHOSTING.md @@ -29,9 +29,9 @@ 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) 2. Extract the zip file so you can edit the files. 3. Open `config.js` in notepad, VScode or similar. -4. Put your cloudflare proxy URL inbetween the double qoutes of `VITE_CORS_PROXY_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 Your client has been prepared, you can now host it on any webhost. diff --git a/public/config.js b/public/config.js index 463fdd2c..9ffc51ab 100644 --- a/public/config.js +++ b/public/config.js @@ -1,5 +1,7 @@ window.__CONFIG__ = { + // url must NOT end with a slash VITE_CORS_PROXY_URL: "", + VITE_TMDB_API_KEY: "b030404650f279792a8d3287232358e3", VITE_OMDB_API_KEY: "aa0937c0" }; From ffcba436d7065a367e99d482f6809de48641562b Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 27 Dec 2022 17:02:12 +0100 Subject: [PATCH 5/7] update deploy script with new config system --- .github/workflows/deploying.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploying.yml b/.github/workflows/deploying.yml index 07a78f25..a9f5152c 100644 --- a/.github/workflows/deploying.yml +++ b/.github/workflows/deploying.yml @@ -42,7 +42,10 @@ jobs: with: name: production-files path: ./dist - + - name: Insert config + env: + DEPLOY_CONFIG: ${{ secrets.DEPLOY_CONFIG }} + run: cat "$DEPLOY_CONFIG" > ./dist/config.js - name: Deploy to gh-pages uses: peaceiris/actions-gh-pages@v3 with: From 131706e2bb9ebfe7b0df76642cce50f41514e970 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 27 Dec 2022 17:08:01 +0100 Subject: [PATCH 6/7] bump version --- package.json | 2 +- src/mw_constants.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/mw_constants.ts diff --git a/package.json b/package.json index f264ca15..373f8020 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "movie-web", - "version": "2.1.0", + "version": "2.1.1", "private": true, "homepage": "https://movie.squeezebox.dev", "dependencies": { diff --git a/src/mw_constants.ts b/src/mw_constants.ts new file mode 100644 index 00000000..5e325ebd --- /dev/null +++ b/src/mw_constants.ts @@ -0,0 +1,3 @@ +export const DISCORD_LINK = "https://discord.gg/Jhqt4Xzpfb"; +export const GITHUB_LINK = "https://github.com/JamesHawkinss/movie-web"; +export const APP_VERSION = "2.1.1"; From 93cb97b304efa1bc818e66b6cb95fc06250751a3 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Tue, 27 Dec 2022 17:26:14 +0100 Subject: [PATCH 7/7] formatting deploying.yml --- .github/workflows/deploying.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploying.yml b/.github/workflows/deploying.yml index a9f5152c..61f9ce0b 100644 --- a/.github/workflows/deploying.yml +++ b/.github/workflows/deploying.yml @@ -42,10 +42,12 @@ jobs: with: name: production-files path: ./dist + - name: Insert config env: DEPLOY_CONFIG: ${{ secrets.DEPLOY_CONFIG }} run: cat "$DEPLOY_CONFIG" > ./dist/config.js + - name: Deploy to gh-pages uses: peaceiris/actions-gh-pages@v3 with: