refactor: cleanup url and extractorRegistry variable/prop names

This commit is contained in:
WebStreamr 2025-05-17 20:25:51 +02:00
parent 8b82215c32
commit 4a705ce088
No known key found for this signature in database
12 changed files with 52 additions and 54 deletions

View file

@ -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;
}

View file

@ -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)),
);
};

View file

@ -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')),
);
};

View file

@ -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<string | undefined> => {

View file

@ -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')),
);
};
}

View file

@ -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')),
);
};

View file

@ -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')),
);
};
}

View file

@ -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')),
);
};
}

View file

@ -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));
}),
);
};

View file

@ -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();

View file

@ -6,9 +6,7 @@ import { Context } from '../types';
export class Fetcher {
private readonly axios: AxiosInstance;
private readonly logger: winston.Logger;
private readonly ipUserAgentCache: TTLCache<string, string>;
constructor(axios: AxiosInstance, logger: winston.Logger) {

View file

@ -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 () => {