Add new `proxy-blocked` flag and update proxy

This commit is contained in:
TPN 2024-07-03 07:58:15 +01:00
parent 97f34011fc
commit d8bbe3bb5e
No known key found for this signature in database
GPG Key ID: 40AE091637892B91
3 changed files with 17 additions and 4 deletions

View File

@ -24,7 +24,11 @@ export interface ProviderMakerOptions {
}
export function makeProviders(ops: ProviderMakerOptions) {
const features = getTargetFeatures(ops.proxyStreams ? 'any' : ops.target, ops.consistentIpForRequests ?? false);
const features = getTargetFeatures(
ops.proxyStreams ? 'any' : ops.target,
ops.consistentIpForRequests ?? false,
ops.proxyStreams ?? false,
);
const list = getProviders(features, {
embeds: getBuiltinEmbeds(),
sources: getBuiltinSources(),

View File

@ -9,6 +9,10 @@ export const flags = {
// The source/embed is blocking cloudflare ip's
// This flag is not compatible with a proxy hosted on cloudflare
CF_BLOCKED: 'cf-blocked',
// Streams and sources with this flag wont be proxied
// And will be exclusive to the extension
PROXY_BLOCKED: 'proxy-blocked',
} as const;
export type Flags = (typeof flags)[keyof typeof flags];
@ -53,9 +57,14 @@ export const targetToFeatures: Record<Targets, FeatureMap> = {
},
};
export function getTargetFeatures(target: Targets, consistentIpForRequests: boolean): FeatureMap {
export function getTargetFeatures(
target: Targets,
consistentIpForRequests: boolean,
proxyStreams: boolean,
): FeatureMap {
const features = targetToFeatures[target];
if (!consistentIpForRequests) features.disallowed.push(flags.IP_LOCKED);
if (proxyStreams) features.disallowed.push(flags.PROXY_BLOCKED);
return features;
}

View File

@ -14,11 +14,11 @@ export function setupProxy(stream: Stream): Stream {
: null;
if (stream.type === 'hls')
stream.playlist = `https://swallow.prawnhub.ru/${encodeURIComponent(stream.playlist)}/${headers}`;
stream.playlist = `https://proxy.nsbx.ru/hls/${encodeURIComponent(stream.playlist)}/${headers}`;
if (stream.type === 'file')
Object.entries(stream.qualities).forEach((entry) => {
entry[1].url = `https://mp4proxy.nsbxru.workers.dev/proxy/${encodeURIComponent(entry[1].url)}/${headers}`;
entry[1].url = `https://proxy.nsbx.ru/mp4/${encodeURIComponent(entry[1].url)}/${headers}`;
});
stream.headers = {};