mirror of
https://github.com/sussy-code/providers.git
synced 2026-04-21 08:31:57 +00:00
Support proxy on runners
This commit is contained in:
parent
53534cb5ff
commit
0f95ed0b20
4 changed files with 36 additions and 6 deletions
|
|
@ -31,8 +31,6 @@ export interface RunnerOptions {
|
||||||
|
|
||||||
// the media you want to see sources from
|
// the media you want to see sources from
|
||||||
media: ScrapeMedia;
|
media: ScrapeMedia;
|
||||||
|
|
||||||
proxyStreams?: boolean; // temporary
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SourceRunnerOptions {
|
export interface SourceRunnerOptions {
|
||||||
|
|
@ -44,8 +42,6 @@ export interface SourceRunnerOptions {
|
||||||
|
|
||||||
// id of the source scraper you want to scrape from
|
// id of the source scraper you want to scrape from
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
proxyStreams?: boolean; // temporary
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EmbedRunnerOptions {
|
export interface EmbedRunnerOptions {
|
||||||
|
|
@ -57,8 +53,6 @@ export interface EmbedRunnerOptions {
|
||||||
|
|
||||||
// id of the embed scraper you want to scrape from
|
// id of the embed scraper you want to scrape from
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
proxyStreams?: boolean; // temporary
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProviderControls {
|
export interface ProviderControls {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { ProviderList } from '@/providers/get';
|
||||||
import { ScrapeContext } from '@/utils/context';
|
import { ScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
||||||
|
import { requiresProxy, setupProxy } from '@/utils/proxy';
|
||||||
import { isValidStream, validatePlayableStreams } from '@/utils/valid';
|
import { isValidStream, validatePlayableStreams } from '@/utils/valid';
|
||||||
|
|
||||||
export type IndividualSourceRunnerOptions = {
|
export type IndividualSourceRunnerOptions = {
|
||||||
|
|
@ -16,6 +17,7 @@ export type IndividualSourceRunnerOptions = {
|
||||||
media: ScrapeMedia;
|
media: ScrapeMedia;
|
||||||
id: string;
|
id: string;
|
||||||
events?: IndividualScraperEvents;
|
events?: IndividualScraperEvents;
|
||||||
|
proxyStreams?: boolean; // temporary
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function scrapeInvidualSource(
|
export async function scrapeInvidualSource(
|
||||||
|
|
@ -56,6 +58,10 @@ export async function scrapeInvidualSource(
|
||||||
output.stream = output.stream
|
output.stream = output.stream
|
||||||
.filter((stream) => isValidStream(stream))
|
.filter((stream) => isValidStream(stream))
|
||||||
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
||||||
|
|
||||||
|
output.stream = output.stream.map((stream) =>
|
||||||
|
requiresProxy(stream) && ops.proxyStreams ? setupProxy(stream) : stream,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output) throw new Error('output is null');
|
if (!output) throw new Error('output is null');
|
||||||
|
|
@ -107,6 +113,7 @@ export type IndividualEmbedRunnerOptions = {
|
||||||
url: string;
|
url: string;
|
||||||
id: string;
|
id: string;
|
||||||
events?: IndividualScraperEvents;
|
events?: IndividualScraperEvents;
|
||||||
|
proxyStreams?: boolean; // temporary
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function scrapeIndividualEmbed(
|
export async function scrapeIndividualEmbed(
|
||||||
|
|
@ -138,6 +145,10 @@ export async function scrapeIndividualEmbed(
|
||||||
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
||||||
if (output.stream.length === 0) throw new NotFoundError('No streams found');
|
if (output.stream.length === 0) throw new NotFoundError('No streams found');
|
||||||
|
|
||||||
|
output.stream = output.stream.map((stream) =>
|
||||||
|
requiresProxy(stream) && ops.proxyStreams ? setupProxy(stream) : stream,
|
||||||
|
);
|
||||||
|
|
||||||
const playableStreams = await validatePlayableStreams(output.stream, ops, embedScraper.id);
|
const playableStreams = await validatePlayableStreams(output.stream, ops, embedScraper.id);
|
||||||
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
|
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { ScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
import { reorderOnIdList } from '@/utils/list';
|
import { reorderOnIdList } from '@/utils/list';
|
||||||
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
||||||
|
import { requiresProxy, setupProxy } from '@/utils/proxy';
|
||||||
import { isValidStream, validatePlayableStream } from '@/utils/valid';
|
import { isValidStream, validatePlayableStream } from '@/utils/valid';
|
||||||
|
|
||||||
export type RunOutput = {
|
export type RunOutput = {
|
||||||
|
|
@ -36,6 +37,7 @@ export type ProviderRunnerOptions = {
|
||||||
embedOrder?: string[];
|
embedOrder?: string[];
|
||||||
events?: FullScraperEvents;
|
events?: FullScraperEvents;
|
||||||
media: ScrapeMedia;
|
media: ScrapeMedia;
|
||||||
|
proxyStreams?: boolean; // temporary
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOptions): Promise<RunOutput | null> {
|
export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOptions): Promise<RunOutput | null> {
|
||||||
|
|
@ -85,6 +87,10 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
||||||
output.stream = (output.stream ?? [])
|
output.stream = (output.stream ?? [])
|
||||||
.filter(isValidStream)
|
.filter(isValidStream)
|
||||||
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
||||||
|
|
||||||
|
output.stream = output.stream.map((stream) =>
|
||||||
|
requiresProxy(stream) && ops.proxyStreams ? setupProxy(stream) : stream,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!output || (!output.stream?.length && !output.embeds.length)) {
|
if (!output || (!output.stream?.length && !output.embeds.length)) {
|
||||||
throw new NotFoundError('No streams found');
|
throw new NotFoundError('No streams found');
|
||||||
|
|
@ -161,6 +167,9 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
||||||
embedOutput.stream = embedOutput.stream
|
embedOutput.stream = embedOutput.stream
|
||||||
.filter(isValidStream)
|
.filter(isValidStream)
|
||||||
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
|
||||||
|
embedOutput.stream = embedOutput.stream.map((stream) =>
|
||||||
|
requiresProxy(stream) && ops.proxyStreams ? setupProxy(stream) : stream,
|
||||||
|
);
|
||||||
if (embedOutput.stream.length === 0) {
|
if (embedOutput.stream.length === 0) {
|
||||||
throw new NotFoundError('No streams found');
|
throw new NotFoundError('No streams found');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
src/utils/proxy.ts
Normal file
16
src/utils/proxy.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { flags } from '@/entrypoint/utils/targets';
|
||||||
|
import { Stream } from '@/providers/streams';
|
||||||
|
|
||||||
|
export function requiresProxy(stream: Stream): boolean {
|
||||||
|
if (!stream.flags.includes('cors-allowed') && !!(stream.headers && Object.keys(stream.headers).length > 0))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupProxy(stream: Stream): Stream {
|
||||||
|
// todo
|
||||||
|
|
||||||
|
// stream.headers = {};
|
||||||
|
stream.flags = [flags.CORS_ALLOWED];
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue