From 9da7c07dc6350910d6ef30b24033fdcefc480a06 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Sun, 31 Aug 2025 18:52:42 +0000 Subject: [PATCH] refactor(source): introduce abstract parent class --- src/source/CineHDPlus.ts | 8 +++++--- src/source/Cuevana.ts | 8 +++++--- src/source/Einschalten.ts | 8 +++++--- src/source/Eurostreaming.ts | 8 +++++--- src/source/Frembed.ts | 8 +++++--- src/source/FrenchCloud.ts | 8 +++++--- src/source/HomeCine.ts | 8 +++++--- src/source/KinoGer.ts | 8 +++++--- src/source/MegaKino.ts | 8 +++++--- src/source/MeineCloud.ts | 8 +++++--- src/source/MostraGuarda.ts | 8 +++++--- src/source/Movix.ts | 8 +++++--- src/source/PrimeWire.ts | 8 +++++--- src/source/Soaper.ts | 8 +++++--- src/source/Source.ts | 27 +++++++++++++++++++++++++++ src/source/StreamKiste.ts | 8 +++++--- src/source/VerHdLink.ts | 8 +++++--- src/source/VidSrc.ts | 8 +++++--- src/source/VixSrc.ts | 8 +++++--- src/source/XPrime.ts | 8 +++++--- src/source/index.ts | 4 ++-- src/source/types.ts | 23 ----------------------- src/utils/StreamResolver.test.ts | 30 +++++++++++++++++++----------- 23 files changed, 143 insertions(+), 93 deletions(-) create mode 100644 src/source/Source.ts delete mode 100644 src/source/types.ts diff --git a/src/source/CineHDPlus.ts b/src/source/CineHDPlus.ts index f301942..9e60342 100644 --- a/src/source/CineHDPlus.ts +++ b/src/source/CineHDPlus.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id, ImdbId } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class CineHDPlus implements Source { +export class CineHDPlus extends Source { public readonly id = 'cinehdplus'; public readonly label = 'CineHDPlus'; @@ -18,10 +18,12 @@ export class CineHDPlus implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const seriesPageUrl = await this.fetchSeriesPageUrl(ctx, imdbId); diff --git a/src/source/Cuevana.ts b/src/source/Cuevana.ts index d398ec1..7732638 100644 --- a/src/source/Cuevana.ts +++ b/src/source/Cuevana.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, getTmdbNameAndYear, Id, TmdbId } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class Cuevana implements Source { +export class Cuevana extends Source { public readonly id = 'cuevana'; public readonly label = 'Cuevana'; @@ -18,10 +18,12 @@ export class Cuevana implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const [name] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId, 'es'); diff --git a/src/source/Einschalten.ts b/src/source/Einschalten.ts index 36b20a3..636b78a 100644 --- a/src/source/Einschalten.ts +++ b/src/source/Einschalten.ts @@ -1,14 +1,14 @@ import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; interface EinschaltenResponse { releaseName: string; streamUrl: string; } -export class Einschalten implements Source { +export class Einschalten extends Source { public readonly id = 'einschalten'; public readonly label = 'Einschalten'; @@ -22,10 +22,12 @@ export class Einschalten implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const { releaseName, streamUrl } = JSON.parse(await this.fetcher.text(ctx, new URL(`/api/movies/${tmdbId.id}/watch`, this.baseUrl))) as EinschaltenResponse; diff --git a/src/source/Eurostreaming.ts b/src/source/Eurostreaming.ts index 6f1149c..55e7a34 100644 --- a/src/source/Eurostreaming.ts +++ b/src/source/Eurostreaming.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, getTmdbNameAndYear, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class Eurostreaming implements Source { +export class Eurostreaming extends Source { public readonly id = 'eurostreaming'; public readonly label = 'Eurostreaming'; @@ -18,10 +18,12 @@ export class Eurostreaming implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const [name] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId, 'it'); diff --git a/src/source/Frembed.ts b/src/source/Frembed.ts index 68811ca..354e0ad 100644 --- a/src/source/Frembed.ts +++ b/src/source/Frembed.ts @@ -1,9 +1,9 @@ import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class Frembed implements Source { +export class Frembed extends Source { public readonly id = 'frembed'; public readonly label = 'Frembed'; @@ -17,10 +17,12 @@ export class Frembed implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const apiUrl = tmdbId.season diff --git a/src/source/FrenchCloud.ts b/src/source/FrenchCloud.ts index db20e40..7ff9adb 100644 --- a/src/source/FrenchCloud.ts +++ b/src/source/FrenchCloud.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class FrenchCloud implements Source { +export class FrenchCloud extends Source { public readonly id = 'frenchcloud'; public readonly label = 'FrenchCloud'; @@ -18,10 +18,12 @@ export class FrenchCloud implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const pageUrl = new URL(`/movie/${imdbId.id}`, this.baseUrl); diff --git a/src/source/HomeCine.ts b/src/source/HomeCine.ts index 32199ea..2b1bb11 100644 --- a/src/source/HomeCine.ts +++ b/src/source/HomeCine.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, getTmdbNameAndYear, Id, TmdbId } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class HomeCine implements Source { +export class HomeCine extends Source { public readonly id = 'homecine'; public readonly label = 'HomeCine'; @@ -18,10 +18,12 @@ export class HomeCine implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const [name, year] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId, 'es'); diff --git a/src/source/KinoGer.ts b/src/source/KinoGer.ts index c81c969..c71bb07 100644 --- a/src/source/KinoGer.ts +++ b/src/source/KinoGer.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, getTmdbNameAndYear, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class KinoGer implements Source { +export class KinoGer extends Source { public readonly id = 'kinoger'; public readonly label = 'KinoGer'; @@ -18,10 +18,12 @@ export class KinoGer implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const [name, year] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId, 'de'); diff --git a/src/source/MegaKino.ts b/src/source/MegaKino.ts index f8bb933..51e85bb 100644 --- a/src/source/MegaKino.ts +++ b/src/source/MegaKino.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id, ImdbId } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class MegaKino implements Source { +export class MegaKino extends Source { public readonly id = 'megakino'; public readonly label = 'MegaKino'; @@ -18,10 +18,12 @@ export class MegaKino implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const pageUrl = await this.fetchPageUrl(ctx, imdbId); diff --git a/src/source/MeineCloud.ts b/src/source/MeineCloud.ts index f77c857..3f14c10 100644 --- a/src/source/MeineCloud.ts +++ b/src/source/MeineCloud.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class MeineCloud implements Source { +export class MeineCloud extends Source { public readonly id = 'meinecloud'; public readonly label = 'MeineCloud'; @@ -18,10 +18,12 @@ export class MeineCloud implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const pageUrl = new URL(`/movie/${imdbId.id}`, this.baseUrl); diff --git a/src/source/MostraGuarda.ts b/src/source/MostraGuarda.ts index f64f9fa..4d55ef6 100644 --- a/src/source/MostraGuarda.ts +++ b/src/source/MostraGuarda.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class MostraGuarda implements Source { +export class MostraGuarda extends Source { public readonly id = 'mostraguarda'; public readonly label = 'MostraGuarda'; @@ -18,10 +18,12 @@ export class MostraGuarda implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const pageUrl = new URL(`/movie/${imdbId.id}`, this.baseUrl); diff --git a/src/source/Movix.ts b/src/source/Movix.ts index bf23772..eb55380 100644 --- a/src/source/Movix.ts +++ b/src/source/Movix.ts @@ -1,13 +1,13 @@ import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; interface MovixApiData { player_links?: { decoded_url: string }[]; } -export class Movix implements Source { +export class Movix extends Source { public readonly id = 'movix'; public readonly label = 'Movix'; @@ -21,10 +21,12 @@ export class Movix implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const apiUrl = tmdbId.season diff --git a/src/source/PrimeWire.ts b/src/source/PrimeWire.ts index 3051b7b..54abcdf 100644 --- a/src/source/PrimeWire.ts +++ b/src/source/PrimeWire.ts @@ -4,9 +4,9 @@ import { JSDOM } from 'jsdom'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id, ImdbId } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class PrimeWire implements Source { +export class PrimeWire extends Source { public readonly id = 'primewire'; public readonly label = 'PrimeWire'; @@ -22,10 +22,12 @@ export class PrimeWire implements Source { private readonly redirectUrlCache = new Map(); public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); // We need any non-protected entrypoint to grab the app.js diff --git a/src/source/Soaper.ts b/src/source/Soaper.ts index 45feab8..a60d021 100644 --- a/src/source/Soaper.ts +++ b/src/source/Soaper.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, getTmdbNameAndYear, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class Soaper implements Source { +export class Soaper extends Source { public readonly id = 'soaper'; public readonly label = 'Soaper'; @@ -18,10 +18,12 @@ export class Soaper implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const [name, year] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId); diff --git a/src/source/Source.ts b/src/source/Source.ts new file mode 100644 index 0000000..a2ee5a2 --- /dev/null +++ b/src/source/Source.ts @@ -0,0 +1,27 @@ +import { ContentType } from 'stremio-addon-sdk'; +import { Context, CountryCode } from '../types'; +import { Id } from '../utils'; + +export interface SourceResult { + countryCode: CountryCode; + title?: string; + url: URL; +} + +export abstract class Source { + public abstract readonly id: string; + + public abstract readonly label: string; + + public abstract readonly contentTypes: ContentType[]; + + public abstract readonly countryCodes: CountryCode[]; + + public abstract readonly baseUrl: string; + + protected abstract handleInternal(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])>; + + public async handle(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])> { + return await this.handleInternal(ctx, type, id); + } +} diff --git a/src/source/StreamKiste.ts b/src/source/StreamKiste.ts index cd84a45..55d28c6 100644 --- a/src/source/StreamKiste.ts +++ b/src/source/StreamKiste.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id, ImdbId } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class StreamKiste implements Source { +export class StreamKiste extends Source { public readonly id = 'streamkiste'; public readonly label = 'StreamKiste'; @@ -18,10 +18,12 @@ export class StreamKiste implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const seriesPageUrl = await this.fetchSeriesPageUrl(ctx, imdbId); diff --git a/src/source/VerHdLink.ts b/src/source/VerHdLink.ts index bdedc13..788d1fa 100644 --- a/src/source/VerHdLink.ts +++ b/src/source/VerHdLink.ts @@ -2,9 +2,9 @@ import * as cheerio from 'cheerio'; import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class VerHdLink implements Source { +export class VerHdLink extends Source { public readonly id = 'verhdlink'; public readonly label = 'VerHdLink'; @@ -18,10 +18,12 @@ export class VerHdLink implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const pageUrl = new URL(`/movie/${imdbId.id}`, this.baseUrl); diff --git a/src/source/VidSrc.ts b/src/source/VidSrc.ts index 046d833..2b5eb7c 100644 --- a/src/source/VidSrc.ts +++ b/src/source/VidSrc.ts @@ -1,9 +1,9 @@ import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getImdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class VidSrc implements Source { +export class VidSrc extends Source { public readonly id = 'vidsrc'; public readonly label = 'VidSrc'; @@ -17,10 +17,12 @@ export class VidSrc implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); const url = imdbId.season diff --git a/src/source/VixSrc.ts b/src/source/VixSrc.ts index 6170c77..5c77390 100644 --- a/src/source/VixSrc.ts +++ b/src/source/VixSrc.ts @@ -1,9 +1,9 @@ import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class VixSrc implements Source { +export class VixSrc extends Source { public readonly id = 'vixsrc'; public readonly label = 'VixSrc'; @@ -17,10 +17,12 @@ export class VixSrc implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const url = tmdbId.season diff --git a/src/source/XPrime.ts b/src/source/XPrime.ts index 5d68815..51dd166 100644 --- a/src/source/XPrime.ts +++ b/src/source/XPrime.ts @@ -1,9 +1,9 @@ import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode } from '../types'; import { Fetcher, getTmdbId, getTmdbNameAndYear, Id } from '../utils'; -import { Source, SourceResult } from './types'; +import { Source, SourceResult } from './Source'; -export class XPrime implements Source { +export class XPrime extends Source { public readonly id = 'xprime'; public readonly label = 'XPrime'; @@ -17,10 +17,12 @@ export class XPrime implements Source { private readonly fetcher: Fetcher; public constructor(fetcher: Fetcher) { + super(); + this.fetcher = fetcher; } - public async handle(ctx: Context, _type: string, id: Id): Promise { + public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const tmdbId = await getTmdbId(ctx, this.fetcher, id); const [name, year] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId); diff --git a/src/source/index.ts b/src/source/index.ts index 3129202..ee8a248 100644 --- a/src/source/index.ts +++ b/src/source/index.ts @@ -13,14 +13,14 @@ import { MostraGuarda } from './MostraGuarda'; import { Movix } from './Movix'; import { PrimeWire } from './PrimeWire'; import { Soaper } from './Soaper'; +import { Source } from './Source'; import { StreamKiste } from './StreamKiste'; -import { Source } from './types'; import { VerHdLink } from './VerHdLink'; import { VidSrc } from './VidSrc'; import { VixSrc } from './VixSrc'; import { XPrime } from './XPrime'; -export * from './types'; +export * from './Source'; export const createSources = (fetcher: Fetcher): Source[] => [ // multi diff --git a/src/source/types.ts b/src/source/types.ts deleted file mode 100644 index 7f60699..0000000 --- a/src/source/types.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ContentType } from 'stremio-addon-sdk'; -import { Context, CountryCode } from '../types'; -import { Id } from '../utils'; - -export interface SourceResult { - countryCode: CountryCode; - title?: string; - url: URL; -} - -export interface Source { - readonly id: string; - - readonly label: string; - - readonly contentTypes: ContentType[]; - - readonly countryCodes: CountryCode[]; - - readonly baseUrl: string; - - handle(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])>; -} diff --git a/src/utils/StreamResolver.test.ts b/src/utils/StreamResolver.test.ts index 54bea4c..222a6b3 100644 --- a/src/utils/StreamResolver.test.ts +++ b/src/utils/StreamResolver.test.ts @@ -79,7 +79,7 @@ describe('resolve', () => { }); test('adds error info', async () => { - class MockSource implements Source { + class MockSource extends Source { public readonly id = 'mocksource'; public readonly label = 'MockSource'; @@ -90,7 +90,7 @@ describe('resolve', () => { public readonly baseUrl = 'https://example.com'; - public readonly handle = async (): Promise => { + public readonly handleInternal = async (): Promise => { return [{ countryCode: CountryCode.de, url: new URL('https://example.com') }]; }; } @@ -258,17 +258,25 @@ describe('resolve', () => { }); test('ignores not found errors', async () => { - const mockHandler: Source = { - id: 'mocksource', - label: 'MockSource', - contentTypes: ['movie'], - countryCodes: [CountryCode.de], - baseUrl: 'https://example.com', - handle: jest.fn().mockRejectedValue(new NotFoundError()), - }; + class MockSource extends Source { + public readonly id = 'mocksource'; + + public readonly label = 'MockSource'; + + public readonly contentTypes: ContentType[] = ['movie']; + + public readonly countryCodes: CountryCode[] = [CountryCode.de]; + + public readonly baseUrl = 'https://example.com'; + + public readonly handleInternal = async (): Promise => { + throw new NotFoundError(); + }; + } + const streamResolver = new StreamResolver(logger, new ExtractorRegistry(logger, createExtractors(fetcher))); - const streams = await streamResolver.resolve(ctx, [mockHandler], 'movie', new ImdbId('tt12345678', undefined, undefined)); + const streams = await streamResolver.resolve(ctx, [new MockSource()], 'movie', new ImdbId('tt12345678', undefined, undefined)); expect(streams).toMatchSnapshot(); });