From 4a557b8140bf8cc5f8d3e3dc81a4b6454f13d7ef Mon Sep 17 00:00:00 2001 From: mrjvs Date: Mon, 25 Dec 2023 01:00:19 +0100 Subject: [PATCH] Add builder for adding custom sources --- .eslintrc.js | 2 +- src/__test__/providers/checks.test.ts | 38 ++++++-- src/__test__/runner/list.test.ts | 4 +- src/__test__/runner/meta.test.ts | 4 +- src/__test__/utils/features.test.ts | 2 +- src/entrypoint/builder.ts | 93 +++++++++++++++++++ .../builder.ts => entrypoint/controls.ts} | 43 ++++----- src/entrypoint/declare.ts | 37 ++++++++ src/entrypoint/providers.ts | 10 ++ src/{main => entrypoint/utils}/events.ts | 0 src/{main => entrypoint/utils}/media.ts | 0 src/{main => entrypoint/utils}/meta.ts | 2 +- src/{main => entrypoint/utils}/targets.ts | 6 +- src/index.ts | 26 +++--- src/providers/base.ts | 2 +- src/providers/embeds/febbox/common.ts | 2 +- src/providers/embeds/febbox/fileList.ts | 2 +- src/providers/embeds/febbox/hls.ts | 4 +- src/providers/embeds/febbox/mp4.ts | 2 +- src/providers/embeds/mp4upload.ts | 2 +- src/providers/embeds/smashystream/dued.ts | 2 +- src/providers/embeds/smashystream/video1.ts | 2 +- src/providers/embeds/streamsb.ts | 2 +- src/providers/embeds/upcloud.ts | 2 +- src/providers/embeds/upstream.ts | 2 +- src/providers/get.ts | 9 +- src/providers/sources/flixhq/index.ts | 2 +- src/providers/sources/flixhq/scrape.ts | 2 +- src/providers/sources/flixhq/search.ts | 2 +- src/providers/sources/gomovies/index.ts | 2 +- src/providers/sources/kissasian/index.ts | 2 +- src/providers/sources/lookmovie/index.ts | 2 +- src/providers/sources/lookmovie/type.ts | 2 +- src/providers/sources/lookmovie/util.ts | 2 +- src/providers/sources/lookmovie/video.ts | 2 +- src/providers/sources/remotestream.ts | 2 +- src/providers/sources/showbox/index.ts | 2 +- src/providers/sources/smashystream/index.ts | 2 +- src/providers/sources/zoechip/index.ts | 2 +- src/providers/sources/zoechip/scrape.ts | 2 +- src/providers/sources/zoechip/search.ts | 2 +- src/providers/streams.ts | 2 +- src/{main => runners}/individualRunner.ts | 6 +- src/{main => runners}/runner.ts | 6 +- src/utils/compare.ts | 2 +- src/utils/context.ts | 2 +- 46 files changed, 251 insertions(+), 97 deletions(-) create mode 100644 src/entrypoint/builder.ts rename src/{main/builder.ts => entrypoint/controls.ts} (68%) create mode 100644 src/entrypoint/declare.ts create mode 100644 src/entrypoint/providers.ts rename src/{main => entrypoint/utils}/events.ts (100%) rename src/{main => entrypoint/utils}/media.ts (100%) rename src/{main => entrypoint/utils}/meta.ts (96%) rename src/{main => entrypoint/utils}/targets.ts (85%) rename src/{main => runners}/individualRunner.ts (93%) rename src/{main => runners}/runner.ts (96%) diff --git a/.eslintrc.js b/.eslintrc.js index 7939452..0e7322b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { browser: true, }, extends: ['airbnb-base', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], - ignorePatterns: ['lib/*', 'tests/*', '/*.js', '/*.ts', '/**/*.test.ts', 'test/*'], + ignorePatterns: ['lib/*', 'tests/*', '/*.js', '/*.ts', '/src/__test__/*', '/**/*.test.ts', 'test/*'], parser: '@typescript-eslint/parser', parserOptions: { project: './tsconfig.json', diff --git a/src/__test__/providers/checks.test.ts b/src/__test__/providers/checks.test.ts index 1396c9d..404fb31 100644 --- a/src/__test__/providers/checks.test.ts +++ b/src/__test__/providers/checks.test.ts @@ -1,5 +1,6 @@ import { mockEmbeds, mockSources } from '@/__test__/providerTests'; -import { FeatureMap } from '@/main/targets'; +import { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers'; +import { FeatureMap } from '@/entrypoint/utils/targets'; import { getProviders } from '@/providers/get'; import { vi, describe, it, expect, afterEach } from 'vitest'; @@ -19,7 +20,10 @@ describe('getProviders()', () => { it('should return providers', () => { mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.embedD]); mocks.gatherAllSources.mockReturnValue([mockSources.sourceA, mockSources.sourceB]); - expect(getProviders(features)).toEqual({ + expect(getProviders(features, { + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + })).toEqual({ sources: [mockSources.sourceA, mockSources.sourceB], embeds: [mockEmbeds.embedD], }); @@ -28,7 +32,10 @@ describe('getProviders()', () => { it('should filter out disabled providers', () => { mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.embedD, mockEmbeds.embedEDisabled]); mocks.gatherAllSources.mockReturnValue([mockSources.sourceA, mockSources.sourceCDisabled, mockSources.sourceB]); - expect(getProviders(features)).toEqual({ + expect(getProviders(features,{ + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + })).toEqual({ sources: [mockSources.sourceA, mockSources.sourceB], embeds: [mockEmbeds.embedD], }); @@ -37,31 +44,46 @@ describe('getProviders()', () => { it('should throw on duplicate ids in sources', () => { mocks.gatherAllEmbeds.mockReturnValue([]); mocks.gatherAllSources.mockReturnValue([mockSources.sourceAHigherRank, mockSources.sourceA, mockSources.sourceB]); - expect(() => getProviders(features)).toThrowError(); + expect(() => getProviders(features,{ + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + })).toThrowError(); }); it('should throw on duplicate ids in embeds', () => { mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.embedD, mockEmbeds.embedDHigherRank, mockEmbeds.embedA]); mocks.gatherAllSources.mockReturnValue([]); - expect(() => getProviders(features)).toThrowError(); + expect(() => getProviders(features,{ + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + })).toThrowError(); }); it('should throw on duplicate ids between sources and embeds', () => { mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.embedD, mockEmbeds.embedA]); mocks.gatherAllSources.mockReturnValue([mockSources.sourceA, mockSources.sourceB]); - expect(() => getProviders(features)).toThrowError(); + expect(() => getProviders(features,{ + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + })).toThrowError(); }); it('should throw on duplicate rank between sources and embeds', () => { mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.embedD, mockEmbeds.embedA]); mocks.gatherAllSources.mockReturnValue([mockSources.sourceA, mockSources.sourceB]); - expect(() => getProviders(features)).toThrowError(); + expect(() => getProviders(features,{ + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + })).toThrowError(); }); it('should not throw with same rank between sources and embeds', () => { mocks.gatherAllEmbeds.mockReturnValue([mockEmbeds.embedD, mockEmbeds.embedHSameRankAsSourceA]); mocks.gatherAllSources.mockReturnValue([mockSources.sourceA, mockSources.sourceB]); - expect(getProviders(features)).toEqual({ + expect(getProviders(features,{ + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + })).toEqual({ sources: [mockSources.sourceA, mockSources.sourceB], embeds: [mockEmbeds.embedD, mockEmbeds.embedHSameRankAsSourceA], }); diff --git a/src/__test__/runner/list.test.ts b/src/__test__/runner/list.test.ts index 922392f..336de44 100644 --- a/src/__test__/runner/list.test.ts +++ b/src/__test__/runner/list.test.ts @@ -1,6 +1,6 @@ import { mockEmbeds, mockSources } from '@/__test__/providerTests'; -import { makeProviders } from '@/main/builder'; -import { targets } from '@/main/targets'; +import { makeProviders } from '@/entrypoint/declare'; +import { targets } from '@/entrypoint/utils/targets'; import { afterEach, describe, expect, it, vi } from 'vitest'; const mocks = await vi.hoisted(async () => (await import('../providerTests.ts')).makeProviderMocks()); diff --git a/src/__test__/runner/meta.test.ts b/src/__test__/runner/meta.test.ts index a5cdbf4..423a8e6 100644 --- a/src/__test__/runner/meta.test.ts +++ b/src/__test__/runner/meta.test.ts @@ -1,6 +1,6 @@ import { mockEmbeds, mockSources } from '@/__test__/providerTests'; -import { makeProviders } from '@/main/builder'; -import { targets } from '@/main/targets'; +import { makeProviders } from '@/entrypoint/declare'; +import { targets } from '@/entrypoint/utils/targets'; import { afterEach, describe, expect, it, vi } from 'vitest'; const mocks = await vi.hoisted(async () => (await import('../providerTests.ts')).makeProviderMocks()); diff --git a/src/__test__/utils/features.test.ts b/src/__test__/utils/features.test.ts index 0cb6a4e..0da4019 100644 --- a/src/__test__/utils/features.test.ts +++ b/src/__test__/utils/features.test.ts @@ -1,4 +1,4 @@ -import { FeatureMap, Flags, flags, flagsAllowedInFeatures } from "@/main/targets"; +import { FeatureMap, Flags, flags, flagsAllowedInFeatures } from "@/entrypoint/utils/targets"; import { describe, it, expect } from "vitest"; describe('flagsAllowedInFeatures()', () => { diff --git a/src/entrypoint/builder.ts b/src/entrypoint/builder.ts new file mode 100644 index 0000000..abf8288 --- /dev/null +++ b/src/entrypoint/builder.ts @@ -0,0 +1,93 @@ +import { ProviderControls, makeControls } from '@/entrypoint/controls'; +import { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers'; +import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets'; +import { Fetcher } from '@/fetchers/types'; +import { Embed, Sourcerer } from '@/providers/base'; +import { getProviders } from '@/providers/get'; + +export type ProviderBuilder = { + setTarget(target: Targets): ProviderBuilder; + setFetcher(fetcher: Fetcher): ProviderBuilder; + setProxiedFetcher(fetcher: Fetcher): ProviderBuilder; + addSource(scraper: Sourcerer): ProviderBuilder; + addSource(name: string): ProviderBuilder; + addEmbed(scraper: Embed): ProviderBuilder; + addEmbed(name: string): ProviderBuilder; + addBuiltinProviders(): ProviderBuilder; + enableConsistentIpForRequests(): ProviderBuilder; + build(): ProviderControls; +}; + +export function buildProviders(): ProviderBuilder { + let consistentIpForRequests = false; + let target: Targets | null = null; + let fetcher: Fetcher | null = null; + let proxiedFetcher: Fetcher | null = null; + const embeds: Embed[] = []; + const sources: Sourcerer[] = []; + const builtinSources = getBuiltinSources(); + const builtinEmbeds = getBuiltinEmbeds(); + + return { + enableConsistentIpForRequests() { + consistentIpForRequests = true; + return this; + }, + setFetcher(f) { + fetcher = f; + return this; + }, + setProxiedFetcher(f) { + proxiedFetcher = f; + return this; + }, + setTarget(t) { + target = t; + return this; + }, + addSource(input) { + if (typeof input !== 'string') { + sources.push(input); + return this; + } + + const matchingSource = builtinSources.find((v) => v.id === input); + if (!matchingSource) throw new Error('Source not found'); + sources.push(matchingSource); + return this; + }, + addEmbed(input) { + if (typeof input !== 'string') { + embeds.push(input); + return this; + } + + const matchingEmbed = builtinEmbeds.find((v) => v.id === input); + if (!matchingEmbed) throw new Error('Embed not found'); + embeds.push(matchingEmbed); + return this; + }, + addBuiltinProviders() { + sources.push(...builtinSources); + embeds.push(...builtinEmbeds); + return this; + }, + build() { + if (!target) throw new Error('Target not set'); + if (!fetcher) throw new Error('Fetcher not set'); + const features = getTargetFeatures(target, consistentIpForRequests); + const list = getProviders(features, { + embeds, + sources, + }); + + return makeControls({ + fetcher, + proxiedFetcher: proxiedFetcher ?? undefined, + embeds: list.embeds, + sources: list.sources, + features, + }); + }, + }; +} diff --git a/src/main/builder.ts b/src/entrypoint/controls.ts similarity index 68% rename from src/main/builder.ts rename to src/entrypoint/controls.ts index 2ad6911..babcde4 100644 --- a/src/main/builder.ts +++ b/src/entrypoint/controls.ts @@ -1,28 +1,19 @@ +import { FullScraperEvents, IndividualScraperEvents } from '@/entrypoint/utils/events'; +import { ScrapeMedia } from '@/entrypoint/utils/media'; +import { MetaOutput, getAllEmbedMetaSorted, getAllSourceMetaSorted, getSpecificId } from '@/entrypoint/utils/meta'; +import { FeatureMap } from '@/entrypoint/utils/targets'; import { makeFullFetcher } from '@/fetchers/common'; import { Fetcher } from '@/fetchers/types'; -import { FullScraperEvents, IndividualScraperEvents } from '@/main/events'; -import { scrapeIndividualEmbed, scrapeInvidualSource } from '@/main/individualRunner'; -import { ScrapeMedia } from '@/main/media'; -import { MetaOutput, getAllEmbedMetaSorted, getAllSourceMetaSorted, getSpecificId } from '@/main/meta'; -import { RunOutput, runAllProviders } from '@/main/runner'; -import { Targets, flags, getTargetFeatures } from '@/main/targets'; -import { EmbedOutput, SourcererOutput } from '@/providers/base'; -import { getProviders } from '@/providers/get'; +import { Embed, EmbedOutput, Sourcerer, SourcererOutput } from '@/providers/base'; +import { scrapeIndividualEmbed, scrapeInvidualSource } from '@/runners/individualRunner'; +import { RunOutput, runAllProviders } from '@/runners/runner'; -export interface ProviderBuilderOptions { - // fetcher, every web request gets called through here +export interface ProviderControlsInput { fetcher: Fetcher; - - // proxied fetcher, if the scraper needs to access a CORS proxy. this fetcher will be called instead - // of the normal fetcher. Defaults to the normal fetcher. proxiedFetcher?: Fetcher; - - // target of where the streams will be used - target: Targets; - - // Set this to true, if the requests will have the same IP as - // the device that the stream will be played on - consistentIpForRequests?: boolean; + features: FeatureMap; + sources: Sourcerer[]; + embeds: Embed[]; } export interface RunnerOptions { @@ -84,12 +75,14 @@ export interface ProviderControls { listEmbeds(): MetaOutput[]; } -export function makeProviders(ops: ProviderBuilderOptions): ProviderControls { - const features = getTargetFeatures(ops.target); - if (!ops.consistentIpForRequests) features.disallowed.push(flags.IP_LOCKED); - const list = getProviders(features); +export function makeControls(ops: ProviderControlsInput): ProviderControls { + const list = { + embeds: ops.embeds, + sources: ops.sources, + }; + const providerRunnerOps = { - features, + features: ops.features, fetcher: makeFullFetcher(ops.fetcher), proxiedFetcher: makeFullFetcher(ops.proxiedFetcher ?? ops.fetcher), }; diff --git a/src/entrypoint/declare.ts b/src/entrypoint/declare.ts new file mode 100644 index 0000000..152ee87 --- /dev/null +++ b/src/entrypoint/declare.ts @@ -0,0 +1,37 @@ +import { makeControls } from '@/entrypoint/controls'; +import { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers'; +import { Targets, getTargetFeatures } from '@/entrypoint/utils/targets'; +import { Fetcher } from '@/fetchers/types'; +import { getProviders } from '@/providers/get'; + +export interface ProviderMakerOptions { + // fetcher, every web request gets called through here + fetcher: Fetcher; + + // proxied fetcher, if the scraper needs to access a CORS proxy. this fetcher will be called instead + // of the normal fetcher. Defaults to the normal fetcher. + proxiedFetcher?: Fetcher; + + // target of where the streams will be used + target: Targets; + + // Set this to true, if the requests will have the same IP as + // the device that the stream will be played on + consistentIpForRequests?: boolean; +} + +export function makeProviders(ops: ProviderMakerOptions) { + const features = getTargetFeatures(ops.target, ops.consistentIpForRequests ?? false); + const list = getProviders(features, { + embeds: getBuiltinEmbeds(), + sources: getBuiltinSources(), + }); + + return makeControls({ + embeds: list.embeds, + sources: list.sources, + features, + fetcher: ops.fetcher, + proxiedFetcher: ops.proxiedFetcher, + }); +} diff --git a/src/entrypoint/providers.ts b/src/entrypoint/providers.ts new file mode 100644 index 0000000..b306417 --- /dev/null +++ b/src/entrypoint/providers.ts @@ -0,0 +1,10 @@ +import { gatherAllEmbeds, gatherAllSources } from '@/providers/all'; +import { Embed, Sourcerer } from '@/providers/base'; + +export function getBuiltinSources(): Sourcerer[] { + return gatherAllSources(); +} + +export function getBuiltinEmbeds(): Embed[] { + return gatherAllEmbeds(); +} diff --git a/src/main/events.ts b/src/entrypoint/utils/events.ts similarity index 100% rename from src/main/events.ts rename to src/entrypoint/utils/events.ts diff --git a/src/main/media.ts b/src/entrypoint/utils/media.ts similarity index 100% rename from src/main/media.ts rename to src/entrypoint/utils/media.ts diff --git a/src/main/meta.ts b/src/entrypoint/utils/meta.ts similarity index 96% rename from src/main/meta.ts rename to src/entrypoint/utils/meta.ts index 5696183..5e54b2a 100644 --- a/src/main/meta.ts +++ b/src/entrypoint/utils/meta.ts @@ -1,4 +1,4 @@ -import { MediaTypes } from '@/main/media'; +import { MediaTypes } from '@/entrypoint/utils/media'; import { Embed, Sourcerer } from '@/providers/base'; import { ProviderList } from '@/providers/get'; diff --git a/src/main/targets.ts b/src/entrypoint/utils/targets.ts similarity index 85% rename from src/main/targets.ts rename to src/entrypoint/utils/targets.ts index 1527272..16a02da 100644 --- a/src/main/targets.ts +++ b/src/entrypoint/utils/targets.ts @@ -49,8 +49,10 @@ export const targetToFeatures: Record = { }, }; -export function getTargetFeatures(target: Targets): FeatureMap { - return targetToFeatures[target]; +export function getTargetFeatures(target: Targets, consistentIpForRequests: boolean): FeatureMap { + const features = targetToFeatures[target]; + if (!consistentIpForRequests) features.disallowed.push(flags.IP_LOCKED); + return features; } export function flagsAllowedInFeatures(features: FeatureMap, inputFlags: Flags[]): boolean { diff --git a/src/index.ts b/src/index.ts index d3e310d..347f8dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,21 +1,19 @@ export type { EmbedOutput, SourcererOutput } from '@/providers/base'; export type { Stream, StreamFile, FileBasedStream, HlsBasedStream, Qualities } from '@/providers/streams'; export type { Fetcher, FetcherOptions } from '@/fetchers/types'; -export type { RunOutput } from '@/main/runner'; -export type { MetaOutput } from '@/main/meta'; -export type { FullScraperEvents } from '@/main/events'; -export type { Targets, Flags } from '@/main/targets'; -export type { MediaTypes, ShowMedia, ScrapeMedia, MovieMedia } from '@/main/media'; -export type { - ProviderBuilderOptions, - ProviderControls, - RunnerOptions, - EmbedRunnerOptions, - SourceRunnerOptions, -} from '@/main/builder'; +export type { RunOutput } from '@/runners/runner'; +export type { MetaOutput } from '@/entrypoint/utils/meta'; +export type { FullScraperEvents } from '@/entrypoint/utils/events'; +export type { Targets, Flags } from '@/entrypoint/utils/targets'; +export type { MediaTypes, ShowMedia, ScrapeMedia, MovieMedia } from '@/entrypoint/utils/media'; +export type { ProviderControls, RunnerOptions, EmbedRunnerOptions, SourceRunnerOptions } from '@/entrypoint/controls'; +export type { ProviderBuilder } from '@/entrypoint/builder'; +export type { ProviderMakerOptions } from '@/entrypoint/declare'; export { NotFoundError } from '@/utils/errors'; -export { makeProviders } from '@/main/builder'; +export { makeProviders } from '@/entrypoint/declare'; +export { buildProviders } from '@/entrypoint/builder'; +export { getBuiltinEmbeds, getBuiltinSources } from '@/entrypoint/providers'; export { makeStandardFetcher } from '@/fetchers/standardFetch'; export { makeSimpleProxyFetcher } from '@/fetchers/simpleProxy'; -export { flags, targets } from '@/main/targets'; +export { flags, targets } from '@/entrypoint/utils/targets'; diff --git a/src/providers/base.ts b/src/providers/base.ts index d503ecd..7371166 100644 --- a/src/providers/base.ts +++ b/src/providers/base.ts @@ -1,4 +1,4 @@ -import { Flags } from '@/main/targets'; +import { Flags } from '@/entrypoint/utils/targets'; import { Stream } from '@/providers/streams'; import { EmbedScrapeContext, MovieScrapeContext, ShowScrapeContext } from '@/utils/context'; diff --git a/src/providers/embeds/febbox/common.ts b/src/providers/embeds/febbox/common.ts index 4348c25..5d902db 100644 --- a/src/providers/embeds/febbox/common.ts +++ b/src/providers/embeds/febbox/common.ts @@ -1,4 +1,4 @@ -import { MediaTypes } from '@/main/media'; +import { MediaTypes } from '@/entrypoint/utils/media'; export const febBoxBase = `https://www.febbox.com`; diff --git a/src/providers/embeds/febbox/fileList.ts b/src/providers/embeds/febbox/fileList.ts index b0c03fb..593fc77 100644 --- a/src/providers/embeds/febbox/fileList.ts +++ b/src/providers/embeds/febbox/fileList.ts @@ -1,4 +1,4 @@ -import { MediaTypes } from '@/main/media'; +import { MediaTypes } from '@/entrypoint/utils/media'; import { FebboxFileList, febBoxBase } from '@/providers/embeds/febbox/common'; import { EmbedScrapeContext } from '@/utils/context'; diff --git a/src/providers/embeds/febbox/hls.ts b/src/providers/embeds/febbox/hls.ts index 78cd4ea..d9fa54f 100644 --- a/src/providers/embeds/febbox/hls.ts +++ b/src/providers/embeds/febbox/hls.ts @@ -1,5 +1,5 @@ -import { MediaTypes } from '@/main/media'; -import { flags } from '@/main/targets'; +import { MediaTypes } from '@/entrypoint/utils/media'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; import { parseInputUrl } from '@/providers/embeds/febbox/common'; import { getStreams } from '@/providers/embeds/febbox/fileList'; diff --git a/src/providers/embeds/febbox/mp4.ts b/src/providers/embeds/febbox/mp4.ts index bcebbff..1122e53 100644 --- a/src/providers/embeds/febbox/mp4.ts +++ b/src/providers/embeds/febbox/mp4.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; import { parseInputUrl } from '@/providers/embeds/febbox/common'; import { getStreamQualities } from '@/providers/embeds/febbox/qualities'; diff --git a/src/providers/embeds/mp4upload.ts b/src/providers/embeds/mp4upload.ts index 69547d8..5bc8576 100644 --- a/src/providers/embeds/mp4upload.ts +++ b/src/providers/embeds/mp4upload.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; export const mp4uploadScraper = makeEmbed({ diff --git a/src/providers/embeds/smashystream/dued.ts b/src/providers/embeds/smashystream/dued.ts index a143cbc..c7a1d1d 100644 --- a/src/providers/embeds/smashystream/dued.ts +++ b/src/providers/embeds/smashystream/dued.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; type DPlayerSourcesResponse = { diff --git a/src/providers/embeds/smashystream/video1.ts b/src/providers/embeds/smashystream/video1.ts index 391e67c..1fc2edf 100644 --- a/src/providers/embeds/smashystream/video1.ts +++ b/src/providers/embeds/smashystream/video1.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; import { Caption, getCaptionTypeFromUrl, labelToLanguageCode } from '@/providers/captions'; diff --git a/src/providers/embeds/streamsb.ts b/src/providers/embeds/streamsb.ts index 98954e5..2314be4 100644 --- a/src/providers/embeds/streamsb.ts +++ b/src/providers/embeds/streamsb.ts @@ -3,7 +3,7 @@ import Base64 from 'crypto-js/enc-base64'; import Utf8 from 'crypto-js/enc-utf8'; import FormData from 'form-data'; -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; import { StreamFile } from '@/providers/streams'; import { EmbedScrapeContext } from '@/utils/context'; diff --git a/src/providers/embeds/upcloud.ts b/src/providers/embeds/upcloud.ts index 44e39af..7880cc4 100644 --- a/src/providers/embeds/upcloud.ts +++ b/src/providers/embeds/upcloud.ts @@ -1,6 +1,6 @@ import crypto from 'crypto-js'; -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; import { Caption, getCaptionTypeFromUrl, labelToLanguageCode } from '@/providers/captions'; diff --git a/src/providers/embeds/upstream.ts b/src/providers/embeds/upstream.ts index ba25056..8becf22 100644 --- a/src/providers/embeds/upstream.ts +++ b/src/providers/embeds/upstream.ts @@ -1,6 +1,6 @@ import * as unpacker from 'unpacker'; -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeEmbed } from '@/providers/base'; const packedRegex = /(eval\(function\(p,a,c,k,e,d\).*\)\)\))/; diff --git a/src/providers/get.ts b/src/providers/get.ts index 085aba5..900bbd1 100644 --- a/src/providers/get.ts +++ b/src/providers/get.ts @@ -1,5 +1,4 @@ -import { FeatureMap, flagsAllowedInFeatures } from '@/main/targets'; -import { gatherAllEmbeds, gatherAllSources } from '@/providers/all'; +import { FeatureMap, flagsAllowedInFeatures } from '@/entrypoint/utils/targets'; import { Embed, Sourcerer } from '@/providers/base'; import { hasDuplicates } from '@/utils/predicates'; @@ -8,9 +7,9 @@ export interface ProviderList { embeds: Embed[]; } -export function getProviders(features: FeatureMap): ProviderList { - const sources = gatherAllSources().filter((v) => !v?.disabled); - const embeds = gatherAllEmbeds().filter((v) => !v?.disabled); +export function getProviders(features: FeatureMap, list: ProviderList): ProviderList { + const sources = list.sources.filter((v) => !v?.disabled); + const embeds = list.embeds.filter((v) => !v?.disabled); const combined = [...sources, ...embeds]; const anyDuplicateId = hasDuplicates(combined.map((v) => v.id)); diff --git a/src/providers/sources/flixhq/index.ts b/src/providers/sources/flixhq/index.ts index b866677..e9fbaef 100644 --- a/src/providers/sources/flixhq/index.ts +++ b/src/providers/sources/flixhq/index.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeSourcerer } from '@/providers/base'; import { upcloudScraper } from '@/providers/embeds/upcloud'; import { getFlixhqMovieSources, getFlixhqShowSources, getFlixhqSourceDetails } from '@/providers/sources/flixhq/scrape'; diff --git a/src/providers/sources/flixhq/scrape.ts b/src/providers/sources/flixhq/scrape.ts index a73916c..3f42e9a 100644 --- a/src/providers/sources/flixhq/scrape.ts +++ b/src/providers/sources/flixhq/scrape.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { MovieMedia, ShowMedia } from '@/main/media'; +import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media'; import { flixHqBase } from '@/providers/sources/flixhq/common'; import { ScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; diff --git a/src/providers/sources/flixhq/search.ts b/src/providers/sources/flixhq/search.ts index d52f65a..bcab033 100644 --- a/src/providers/sources/flixhq/search.ts +++ b/src/providers/sources/flixhq/search.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { MovieMedia, ShowMedia } from '@/main/media'; +import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media'; import { flixHqBase } from '@/providers/sources/flixhq/common'; import { compareMedia, compareTitle } from '@/utils/compare'; import { ScrapeContext } from '@/utils/context'; diff --git a/src/providers/sources/gomovies/index.ts b/src/providers/sources/gomovies/index.ts index ff43411..9bec3e0 100644 --- a/src/providers/sources/gomovies/index.ts +++ b/src/providers/sources/gomovies/index.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeSourcerer } from '@/providers/base'; import { upcloudScraper } from '@/providers/embeds/upcloud'; import { NotFoundError } from '@/utils/errors'; diff --git a/src/providers/sources/kissasian/index.ts b/src/providers/sources/kissasian/index.ts index d856ea5..4b8032b 100644 --- a/src/providers/sources/kissasian/index.ts +++ b/src/providers/sources/kissasian/index.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeSourcerer } from '@/providers/base'; import { NotFoundError } from '@/utils/errors'; diff --git a/src/providers/sources/lookmovie/index.ts b/src/providers/sources/lookmovie/index.ts index 606a6e3..5cd82e9 100644 --- a/src/providers/sources/lookmovie/index.ts +++ b/src/providers/sources/lookmovie/index.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { SourcererOutput, makeSourcerer } from '@/providers/base'; import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; diff --git a/src/providers/sources/lookmovie/type.ts b/src/providers/sources/lookmovie/type.ts index 3731520..8335c96 100644 --- a/src/providers/sources/lookmovie/type.ts +++ b/src/providers/sources/lookmovie/type.ts @@ -1,4 +1,4 @@ -import { MovieMedia } from '@/main/media'; +import { MovieMedia } from '@/entrypoint/utils/media'; // ! Types interface BaseConfig { diff --git a/src/providers/sources/lookmovie/util.ts b/src/providers/sources/lookmovie/util.ts index 231e715..7c8f202 100644 --- a/src/providers/sources/lookmovie/util.ts +++ b/src/providers/sources/lookmovie/util.ts @@ -1,4 +1,4 @@ -import { MovieMedia, ShowMedia } from '@/main/media'; +import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media'; import { compareMedia } from '@/utils/compare'; import { ScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; diff --git a/src/providers/sources/lookmovie/video.ts b/src/providers/sources/lookmovie/video.ts index 38ace62..f439229 100644 --- a/src/providers/sources/lookmovie/video.ts +++ b/src/providers/sources/lookmovie/video.ts @@ -1,4 +1,4 @@ -import { MovieMedia, ShowMedia } from '@/main/media'; +import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media'; import { ScrapeContext } from '@/utils/context'; import { StreamsDataResult } from './type'; diff --git a/src/providers/sources/remotestream.ts b/src/providers/sources/remotestream.ts index f97cf4d..6d0a44c 100644 --- a/src/providers/sources/remotestream.ts +++ b/src/providers/sources/remotestream.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeSourcerer } from '@/providers/base'; import { NotFoundError } from '@/utils/errors'; diff --git a/src/providers/sources/showbox/index.ts b/src/providers/sources/showbox/index.ts index 064011e..267a6ef 100644 --- a/src/providers/sources/showbox/index.ts +++ b/src/providers/sources/showbox/index.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { SourcererOutput, makeSourcerer } from '@/providers/base'; import { febboxHlsScraper } from '@/providers/embeds/febbox/hls'; import { febboxMp4Scraper } from '@/providers/embeds/febbox/mp4'; diff --git a/src/providers/sources/smashystream/index.ts b/src/providers/sources/smashystream/index.ts index c7601f8..62102ea 100644 --- a/src/providers/sources/smashystream/index.ts +++ b/src/providers/sources/smashystream/index.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { SourcererEmbed, SourcererOutput, makeSourcerer } from '@/providers/base'; import { smashyStreamDScraper } from '@/providers/embeds/smashystream/dued'; import { smashyStreamFScraper } from '@/providers/embeds/smashystream/video1'; diff --git a/src/providers/sources/zoechip/index.ts b/src/providers/sources/zoechip/index.ts index 6b7aae2..ee7f3a6 100644 --- a/src/providers/sources/zoechip/index.ts +++ b/src/providers/sources/zoechip/index.ts @@ -1,4 +1,4 @@ -import { flags } from '@/main/targets'; +import { flags } from '@/entrypoint/utils/targets'; import { makeSourcerer } from '@/providers/base'; import { scrapeMovie } from '@/providers/sources/zoechip/scrape-movie'; import { scrapeShow } from '@/providers/sources/zoechip/scrape-show'; diff --git a/src/providers/sources/zoechip/scrape.ts b/src/providers/sources/zoechip/scrape.ts index 126a3e0..d3eb183 100644 --- a/src/providers/sources/zoechip/scrape.ts +++ b/src/providers/sources/zoechip/scrape.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { ShowMedia } from '@/main/media'; +import { ShowMedia } from '@/entrypoint/utils/media'; import { ZoeChipSourceDetails, zoeBase } from '@/providers/sources/zoechip/common'; import { MovieScrapeContext, ScrapeContext, ShowScrapeContext } from '@/utils/context'; diff --git a/src/providers/sources/zoechip/search.ts b/src/providers/sources/zoechip/search.ts index 6297bc4..f3a838d 100644 --- a/src/providers/sources/zoechip/search.ts +++ b/src/providers/sources/zoechip/search.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; -import { MovieMedia, ShowMedia } from '@/main/media'; +import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media'; import { zoeBase } from '@/providers/sources/zoechip/common'; import { compareMedia } from '@/utils/compare'; import { ScrapeContext } from '@/utils/context'; diff --git a/src/providers/streams.ts b/src/providers/streams.ts index 9a9a9be..03ae873 100644 --- a/src/providers/streams.ts +++ b/src/providers/streams.ts @@ -1,4 +1,4 @@ -import { Flags } from '@/main/targets'; +import { Flags } from '@/entrypoint/utils/targets'; import { Caption } from '@/providers/captions'; export type StreamFile = { diff --git a/src/main/individualRunner.ts b/src/runners/individualRunner.ts similarity index 93% rename from src/main/individualRunner.ts rename to src/runners/individualRunner.ts index 3b48a29..2befd84 100644 --- a/src/main/individualRunner.ts +++ b/src/runners/individualRunner.ts @@ -1,7 +1,7 @@ +import { IndividualScraperEvents } from '@/entrypoint/utils/events'; +import { ScrapeMedia } from '@/entrypoint/utils/media'; +import { FeatureMap, flagsAllowedInFeatures } from '@/entrypoint/utils/targets'; import { UseableFetcher } from '@/fetchers/types'; -import { IndividualScraperEvents } from '@/main/events'; -import { ScrapeMedia } from '@/main/media'; -import { FeatureMap, flagsAllowedInFeatures } from '@/main/targets'; import { EmbedOutput, SourcererOutput } from '@/providers/base'; import { ProviderList } from '@/providers/get'; import { ScrapeContext } from '@/utils/context'; diff --git a/src/main/runner.ts b/src/runners/runner.ts similarity index 96% rename from src/main/runner.ts rename to src/runners/runner.ts index cf9fc82..1774213 100644 --- a/src/main/runner.ts +++ b/src/runners/runner.ts @@ -1,7 +1,7 @@ +import { FullScraperEvents } from '@/entrypoint/utils/events'; +import { ScrapeMedia } from '@/entrypoint/utils/media'; +import { FeatureMap, flagsAllowedInFeatures } from '@/entrypoint/utils/targets'; import { UseableFetcher } from '@/fetchers/types'; -import { FullScraperEvents } from '@/main/events'; -import { ScrapeMedia } from '@/main/media'; -import { FeatureMap, flagsAllowedInFeatures } from '@/main/targets'; import { EmbedOutput, SourcererOutput } from '@/providers/base'; import { ProviderList } from '@/providers/get'; import { Stream } from '@/providers/streams'; diff --git a/src/utils/compare.ts b/src/utils/compare.ts index 8cce7da..cceffb8 100644 --- a/src/utils/compare.ts +++ b/src/utils/compare.ts @@ -1,4 +1,4 @@ -import { CommonMedia } from '@/main/media'; +import { CommonMedia } from '@/entrypoint/utils/media'; export function normalizeTitle(title: string): string { return title diff --git a/src/utils/context.ts b/src/utils/context.ts index 1a84253..36cd151 100644 --- a/src/utils/context.ts +++ b/src/utils/context.ts @@ -1,5 +1,5 @@ +import { MovieMedia, ShowMedia } from '@/entrypoint/utils/media'; import { UseableFetcher } from '@/fetchers/types'; -import { MovieMedia, ShowMedia } from '@/main/media'; export type ScrapeContext = { proxiedFetcher: (...params: Parameters>) => ReturnType>;