mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 17:55:33 +00:00
init m3u8 proxy rotation
This commit is contained in:
parent
963af9306f
commit
bd97db1fbd
4 changed files with 36 additions and 2 deletions
|
|
@ -1,8 +1,16 @@
|
|||
import { Fetcher, makeSimpleProxyFetcher } from "@movie-web/providers";
|
||||
import {
|
||||
Fetcher,
|
||||
makeSimpleProxyFetcher,
|
||||
setM3U8ProxyUrl,
|
||||
} from "@movie-web/providers";
|
||||
|
||||
import { sendExtensionRequest } from "@/backend/extension/messaging";
|
||||
import { getApiToken, setApiToken } from "@/backend/helpers/providerApi";
|
||||
import { getProviderApiUrls, getProxyUrls } from "@/utils/proxyUrls";
|
||||
import {
|
||||
getM3U8ProxyUrls,
|
||||
getProviderApiUrls,
|
||||
getProxyUrls,
|
||||
} from "@/utils/proxyUrls";
|
||||
|
||||
import { convertBodyToObject, getBodyTypeFromBody } from "../extension/request";
|
||||
|
||||
|
|
@ -22,6 +30,8 @@ function makeLoadbalancedList(getter: () => string[]) {
|
|||
export const getLoadbalancedProxyUrl = makeLoadbalancedList(getProxyUrls);
|
||||
export const getLoadbalancedProviderApiUrl =
|
||||
makeLoadbalancedList(getProviderApiUrls);
|
||||
export const getLoadbalancedM3U8ProxyUrl =
|
||||
makeLoadbalancedList(getM3U8ProxyUrls);
|
||||
|
||||
async function fetchButWithApiTokens(
|
||||
input: RequestInfo | URL,
|
||||
|
|
@ -44,6 +54,13 @@ async function fetchButWithApiTokens(
|
|||
return response;
|
||||
}
|
||||
|
||||
export function setupM3U8Proxy() {
|
||||
const proxyUrl = getLoadbalancedM3U8ProxyUrl();
|
||||
if (proxyUrl) {
|
||||
setM3U8ProxyUrl(proxyUrl);
|
||||
}
|
||||
}
|
||||
|
||||
export function makeLoadBalancedSimpleProxyFetcher() {
|
||||
const fetcher: Fetcher = async (a, b) => {
|
||||
const currentFetcher = makeSimpleProxyFetcher(
|
||||
|
|
|
|||
|
|
@ -8,8 +8,12 @@ import { isExtensionActiveCached } from "@/backend/extension/messaging";
|
|||
import {
|
||||
makeExtensionFetcher,
|
||||
makeLoadBalancedSimpleProxyFetcher,
|
||||
setupM3U8Proxy,
|
||||
} from "@/backend/providers/fetchers";
|
||||
|
||||
// Initialize M3U8 proxy on module load
|
||||
setupM3U8Proxy();
|
||||
|
||||
export function getProviders() {
|
||||
if (isExtensionActiveCached()) {
|
||||
return makeProviders({
|
||||
|
|
@ -20,6 +24,8 @@ export function getProviders() {
|
|||
});
|
||||
}
|
||||
|
||||
setupM3U8Proxy();
|
||||
|
||||
return makeProviders({
|
||||
fetcher: makeStandardFetcher(fetch),
|
||||
proxiedFetcher: makeLoadBalancedSimpleProxyFetcher(),
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ interface Config {
|
|||
TWITTER_LINK: string;
|
||||
TMDB_READ_API_KEY: string;
|
||||
CORS_PROXY_URL: string;
|
||||
M3U8_PROXY_URL: string;
|
||||
NORMAL_ROUTER: boolean;
|
||||
BACKEND_URL: string;
|
||||
DISALLOWED_IDS: string;
|
||||
|
|
@ -39,6 +40,7 @@ export interface RuntimeConfig {
|
|||
TMDB_READ_API_KEY: string | null;
|
||||
NORMAL_ROUTER: boolean;
|
||||
PROXY_URLS: string[];
|
||||
M3U8_PROXY_URLS: string[];
|
||||
BACKEND_URL: string | null;
|
||||
DISALLOWED_IDS: string[];
|
||||
TURNSTILE_KEY: string | null;
|
||||
|
|
@ -68,6 +70,7 @@ const env: Record<keyof Config, undefined | string> = {
|
|||
.VITE_ONBOARDING_PROXY_INSTALL_LINK,
|
||||
DMCA_EMAIL: import.meta.env.VITE_DMCA_EMAIL,
|
||||
CORS_PROXY_URL: import.meta.env.VITE_CORS_PROXY_URL,
|
||||
M3U8_PROXY_URL: import.meta.env.VITE_M3U8_PROXY_URL,
|
||||
NORMAL_ROUTER: import.meta.env.VITE_NORMAL_ROUTER,
|
||||
BACKEND_URL: import.meta.env.VITE_BACKEND_URL,
|
||||
DISALLOWED_IDS: import.meta.env.VITE_DISALLOWED_IDS,
|
||||
|
|
@ -122,6 +125,10 @@ export function conf(): RuntimeConfig {
|
|||
.split(",")
|
||||
.map((v) => v.trim())
|
||||
.filter((v) => v.length > 0),
|
||||
M3U8_PROXY_URLS: getKey("M3U8_PROXY_URL", "")
|
||||
.split(",")
|
||||
.map((v) => v.trim())
|
||||
.filter((v) => v.length > 0),
|
||||
NORMAL_ROUTER: getKey("NORMAL_ROUTER", "false") === "true",
|
||||
HAS_ONBOARDING: getKey("HAS_ONBOARDING", "false") === "true",
|
||||
ALLOW_AUTOPLAY: getKey("ALLOW_AUTOPLAY", "false") === "true",
|
||||
|
|
|
|||
|
|
@ -70,6 +70,10 @@ export function getProxyUrls() {
|
|||
.map((v) => v.url);
|
||||
}
|
||||
|
||||
export function getM3U8ProxyUrls(): string[] {
|
||||
return conf().M3U8_PROXY_URLS;
|
||||
}
|
||||
|
||||
export function getProviderApiUrls() {
|
||||
return getParsedUrls()
|
||||
.filter((v) => v.type === "api")
|
||||
|
|
|
|||
Loading…
Reference in a new issue