refactor: introduce type for CountryCode

This commit is contained in:
WebStreamr 2025-05-25 19:32:16 +02:00
parent 979dddd20c
commit f27fc6c38a
No known key found for this signature in database
13 changed files with 32 additions and 30 deletions

View file

@ -34,7 +34,7 @@ export class StreamController {
this.logger.info(`Search stream for type "${type}" and id "${id}" for ip ${ctx.ip}`, ctx);
const handlers = this.handlers.filter(handler => handler.languages.filter(language => language in ctx.config).length);
const handlers = this.handlers.filter(handler => handler.countryCodes.filter(countryCode => countryCode in ctx.config).length);
const streams = await this.streamResolver.resolve(ctx, handlers, type, id);

View file

@ -2,7 +2,7 @@ import * as cheerio from 'cheerio';
import { Handler } from './types';
import { Fetcher, ImdbId, parseImdbId } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class CineHDPlus implements Handler {
readonly id = 'cinehdplus';
@ -11,7 +11,7 @@ export class CineHDPlus implements Handler {
readonly contentTypes = ['series'];
readonly languages = ['es', 'mx'];
readonly countryCodes: CountryCode[] = ['es', 'mx'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;

View file

@ -2,7 +2,7 @@ import * as cheerio from 'cheerio';
import { Handler } from './types';
import { ImdbId, parseImdbId, Fetcher } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class Eurostreaming implements Handler {
readonly id = 'eurostreaming';
@ -11,7 +11,7 @@ export class Eurostreaming implements Handler {
readonly contentTypes = ['series'];
readonly languages = ['it'];
readonly countryCodes: CountryCode[] = ['it'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;

View file

@ -2,7 +2,7 @@ import axios from 'axios';
import { Handler } from './types';
import { parseImdbId, Fetcher, getTmdbIdFromImdbId } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class Frembed implements Handler {
readonly id = 'frembed';
@ -11,7 +11,7 @@ export class Frembed implements Handler {
readonly contentTypes = ['series'];
readonly languages = ['fr'];
readonly countryCodes: CountryCode[] = ['fr'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;

View file

@ -2,7 +2,7 @@ import * as cheerio from 'cheerio';
import { Handler } from './types';
import { Fetcher, parseImdbId } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class FrenchCloud implements Handler {
readonly id = 'frenchcloud';
@ -11,7 +11,7 @@ export class FrenchCloud implements Handler {
readonly contentTypes = ['movie'];
readonly languages = ['fr'];
readonly countryCodes: CountryCode[] = ['fr'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;

View file

@ -2,7 +2,7 @@ import * as cheerio from 'cheerio';
import { Handler } from './types';
import { ImdbId, parseImdbId, Fetcher } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class KinoKiste implements Handler {
readonly id = 'kinokiste';
@ -11,7 +11,7 @@ export class KinoKiste implements Handler {
readonly contentTypes = ['series'];
readonly languages = ['de'];
readonly countryCodes: CountryCode[] = ['de'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;

View file

@ -2,7 +2,7 @@ import * as cheerio from 'cheerio';
import { Handler } from './types';
import { Fetcher, parseImdbId } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class MeineCloud implements Handler {
readonly id = 'meinecloud';
@ -11,7 +11,7 @@ export class MeineCloud implements Handler {
readonly contentTypes = ['movie'];
readonly languages = ['de'];
readonly countryCodes: CountryCode[] = ['de'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;

View file

@ -2,7 +2,7 @@ import * as cheerio from 'cheerio';
import { Handler } from './types';
import { Fetcher, parseImdbId } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class MostraGuarda implements Handler {
readonly id = 'mostraguarda';
@ -11,7 +11,7 @@ export class MostraGuarda implements Handler {
readonly contentTypes = ['movie'];
readonly languages = ['it'];
readonly countryCodes: CountryCode[] = ['it'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;

View file

@ -2,7 +2,7 @@ import * as cheerio from 'cheerio';
import { Handler } from './types';
import { Fetcher, parseImdbId } from '../utils';
import { ExtractorRegistry } from '../extractor';
import { Context } from '../types';
import { Context, CountryCode } from '../types';
export class VerHdLink implements Handler {
readonly id = 'verhdlink';
@ -11,7 +11,7 @@ export class VerHdLink implements Handler {
readonly contentTypes = ['movie'];
readonly languages = ['es', 'mx'];
readonly countryCodes: CountryCode[] = ['es', 'mx'];
private readonly fetcher: Fetcher;
private readonly extractorRegistry: ExtractorRegistry;
@ -33,7 +33,7 @@ export class VerHdLink implements Handler {
return Promise.all(
$('._player-mirrors')
.map((_i, el) => {
let countryCode = undefined;
let countryCode: CountryCode;
if ($(el).hasClass('latino') && 'mx' in ctx.config) {
countryCode = 'mx';
} else if ($(el).hasClass('castellano') && 'es' in ctx.config) {

View file

@ -1,4 +1,4 @@
import { Context, UrlResult } from '../types';
import { Context, CountryCode, UrlResult } from '../types';
export interface Handler {
readonly id: string;
@ -7,7 +7,7 @@ export interface Handler {
readonly contentTypes: string[];
readonly languages: string[];
readonly countryCodes: CountryCode[];
readonly handle: (ctx: Context, type: string, id: string) => Promise<(UrlResult | undefined)[]>;
}

View file

@ -10,9 +10,11 @@ export type ManifestWithConfig = Manifest & { config: ManifestConfig[] };
export type Config = Record<string, string>;
export type CountryCode = 'de' | 'en' | 'es' | 'fr' | 'it' | 'mx';
export interface Meta {
bytes?: number;
countryCode: string;
countryCode: CountryCode;
height?: number;
}

View file

@ -62,7 +62,7 @@ describe('resolve', () => {
id: 'mockhandler',
label: 'MockHandler',
contentTypes: ['movie'],
languages: ['de'],
countryCodes: ['de'],
handle: jest.fn().mockRejectedValue(new NotFoundError()),
};

View file

@ -30,20 +30,20 @@ export const buildManifest = (handlers: Handler[], config: Config): ManifestWith
},
};
const languageHandlers: Record<string, Handler[]> = {};
const countryCodeHandlers: Record<string, Handler[]> = {};
handlers.forEach((handler) => {
handler.languages.forEach(language => languageHandlers[language] = [...(languageHandlers[language] ?? []), handler]);
handler.countryCodes.forEach(countryCode => countryCodeHandlers[countryCode] = [...(countryCodeHandlers[countryCode] ?? []), handler]);
});
const sortedLanguageHandlers = Object.entries(languageHandlers)
.sort(([languageA], [languageB]) => languageA.localeCompare(languageB));
const sortedLanguageHandlers = Object.entries(countryCodeHandlers)
.sort(([countryCodeA], [countryCodeB]) => countryCodeA.localeCompare(countryCodeB));
for (const [language, handlers] of sortedLanguageHandlers) {
for (const [countryCode, handlers] of sortedLanguageHandlers) {
manifest.config.push({
key: language,
key: countryCode,
type: 'checkbox',
title: `${flag(language)} (${handlers.map(handler => handler.label).join(', ')})`,
...(language in config && { default: 'checked' }),
title: `${flag(countryCode)} (${handlers.map(handler => handler.label).join(', ')})`,
...(countryCode in config && { default: 'checked' }),
});
}