mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-26 15:51:51 +01:00
Merge pull request #597 from movie-web/cdn-replacements
CDN replacements
This commit is contained in:
commit
f3b0545881
@ -12,6 +12,7 @@ import {
|
|||||||
SourceQuality,
|
SourceQuality,
|
||||||
getPreferredQuality,
|
getPreferredQuality,
|
||||||
} from "@/stores/player/utils/qualities";
|
} from "@/stores/player/utils/qualities";
|
||||||
|
import { processCdnLink } from "@/utils/cdn";
|
||||||
import {
|
import {
|
||||||
canChangeVolume,
|
canChangeVolume,
|
||||||
canFullscreen,
|
canFullscreen,
|
||||||
@ -101,7 +102,7 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
|||||||
function setupSource(vid: HTMLVideoElement, src: LoadableSource) {
|
function setupSource(vid: HTMLVideoElement, src: LoadableSource) {
|
||||||
if (src.type === "hls") {
|
if (src.type === "hls") {
|
||||||
if (canPlayHlsNatively(vid)) {
|
if (canPlayHlsNatively(vid)) {
|
||||||
vid.src = src.url;
|
vid.src = processCdnLink(src.url);
|
||||||
vid.currentTime = startAt;
|
vid.currentTime = startAt;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -151,12 +152,12 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hls.attachMedia(vid);
|
hls.attachMedia(vid);
|
||||||
hls.loadSource(src.url);
|
hls.loadSource(processCdnLink(src.url));
|
||||||
vid.currentTime = startAt;
|
vid.currentTime = startAt;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vid.src = src.url;
|
vid.src = processCdnLink(src.url);
|
||||||
vid.currentTime = startAt;
|
vid.currentTime = startAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
DisplayMeta,
|
DisplayMeta,
|
||||||
} from "@/components/player/display/displayInterface";
|
} from "@/components/player/display/displayInterface";
|
||||||
import { LoadableSource } from "@/stores/player/utils/qualities";
|
import { LoadableSource } from "@/stores/player/utils/qualities";
|
||||||
|
import { processCdnLink } from "@/utils/cdn";
|
||||||
import {
|
import {
|
||||||
canChangeVolume,
|
canChangeVolume,
|
||||||
canFullscreen,
|
canFullscreen,
|
||||||
@ -112,7 +113,7 @@ export function makeChromecastDisplayInterface(
|
|||||||
metaData.title = meta.title;
|
metaData.title = meta.title;
|
||||||
|
|
||||||
const mediaInfo = new chrome.cast.media.MediaInfo("video", type);
|
const mediaInfo = new chrome.cast.media.MediaInfo("video", type);
|
||||||
(mediaInfo as any).contentUrl = source.url;
|
(mediaInfo as any).contentUrl = processCdnLink(source.url);
|
||||||
mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED;
|
mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED;
|
||||||
mediaInfo.metadata = metaData;
|
mediaInfo.metadata = metaData;
|
||||||
mediaInfo.customData = {
|
mediaInfo.customData = {
|
||||||
|
@ -5,6 +5,7 @@ import { playerStatus } from "@/stores/player/slices/source";
|
|||||||
import { ThumbnailImage } from "@/stores/player/slices/thumbnails";
|
import { ThumbnailImage } from "@/stores/player/slices/thumbnails";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities";
|
import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities";
|
||||||
|
import { processCdnLink } from "@/utils/cdn";
|
||||||
import { isSafari } from "@/utils/detectFeatures";
|
import { isSafari } from "@/utils/detectFeatures";
|
||||||
|
|
||||||
function makeQueue(layers: number): number[] {
|
function makeQueue(layers: number): number[] {
|
||||||
@ -46,11 +47,11 @@ class ThumnbnailWorker {
|
|||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
this.hls = new Hls();
|
this.hls = new Hls();
|
||||||
if (source.type === "mp4") {
|
if (source.type === "mp4") {
|
||||||
el.src = source.url;
|
el.src = processCdnLink(source.url);
|
||||||
el.crossOrigin = "anonymous";
|
el.crossOrigin = "anonymous";
|
||||||
} else if (source.type === "hls") {
|
} else if (source.type === "hls") {
|
||||||
this.hls.attachMedia(el);
|
this.hls.attachMedia(el);
|
||||||
this.hls.loadSource(source.url);
|
this.hls.loadSource(processCdnLink(source.url));
|
||||||
} else throw new Error("Invalid loadable source type");
|
} else throw new Error("Invalid loadable source type");
|
||||||
this.videoEl = el;
|
this.videoEl = el;
|
||||||
this.canvasEl = canvas;
|
this.canvasEl = canvas;
|
||||||
|
@ -18,6 +18,7 @@ interface Config {
|
|||||||
BACKEND_URL: string;
|
BACKEND_URL: string;
|
||||||
DISALLOWED_IDS: string;
|
DISALLOWED_IDS: string;
|
||||||
TURNSTILE_KEY: string;
|
TURNSTILE_KEY: string;
|
||||||
|
CDN_REPLACEMENTS: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RuntimeConfig {
|
export interface RuntimeConfig {
|
||||||
@ -32,6 +33,7 @@ export interface RuntimeConfig {
|
|||||||
BACKEND_URL: string;
|
BACKEND_URL: string;
|
||||||
DISALLOWED_IDS: string[];
|
DISALLOWED_IDS: string[];
|
||||||
TURNSTILE_KEY: string | null;
|
TURNSTILE_KEY: string | null;
|
||||||
|
CDN_REPLACEMENTS: Array<string[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const env: Record<keyof Config, undefined | string> = {
|
const env: Record<keyof Config, undefined | string> = {
|
||||||
@ -46,6 +48,7 @@ const env: Record<keyof Config, undefined | string> = {
|
|||||||
BACKEND_URL: import.meta.env.VITE_BACKEND_URL,
|
BACKEND_URL: import.meta.env.VITE_BACKEND_URL,
|
||||||
DISALLOWED_IDS: import.meta.env.VITE_DISALLOWED_IDS,
|
DISALLOWED_IDS: import.meta.env.VITE_DISALLOWED_IDS,
|
||||||
TURNSTILE_KEY: import.meta.env.VITE_TURNSTILE_KEY,
|
TURNSTILE_KEY: import.meta.env.VITE_TURNSTILE_KEY,
|
||||||
|
CDN_REPLACEMENTS: import.meta.env.VITE_CDN_REPLACEMENTS,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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)
|
||||||
@ -84,5 +87,14 @@ export function conf(): RuntimeConfig {
|
|||||||
.split(",")
|
.split(",")
|
||||||
.map((v) => v.trim())
|
.map((v) => v.trim())
|
||||||
.filter((v) => v.length > 0), // Should be comma-seperated and contain the media type and ID, formatted like so: movie-753342,movie-753342,movie-753342
|
.filter((v) => v.length > 0), // Should be comma-seperated and contain the media type and ID, formatted like so: movie-753342,movie-753342,movie-753342
|
||||||
|
CDN_REPLACEMENTS: getKey("CDN_REPLACEMENTS", "")
|
||||||
|
.split(",")
|
||||||
|
.map((v) =>
|
||||||
|
v
|
||||||
|
.split(":")
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter((s) => s.length > 0),
|
||||||
|
)
|
||||||
|
.filter((v) => v.length === 2), // The format is <beforeA>:<afterA>,<beforeB>:<afterB>
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
16
src/utils/cdn.ts
Normal file
16
src/utils/cdn.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { conf } from "@/setup/config";
|
||||||
|
|
||||||
|
export function processCdnLink(url: string): string {
|
||||||
|
const parsedUrl = new URL(url);
|
||||||
|
const replacements = conf().CDN_REPLACEMENTS;
|
||||||
|
for (const [before, after] of replacements) {
|
||||||
|
if (parsedUrl.hostname.endsWith(before)) {
|
||||||
|
parsedUrl.hostname = after;
|
||||||
|
parsedUrl.port = "";
|
||||||
|
parsedUrl.protocol = "https://";
|
||||||
|
return parsedUrl.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user