From 453cc747a1008cf8b904549870d6369f7287b774 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Mon, 21 Jul 2025 14:39:13 +0000 Subject: [PATCH] refactor: introduce createSources() analogue to createExtractors() --- src/index.ts | 31 ++-------------- src/source/index.ts | 63 +++++++++++++++++++++++--------- src/utils/StreamResolver.test.ts | 4 +- src/utils/manifest.test.ts | 5 ++- 4 files changed, 57 insertions(+), 46 deletions(-) diff --git a/src/index.ts b/src/index.ts index a6406d0..52dc60a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid'; import winston from 'winston'; import { ConfigureController, ManifestController, StreamController } from './controller'; import { createExtractors, ExtractorRegistry } from './extractor'; -import { CineHDPlus, Cuevana, Eurostreaming, Frembed, FrenchCloud, HomeCine, KinoGer, MegaKino, MeineCloud, MostraGuarda, Movix, PrimeWire, Soaper, Source, StreamKiste, VerHdLink, VidSrc, VixSrc } from './source'; +import { createSources } from './source'; import { contextFromRequestAndResponse, envGet, envIsProd, Fetcher, StreamResolver } from './utils'; console.log = console.warn = console.error = console.info = console.debug = () => { /* disable in favor of logger */ }; @@ -31,31 +31,8 @@ if (process.env['ALL_PROXY']) { } const fetcher = new Fetcher(logger); -const sources: Source[] = [ - // multi - new VixSrc(fetcher), - // EN - new PrimeWire(fetcher), - new Soaper(fetcher), - new VidSrc(fetcher), - // ES / MX - new CineHDPlus(fetcher), - new Cuevana(fetcher), - new HomeCine(fetcher), - new VerHdLink(fetcher), - // DE - new KinoGer(fetcher), - new MegaKino(fetcher), - new MeineCloud(fetcher), - new StreamKiste(fetcher), - // FR - new Frembed(fetcher), - new FrenchCloud(fetcher), - new Movix(fetcher), - // IT - new Eurostreaming(fetcher), - new MostraGuarda(fetcher), -]; +const sources = createSources(fetcher); +const extractors = createExtractors(fetcher); const addon = express(); addon.set('trust proxy', true); @@ -76,7 +53,7 @@ addon.use((_req: Request, res: Response, next: NextFunction) => { addon.use('/', (new ConfigureController(sources)).router); addon.use('/', (new ManifestController(sources)).router); -const extractorRegistry = new ExtractorRegistry(logger, createExtractors(fetcher)); +const extractorRegistry = new ExtractorRegistry(logger, extractors); const streamResolver = new StreamResolver(logger, extractorRegistry); addon.use('/', (new StreamController(logger, sources, streamResolver)).router); diff --git a/src/source/index.ts b/src/source/index.ts index 473ae15..ef004e7 100644 --- a/src/source/index.ts +++ b/src/source/index.ts @@ -1,18 +1,47 @@ -export * from './CineHDPlus'; -export * from './Cuevana'; -export * from './Eurostreaming'; -export * from './Frembed'; -export * from './FrenchCloud'; -export * from './HomeCine'; -export * from './KinoGer'; -export * from './MegaKino'; -export * from './MeineCloud'; -export * from './MostraGuarda'; -export * from './Movix'; -export * from './PrimeWire'; -export * from './Soaper'; -export * from './StreamKiste'; -export * from './VerHdLink'; -export * from './VidSrc'; -export * from './VixSrc'; +import { Fetcher } from '../utils'; +import { CineHDPlus } from './CineHDPlus'; +import { Cuevana } from './Cuevana'; +import { Eurostreaming } from './Eurostreaming'; +import { Frembed } from './Frembed'; +import { FrenchCloud } from './FrenchCloud'; +import { HomeCine } from './HomeCine'; +import { KinoGer } from './KinoGer'; +import { MegaKino } from './MegaKino'; +import { MeineCloud } from './MeineCloud'; +import { MostraGuarda } from './MostraGuarda'; +import { Movix } from './Movix'; +import { PrimeWire } from './PrimeWire'; +import { Soaper } from './Soaper'; +import { StreamKiste } from './StreamKiste'; +import { Source } from './types'; +import { VerHdLink } from './VerHdLink'; +import { VidSrc } from './VidSrc'; +import { VixSrc } from './VixSrc'; + export * from './types'; + +export const createSources = (fetcher: Fetcher): Source[] => [ + // multi + new VixSrc(fetcher), + // EN + new PrimeWire(fetcher), + new Soaper(fetcher), + new VidSrc(fetcher), + // ES / MX + new CineHDPlus(fetcher), + new Cuevana(fetcher), + new HomeCine(fetcher), + new VerHdLink(fetcher), + // DE + new KinoGer(fetcher), + new MegaKino(fetcher), + new MeineCloud(fetcher), + new StreamKiste(fetcher), + // FR + new Frembed(fetcher), + new FrenchCloud(fetcher), + new Movix(fetcher), + // IT + new Eurostreaming(fetcher), + new MostraGuarda(fetcher), +]; diff --git a/src/utils/StreamResolver.test.ts b/src/utils/StreamResolver.test.ts index e2d6be1..c456bdc 100644 --- a/src/utils/StreamResolver.test.ts +++ b/src/utils/StreamResolver.test.ts @@ -2,7 +2,9 @@ import { ContentType } from 'stremio-addon-sdk'; import winston from 'winston'; import { BlockedError, HttpError, NotFoundError, QueueIsFullError, TimeoutError, TooManyRequestsError, TooManyTimeoutsError } from '../error'; import { createExtractors, Extractor, ExtractorRegistry } from '../extractor'; -import { MeineCloud, MostraGuarda, Source, SourceResult } from '../source'; +import { Source, SourceResult } from '../source'; +import { MeineCloud } from '../source/MeineCloud'; +import { MostraGuarda } from '../source/MostraGuarda'; import { createTestContext } from '../test'; import { BlockedReason, CountryCode, Format, UrlResult } from '../types'; import { FetcherMock } from './FetcherMock'; diff --git a/src/utils/manifest.test.ts b/src/utils/manifest.test.ts index 86e5e03..a3eff20 100644 --- a/src/utils/manifest.test.ts +++ b/src/utils/manifest.test.ts @@ -1,4 +1,7 @@ -import { MeineCloud, StreamKiste, VerHdLink, VixSrc } from '../source'; +import { MeineCloud } from '../source/MeineCloud'; +import { StreamKiste } from '../source/StreamKiste'; +import { VerHdLink } from '../source/VerHdLink'; +import { VixSrc } from '../source/VixSrc'; import { FetcherMock } from './FetcherMock'; import { buildManifest } from './manifest';