From 4a705ce0883f78940d03512b9432eb0aec8120e3 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Sat, 17 May 2025 20:25:51 +0200 Subject: [PATCH] refactor: cleanup url and extractorRegistry variable/prop names --- src/extractor/ExtractorRegistry.ts | 2 +- src/handler/CineHDPlus.ts | 10 +++++----- src/handler/Eurostreaming.ts | 10 +++++----- src/handler/Frembed.ts | 8 ++++---- src/handler/FrenchCloud.ts | 10 +++++----- src/handler/KinoKiste.ts | 10 +++++----- src/handler/MeineCloud.ts | 10 +++++----- src/handler/MostraGuarda.ts | 10 +++++----- src/handler/VerHdLink.ts | 10 +++++----- src/index.ts | 18 +++++++++--------- src/utils/Fetcher.ts | 2 -- src/utils/StreamResolver.test.ts | 6 +++--- 12 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/extractor/ExtractorRegistry.ts b/src/extractor/ExtractorRegistry.ts index ed67bfb..4ec70e5 100644 --- a/src/extractor/ExtractorRegistry.ts +++ b/src/extractor/ExtractorRegistry.ts @@ -28,7 +28,7 @@ export class ExtractorRegistry { return urlResult; } - const extractor = this.extractors.find(embedExtractor => embedExtractor.supports(url)); + const extractor = this.extractors.find(extractor => extractor.supports(url)); if (undefined === extractor) { return undefined; } diff --git a/src/handler/CineHDPlus.ts b/src/handler/CineHDPlus.ts index 8fbbb84..b855823 100644 --- a/src/handler/CineHDPlus.ts +++ b/src/handler/CineHDPlus.ts @@ -14,11 +14,11 @@ export class CineHDPlus implements Handler { readonly languages = ['es', 'mx']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -45,8 +45,8 @@ export class CineHDPlus implements Handler { .children('[data-link]') .map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://'))) .toArray() - .filter(embedUrl => !embedUrl.host.match(/cinehdplus/)) - .map(embedUrl => this.embedExtractors.handle(ctx, embedUrl, countryCode)), + .filter(url => !url.host.match(/cinehdplus/)) + .map(url => this.extractorRegistry.handle(ctx, url, countryCode)), ); }; diff --git a/src/handler/Eurostreaming.ts b/src/handler/Eurostreaming.ts index 9fa0e10..4db42cd 100644 --- a/src/handler/Eurostreaming.ts +++ b/src/handler/Eurostreaming.ts @@ -14,11 +14,11 @@ export class Eurostreaming implements Handler { readonly languages = ['it']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -43,8 +43,8 @@ export class Eurostreaming implements Handler { .children('[data-link!="#"]') .map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://'))) .toArray() - .filter(embedUrl => !embedUrl.host.match(/eurostreaming/)) - .map(embedUrl => this.embedExtractors.handle(ctx, embedUrl, 'it')), + .filter(url => !url.host.match(/eurostreaming/)) + .map(url => this.extractorRegistry.handle(ctx, url, 'it')), ); }; diff --git a/src/handler/Frembed.ts b/src/handler/Frembed.ts index f34f9fb..ad28d5b 100644 --- a/src/handler/Frembed.ts +++ b/src/handler/Frembed.ts @@ -14,11 +14,11 @@ export class Frembed implements Handler { readonly languages = ['fr']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -46,7 +46,7 @@ export class Frembed implements Handler { } } - return Promise.all(urls.map(url => this.embedExtractors.handle(ctx, url, 'fr'))); + return Promise.all(urls.map(url => this.extractorRegistry.handle(ctx, url, 'fr'))); }; private readonly apiCall = async (ctx: Context, url: URL): Promise => { diff --git a/src/handler/FrenchCloud.ts b/src/handler/FrenchCloud.ts index 79411bb..bc6648c 100644 --- a/src/handler/FrenchCloud.ts +++ b/src/handler/FrenchCloud.ts @@ -14,11 +14,11 @@ export class FrenchCloud implements Handler { readonly languages = ['fr']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -34,8 +34,8 @@ export class FrenchCloud implements Handler { $('[data-link!=""]') .map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://'))) .toArray() - .filter(embedUrl => !embedUrl.host.match(/frenchcloud/)) - .map(embedUrl => this.embedExtractors.handle(ctx, embedUrl, 'fr')), + .filter(url => !url.host.match(/frenchcloud/)) + .map(url => this.extractorRegistry.handle(ctx, url, 'fr')), ); }; } diff --git a/src/handler/KinoKiste.ts b/src/handler/KinoKiste.ts index 57df55c..ff7f880 100644 --- a/src/handler/KinoKiste.ts +++ b/src/handler/KinoKiste.ts @@ -14,11 +14,11 @@ export class KinoKiste implements Handler { readonly languages = ['de']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -43,8 +43,8 @@ export class KinoKiste implements Handler { .children('[data-link]') .map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://'))) .toArray() - .filter(embedUrl => !embedUrl.host.match(/kinokiste/)) - .map(embedUrl => this.embedExtractors.handle(ctx, embedUrl, 'de')), + .filter(url => !url.host.match(/kinokiste/)) + .map(url => this.extractorRegistry.handle(ctx, url, 'de')), ); }; diff --git a/src/handler/MeineCloud.ts b/src/handler/MeineCloud.ts index 73b5277..7f6efa6 100644 --- a/src/handler/MeineCloud.ts +++ b/src/handler/MeineCloud.ts @@ -14,11 +14,11 @@ export class MeineCloud implements Handler { readonly languages = ['de']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -34,8 +34,8 @@ export class MeineCloud implements Handler { $('[data-link!=""]') .map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://'))) .toArray() - .filter(embedUrl => !embedUrl.host.match(/meinecloud/)) - .map(embedUrl => this.embedExtractors.handle(ctx, embedUrl, 'de')), + .filter(url => !url.host.match(/meinecloud/)) + .map(url => this.extractorRegistry.handle(ctx, url, 'de')), ); }; } diff --git a/src/handler/MostraGuarda.ts b/src/handler/MostraGuarda.ts index 9f1f6ff..73a6e31 100644 --- a/src/handler/MostraGuarda.ts +++ b/src/handler/MostraGuarda.ts @@ -14,11 +14,11 @@ export class MostraGuarda implements Handler { readonly languages = ['it']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -34,8 +34,8 @@ export class MostraGuarda implements Handler { $('[data-link!=""]') .map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://'))) .toArray() - .filter(embedUrl => !embedUrl.host.match(/mostraguarda/)) - .map(embedUrl => this.embedExtractors.handle(ctx, embedUrl, 'it')), + .filter(url => !url.host.match(/mostraguarda/)) + .map(url => this.extractorRegistry.handle(ctx, url, 'it')), ); }; } diff --git a/src/handler/VerHdLink.ts b/src/handler/VerHdLink.ts index 1754441..26297c4 100644 --- a/src/handler/VerHdLink.ts +++ b/src/handler/VerHdLink.ts @@ -14,11 +14,11 @@ export class VerHdLink implements Handler { readonly languages = ['es', 'mx']; private readonly fetcher: Fetcher; - private readonly embedExtractors: ExtractorRegistry; + private readonly extractorRegistry: ExtractorRegistry; - constructor(fetcher: Fetcher, embedExtractors: ExtractorRegistry) { + constructor(fetcher: Fetcher, extractorRegistry: ExtractorRegistry) { this.fetcher = fetcher; - this.embedExtractors = embedExtractors; + this.extractorRegistry = extractorRegistry; } readonly handle = async (ctx: Context, _type: string, id: string) => { @@ -45,8 +45,8 @@ export class VerHdLink implements Handler { return $('[data-link!=""]', el) .map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://'))) .toArray() - .filter(embedUrl => !embedUrl.host.match(/verhdlink/)) - .map(embedUrl => this.embedExtractors.handle(ctx, embedUrl, countryCode)); + .filter(url => !url.host.match(/verhdlink/)) + .map(url => this.extractorRegistry.handle(ctx, url, countryCode)); }), ); }; diff --git a/src/index.ts b/src/index.ts index ea34048..17a7c21 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,21 +39,21 @@ axiosRetry(axios, { const fetcher = new Fetcher(axios, logger); -const embedExtractors = new ExtractorRegistry(logger, fetcher); +const extractorRegistry = new ExtractorRegistry(logger, fetcher); const handlers: Handler[] = [ // ES / MX - new CineHDPlus(fetcher, embedExtractors), - new VerHdLink(fetcher, embedExtractors), + new CineHDPlus(fetcher, extractorRegistry), + new VerHdLink(fetcher, extractorRegistry), // DE - new KinoKiste(fetcher, embedExtractors), - new MeineCloud(fetcher, embedExtractors), + new KinoKiste(fetcher, extractorRegistry), + new MeineCloud(fetcher, extractorRegistry), // FR - new Frembed(fetcher, embedExtractors), - new FrenchCloud(fetcher, embedExtractors), + new Frembed(fetcher, extractorRegistry), + new FrenchCloud(fetcher, extractorRegistry), // IT - new Eurostreaming(fetcher, embedExtractors), - new MostraGuarda(fetcher, embedExtractors), + new Eurostreaming(fetcher, extractorRegistry), + new MostraGuarda(fetcher, extractorRegistry), ]; const addon = express(); diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index a6ada78..d07b3f7 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -6,9 +6,7 @@ import { Context } from '../types'; export class Fetcher { private readonly axios: AxiosInstance; - private readonly logger: winston.Logger; - private readonly ipUserAgentCache: TTLCache; constructor(axios: AxiosInstance, logger: winston.Logger) { diff --git a/src/utils/StreamResolver.test.ts b/src/utils/StreamResolver.test.ts index 171be4a..046dd32 100644 --- a/src/utils/StreamResolver.test.ts +++ b/src/utils/StreamResolver.test.ts @@ -12,9 +12,9 @@ const ctx: Context = { ip: '127.0.0.1' }; // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const embedExtractorRegistry = new ExtractorRegistry(logger, fetcher); -const meineCloud = new MeineCloud(fetcher, embedExtractorRegistry); -const mostraGuarda = new MostraGuarda(fetcher, embedExtractorRegistry); +const extractorRegistry = new ExtractorRegistry(logger, fetcher); +const meineCloud = new MeineCloud(fetcher, extractorRegistry); +const mostraGuarda = new MostraGuarda(fetcher, extractorRegistry); describe('resolve', () => { test('returns info as stream if no handlers were configured', async () => {