Skip to content

Commit ab0b9f2

Browse files
committed
Add support for 'External Sources'
1 parent 0d43ece commit ab0b9f2

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

src/dev-cli/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { prompt } from 'enquirer';
77
import { runScraper } from '@/dev-cli/scraper';
88
import { processOptions } from '@/dev-cli/validate';
99

10-
import { getBuiltinEmbeds, getBuiltinSources } from '..';
10+
import { getBuiltinEmbeds, getBuiltinExternalSources, getBuiltinSources } from '..';
1111

1212
dotenv.config();
1313

@@ -30,7 +30,7 @@ type ShowAnswers = {
3030
episode: string;
3131
};
3232

33-
const sourceScrapers = getBuiltinSources().sort((a, b) => b.rank - a.rank);
33+
const sourceScrapers = [...getBuiltinSources(), ...getBuiltinExternalSources()].sort((a, b) => b.rank - a.rank);
3434
const embedScrapers = getBuiltinEmbeds().sort((a, b) => b.rank - a.rank);
3535
const sources = [...sourceScrapers, ...embedScrapers];
3636

src/dev-cli/validate.ts

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export async function processOptions(sources: Array<Embed | Sourcerer>, options:
8282
fetcher,
8383
target: targets.ANY,
8484
consistentIpForRequests: true,
85+
externalSources: 'all',
8586
};
8687

8788
return {

src/entrypoint/builder.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ProviderControls, makeControls } from '@/entrypoint/controls';
2-
import { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers';
2+
import { getBuiltinEmbeds, getBuiltinExternalSources, getBuiltinSources } from '@/entrypoint/providers';
33
import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets';
44
import { Fetcher } from '@/fetchers/types';
55
import { Embed, Sourcerer } from '@/providers/base';
@@ -26,6 +26,7 @@ export function buildProviders(): ProviderBuilder {
2626
const embeds: Embed[] = [];
2727
const sources: Sourcerer[] = [];
2828
const builtinSources = getBuiltinSources();
29+
const builtinExternalSources = getBuiltinExternalSources();
2930
const builtinEmbeds = getBuiltinEmbeds();
3031

3132
return {
@@ -51,7 +52,7 @@ export function buildProviders(): ProviderBuilder {
5152
return this;
5253
}
5354

54-
const matchingSource = builtinSources.find((v) => v.id === input);
55+
const matchingSource = [...builtinSources, ...builtinExternalSources].find((v) => v.id === input);
5556
if (!matchingSource) throw new Error('Source not found');
5657
sources.push(matchingSource);
5758
return this;

src/entrypoint/declare.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeControls } from '@/entrypoint/controls';
2-
import { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers';
2+
import { getBuiltinEmbeds, getBuiltinExternalSources, getBuiltinSources } from '@/entrypoint/providers';
33
import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets';
44
import { Fetcher } from '@/fetchers/types';
55
import { getProviders } from '@/providers/get';
@@ -19,6 +19,9 @@ export interface ProviderMakerOptions {
1919
// the device that the stream will be played on
2020
consistentIpForRequests?: boolean;
2121

22+
// used to add built in sources which aren't used by default aka external sources
23+
externalSources?: 'all' | string[];
24+
2225
// This is temporary
2326
proxyStreams?: boolean;
2427
}
@@ -29,9 +32,21 @@ export function makeProviders(ops: ProviderMakerOptions) {
2932
ops.consistentIpForRequests ?? false,
3033
ops.proxyStreams,
3134
);
35+
36+
const sources = [...getBuiltinSources()];
37+
38+
if (ops.externalSources === 'all') sources.push(...getBuiltinExternalSources());
39+
else {
40+
ops.externalSources?.forEach((source) => {
41+
const matchingSource = getBuiltinExternalSources().find((v) => v.id === source);
42+
if (!matchingSource) return;
43+
sources.push(matchingSource);
44+
});
45+
}
46+
3247
const list = getProviders(features, {
3348
embeds: getBuiltinEmbeds(),
34-
sources: getBuiltinSources(),
49+
sources,
3550
});
3651

3752
return makeControls({

src/entrypoint/providers.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { gatherAllEmbeds, gatherAllSources } from '@/providers/all';
22
import { Embed, Sourcerer } from '@/providers/base';
33

44
export function getBuiltinSources(): Sourcerer[] {
5-
return gatherAllSources().filter((v) => !v.disabled);
5+
return gatherAllSources().filter((v) => !v.disabled && !v.externalSource);
6+
}
7+
export function getBuiltinExternalSources(): Sourcerer[] {
8+
return gatherAllSources().filter((v) => v.externalSource && !v.disabled);
69
}
710

811
export function getBuiltinEmbeds(): Embed[] {

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type { SourcererOptions, EmbedOptions } from '@/providers/base';
1515
export { NotFoundError } from '@/utils/errors';
1616
export { makeProviders } from '@/entrypoint/declare';
1717
export { buildProviders } from '@/entrypoint/builder';
18-
export { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers';
18+
export { getBuiltinEmbeds, getBuiltinSources, getBuiltinExternalSources } from '@/entrypoint/providers';
1919
export { makeStandardFetcher } from '@/fetchers/standardFetch';
2020
export { makeSimpleProxyFetcher } from '@/fetchers/simpleProxy';
2121
export { flags, targets } from '@/entrypoint/utils/targets';

src/providers/base.ts

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export type SourcererOptions = {
1919
name: string; // displayed in the UI
2020
rank: number; // the higher the number, the earlier it gets put on the queue
2121
disabled?: boolean;
22+
// these sources are built in but not used by default
23+
// this can have many uses, we use this for sources that only work on official instances
24+
externalSource?: boolean;
2225
flags: Flags[];
2326
scrapeMovie?: (input: MovieScrapeContext) => Promise<SourcererOutput>;
2427
scrapeShow?: (input: ShowScrapeContext) => Promise<SourcererOutput>;
@@ -27,6 +30,7 @@ export type SourcererOptions = {
2730
export type Sourcerer = SourcererOptions & {
2831
type: 'source';
2932
disabled: boolean;
33+
externalSource: boolean;
3034
mediaTypes: MediaScraperTypes[];
3135
};
3236

@@ -38,6 +42,7 @@ export function makeSourcerer(state: SourcererOptions): Sourcerer {
3842
...state,
3943
type: 'source',
4044
disabled: state.disabled ?? false,
45+
externalSource: state.externalSource ?? false,
4146
mediaTypes,
4247
};
4348
}

0 commit comments

Comments
 (0)