mirror of
https://github.com/sussy-code/providers.git
synced 2026-05-12 21:00:38 +00:00
Add support for 'External Sources'
This commit is contained in:
parent
0d43eceaf2
commit
ab0b9f2e73
7 changed files with 33 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ import { prompt } from 'enquirer';
|
||||||
import { runScraper } from '@/dev-cli/scraper';
|
import { runScraper } from '@/dev-cli/scraper';
|
||||||
import { processOptions } from '@/dev-cli/validate';
|
import { processOptions } from '@/dev-cli/validate';
|
||||||
|
|
||||||
import { getBuiltinEmbeds, getBuiltinSources } from '..';
|
import { getBuiltinEmbeds, getBuiltinExternalSources, getBuiltinSources } from '..';
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ type ShowAnswers = {
|
||||||
episode: string;
|
episode: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sourceScrapers = getBuiltinSources().sort((a, b) => b.rank - a.rank);
|
const sourceScrapers = [...getBuiltinSources(), ...getBuiltinExternalSources()].sort((a, b) => b.rank - a.rank);
|
||||||
const embedScrapers = getBuiltinEmbeds().sort((a, b) => b.rank - a.rank);
|
const embedScrapers = getBuiltinEmbeds().sort((a, b) => b.rank - a.rank);
|
||||||
const sources = [...sourceScrapers, ...embedScrapers];
|
const sources = [...sourceScrapers, ...embedScrapers];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ export async function processOptions(sources: Array<Embed | Sourcerer>, options:
|
||||||
fetcher,
|
fetcher,
|
||||||
target: targets.ANY,
|
target: targets.ANY,
|
||||||
consistentIpForRequests: true,
|
consistentIpForRequests: true,
|
||||||
|
externalSources: 'all',
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { ProviderControls, makeControls } from '@/entrypoint/controls';
|
import { ProviderControls, makeControls } from '@/entrypoint/controls';
|
||||||
import { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers';
|
import { getBuiltinEmbeds, getBuiltinExternalSources, getBuiltinSources } from '@/entrypoint/providers';
|
||||||
import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets';
|
import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets';
|
||||||
import { Fetcher } from '@/fetchers/types';
|
import { Fetcher } from '@/fetchers/types';
|
||||||
import { Embed, Sourcerer } from '@/providers/base';
|
import { Embed, Sourcerer } from '@/providers/base';
|
||||||
|
|
@ -26,6 +26,7 @@ export function buildProviders(): ProviderBuilder {
|
||||||
const embeds: Embed[] = [];
|
const embeds: Embed[] = [];
|
||||||
const sources: Sourcerer[] = [];
|
const sources: Sourcerer[] = [];
|
||||||
const builtinSources = getBuiltinSources();
|
const builtinSources = getBuiltinSources();
|
||||||
|
const builtinExternalSources = getBuiltinExternalSources();
|
||||||
const builtinEmbeds = getBuiltinEmbeds();
|
const builtinEmbeds = getBuiltinEmbeds();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -51,7 +52,7 @@ export function buildProviders(): ProviderBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const matchingSource = builtinSources.find((v) => v.id === input);
|
const matchingSource = [...builtinSources, ...builtinExternalSources].find((v) => v.id === input);
|
||||||
if (!matchingSource) throw new Error('Source not found');
|
if (!matchingSource) throw new Error('Source not found');
|
||||||
sources.push(matchingSource);
|
sources.push(matchingSource);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { makeControls } from '@/entrypoint/controls';
|
import { makeControls } from '@/entrypoint/controls';
|
||||||
import { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers';
|
import { getBuiltinEmbeds, getBuiltinExternalSources, getBuiltinSources } from '@/entrypoint/providers';
|
||||||
import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets';
|
import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets';
|
||||||
import { Fetcher } from '@/fetchers/types';
|
import { Fetcher } from '@/fetchers/types';
|
||||||
import { getProviders } from '@/providers/get';
|
import { getProviders } from '@/providers/get';
|
||||||
|
|
@ -19,6 +19,9 @@ export interface ProviderMakerOptions {
|
||||||
// the device that the stream will be played on
|
// the device that the stream will be played on
|
||||||
consistentIpForRequests?: boolean;
|
consistentIpForRequests?: boolean;
|
||||||
|
|
||||||
|
// used to add built in sources which aren't used by default aka external sources
|
||||||
|
externalSources?: 'all' | string[];
|
||||||
|
|
||||||
// This is temporary
|
// This is temporary
|
||||||
proxyStreams?: boolean;
|
proxyStreams?: boolean;
|
||||||
}
|
}
|
||||||
|
|
@ -29,9 +32,21 @@ export function makeProviders(ops: ProviderMakerOptions) {
|
||||||
ops.consistentIpForRequests ?? false,
|
ops.consistentIpForRequests ?? false,
|
||||||
ops.proxyStreams,
|
ops.proxyStreams,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const sources = [...getBuiltinSources()];
|
||||||
|
|
||||||
|
if (ops.externalSources === 'all') sources.push(...getBuiltinExternalSources());
|
||||||
|
else {
|
||||||
|
ops.externalSources?.forEach((source) => {
|
||||||
|
const matchingSource = getBuiltinExternalSources().find((v) => v.id === source);
|
||||||
|
if (!matchingSource) return;
|
||||||
|
sources.push(matchingSource);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const list = getProviders(features, {
|
const list = getProviders(features, {
|
||||||
embeds: getBuiltinEmbeds(),
|
embeds: getBuiltinEmbeds(),
|
||||||
sources: getBuiltinSources(),
|
sources,
|
||||||
});
|
});
|
||||||
|
|
||||||
return makeControls({
|
return makeControls({
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ import { gatherAllEmbeds, gatherAllSources } from '@/providers/all';
|
||||||
import { Embed, Sourcerer } from '@/providers/base';
|
import { Embed, Sourcerer } from '@/providers/base';
|
||||||
|
|
||||||
export function getBuiltinSources(): Sourcerer[] {
|
export function getBuiltinSources(): Sourcerer[] {
|
||||||
return gatherAllSources().filter((v) => !v.disabled);
|
return gatherAllSources().filter((v) => !v.disabled && !v.externalSource);
|
||||||
|
}
|
||||||
|
export function getBuiltinExternalSources(): Sourcerer[] {
|
||||||
|
return gatherAllSources().filter((v) => v.externalSource && !v.disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBuiltinEmbeds(): Embed[] {
|
export function getBuiltinEmbeds(): Embed[] {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export type { SourcererOptions, EmbedOptions } from '@/providers/base';
|
||||||
export { NotFoundError } from '@/utils/errors';
|
export { NotFoundError } from '@/utils/errors';
|
||||||
export { makeProviders } from '@/entrypoint/declare';
|
export { makeProviders } from '@/entrypoint/declare';
|
||||||
export { buildProviders } from '@/entrypoint/builder';
|
export { buildProviders } from '@/entrypoint/builder';
|
||||||
export { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers';
|
export { getBuiltinEmbeds, getBuiltinSources, getBuiltinExternalSources } from '@/entrypoint/providers';
|
||||||
export { makeStandardFetcher } from '@/fetchers/standardFetch';
|
export { makeStandardFetcher } from '@/fetchers/standardFetch';
|
||||||
export { makeSimpleProxyFetcher } from '@/fetchers/simpleProxy';
|
export { makeSimpleProxyFetcher } from '@/fetchers/simpleProxy';
|
||||||
export { flags, targets } from '@/entrypoint/utils/targets';
|
export { flags, targets } from '@/entrypoint/utils/targets';
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ export type SourcererOptions = {
|
||||||
name: string; // displayed in the UI
|
name: string; // displayed in the UI
|
||||||
rank: number; // the higher the number, the earlier it gets put on the queue
|
rank: number; // the higher the number, the earlier it gets put on the queue
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
// these sources are built in but not used by default
|
||||||
|
// this can have many uses, we use this for sources that only work on official instances
|
||||||
|
externalSource?: boolean;
|
||||||
flags: Flags[];
|
flags: Flags[];
|
||||||
scrapeMovie?: (input: MovieScrapeContext) => Promise<SourcererOutput>;
|
scrapeMovie?: (input: MovieScrapeContext) => Promise<SourcererOutput>;
|
||||||
scrapeShow?: (input: ShowScrapeContext) => Promise<SourcererOutput>;
|
scrapeShow?: (input: ShowScrapeContext) => Promise<SourcererOutput>;
|
||||||
|
|
@ -27,6 +30,7 @@ export type SourcererOptions = {
|
||||||
export type Sourcerer = SourcererOptions & {
|
export type Sourcerer = SourcererOptions & {
|
||||||
type: 'source';
|
type: 'source';
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
externalSource: boolean;
|
||||||
mediaTypes: MediaScraperTypes[];
|
mediaTypes: MediaScraperTypes[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -38,6 +42,7 @@ export function makeSourcerer(state: SourcererOptions): Sourcerer {
|
||||||
...state,
|
...state,
|
||||||
type: 'source',
|
type: 'source',
|
||||||
disabled: state.disabled ?? false,
|
disabled: state.disabled ?? false,
|
||||||
|
externalSource: state.externalSource ?? false,
|
||||||
mediaTypes,
|
mediaTypes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue