diff --git a/src/handler/Frembed.test.ts b/src/handler/Frembed.test.ts index db564e1..73c478c 100644 --- a/src/handler/Frembed.test.ts +++ b/src/handler/Frembed.test.ts @@ -12,13 +12,24 @@ const handler = new Frembed(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { fr: 'on' } }; describe('Frembed', () => { - test('does not handle non imdb series', async () => { + test('does not handle non imdb and tmdb series', async () => { const streams = await handler.handle(ctx, 'series', 'kitsu:123'); expect(streams).toHaveLength(0); }); - test('handle imdb black mirror s4e2', async () => { + test('handle imdb black mirror s4e2 via imdb', async () => { const streams = (await handler.handle(ctx, 'series', 'tt2085059:4:2')).filter(stream => stream !== undefined); expect(streams).toMatchSnapshot(); }); + + test('handle imdb black mirror s4e2 via tmdb', async () => { + const streams = (await handler.handle(ctx, 'series', '42009:4:2')).filter(stream => stream !== undefined); + + const streamsWithoutTtl = streams.map((stream) => { + delete stream.ttl; + return stream; + }); // to avoid flakyness because this is served from cache with lower ttl :) + + expect(streamsWithoutTtl).toMatchSnapshot(); + }); }); diff --git a/src/handler/Frembed.ts b/src/handler/Frembed.ts index 5dc235a..4f76d95 100644 --- a/src/handler/Frembed.ts +++ b/src/handler/Frembed.ts @@ -1,5 +1,5 @@ import { Handler } from './types'; -import { parseImdbId, Fetcher, getTmdbIdFromImdbId } from '../utils'; +import { parseImdbId, Fetcher, getTmdbIdFromImdbId, TmdbId, parseTmdbId } from '../utils'; import { ExtractorRegistry } from '../extractor'; import { Context, CountryCode } from '../types'; @@ -21,12 +21,15 @@ export class Frembed implements Handler { } readonly handle = async (ctx: Context, _type: string, id: string) => { - if (!id.startsWith('tt')) { + let tmdbId: TmdbId; + if (id.startsWith('tt')) { + tmdbId = await getTmdbIdFromImdbId(ctx, this.fetcher, parseImdbId(id)); + } else if (/^\d+:/.test(id)) { + tmdbId = parseTmdbId(id); + } else { return []; } - const tmdbId = await getTmdbIdFromImdbId(ctx, this.fetcher, parseImdbId(id)); - const apiUrl = new URL(`https://frembed.space/api/series?id=${tmdbId.id}&sa=${tmdbId.series}&epi=${tmdbId.episode}&idType=tmdb`); const json = JSON.parse(await this.fetcher.text(ctx, apiUrl)); diff --git a/src/handler/__snapshots__/Frembed.test.ts.snap b/src/handler/__snapshots__/Frembed.test.ts.snap index 9812325..6c47f66 100644 --- a/src/handler/__snapshots__/Frembed.test.ts.snap +++ b/src/handler/__snapshots__/Frembed.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Frembed handle imdb black mirror s4e2 1`] = ` +exports[`Frembed handle imdb black mirror s4e2 via imdb 1`] = ` [ { "label": "DoodStream", @@ -50,3 +50,51 @@ exports[`Frembed handle imdb black mirror s4e2 1`] = ` }, ] `; + +exports[`Frembed handle imdb black mirror s4e2 via tmdb 1`] = ` +[ + { + "label": "DoodStream", + "meta": { + "countryCode": "fr", + "title": "Black Mirror 4x2", + }, + "requestHeaders": { + "Referer": "http://dood.to/", + }, + "sourceId": "doodstream_fr", + "url": "https://ee317r.cloudatacdn.com/u5kj63yvxddlsdgge7qremqqka27irwiupc4k7o5cikbh7fdq4j4mwzraf7q/1y4sn4ndoi~mocked-random-string?token=fh3rdlhjvao7chgxndsi3ra7&expiry=639837296000", + }, + { + "isExternal": true, + "label": "netu.fanstream.us", + "meta": { + "countryCode": "fr", + "title": "Black Mirror 4x2", + }, + "sourceId": "external_fr", + "url": "https://netu.fanstream.us/e/0DFgfkcXOsDP", + }, + { + "isExternal": true, + "label": "johnalwayssame.com", + "meta": { + "countryCode": "fr", + "title": "Black Mirror 4x2", + }, + "sourceId": "external_fr", + "url": "https://johnalwayssame.com/e/cqy9oue7sv0g", + }, + { + "error": [Error: TypeError: fetch failed], + "isExternal": true, + "label": "ds2play.com", + "meta": { + "countryCode": "fr", + "title": "Black Mirror 4x2", + }, + "sourceId": "external", + "url": "https://ds2play.com/e/fzfvfq3ngig0", + }, +] +`;