From a371f86933f972357148b3fa11cd9047cc14ddca Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:46:51 +0000 Subject: [PATCH] fix(source): handle non-existent movies gracefully --- src/source/Movix.test.ts | 7 ++++++- src/source/Movix.ts | 4 ++-- .../Movix/https:api.movix.siteapitmdbmovie548473 | 1 + src/source/__snapshots__/Movix.test.ts.snap | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 src/source/__fixtures__/Movix/https:api.movix.siteapitmdbmovie548473 diff --git a/src/source/Movix.test.ts b/src/source/Movix.test.ts index 14771c9..3a24a48 100644 --- a/src/source/Movix.test.ts +++ b/src/source/Movix.test.ts @@ -11,11 +11,16 @@ describe('Movix', () => { handler = new Movix(new FetcherMock(`${__dirname}/__fixtures__/Movix`)); }); - test('handles non-existent content gracefully', async () => { + test('handles non-existent show gracefully', async () => { const streams = await handler.handle(ctx, 'series', new TmdbId(46080, 1, 999)); expect(streams).toMatchSnapshot(); }); + test('handles non-existent movie gracefully', async () => { + const streams = await handler.handle(ctx, 'series', new TmdbId(548473, undefined, undefined)); + expect(streams).toMatchSnapshot(); + }); + test('handle tmdb black mirror s4e2', async () => { const streams = await handler.handle(ctx, 'series', new TmdbId(42009, 4, 2)); expect(streams).toMatchSnapshot(); diff --git a/src/source/Movix.ts b/src/source/Movix.ts index 3d596fb..538d199 100644 --- a/src/source/Movix.ts +++ b/src/source/Movix.ts @@ -4,7 +4,7 @@ import { Fetcher, getTmdbId, Id } from '../utils'; import { Source, SourceResult } from './types'; interface MovixApiData { - player_links: { decoded_url: string }[]; + player_links?: { decoded_url: string }[]; } export class Movix implements Source { @@ -34,7 +34,7 @@ export class Movix implements Source { const json = JSON.parse(await this.fetcher.text(ctx, apiUrl)); const data: MovixApiData | undefined = tmdbId.season ? json['current_episode'] : json; - if (!data) { + if (!data || !data.player_links) { return []; } diff --git a/src/source/__fixtures__/Movix/https:api.movix.siteapitmdbmovie548473 b/src/source/__fixtures__/Movix/https:api.movix.siteapitmdbmovie548473 new file mode 100644 index 0000000..bcd5965 --- /dev/null +++ b/src/source/__fixtures__/Movix/https:api.movix.siteapitmdbmovie548473 @@ -0,0 +1 @@ +{"message":"Contenu non disponible","tmdb_id":"548473","tmdb_details":{"id":548473,"title":"La couleur tombée du ciel","original_title":"Color Out of Space","release_date":"2020-01-24","poster_path":"/nVwMu8nExJIsnQt1hheoBd85wdR.jpg","backdrop_path":"/iyn2JQsftaqhQlXYaCCvn8udM5i.jpg","overview":"Après la chute d’une météorite dans le jardin de leur ferme, Nathan Gardner et sa famille se retrouvent à combattre un organisme extraterrestre et mutant qui s’est introduit dans leurs corps et leurs cerveaux. La quiétude de leur vie à la campagne va se transformer en cauchemar en technicolor.","vote_average":6}} \ No newline at end of file diff --git a/src/source/__snapshots__/Movix.test.ts.snap b/src/source/__snapshots__/Movix.test.ts.snap index df60715..03ff371 100644 --- a/src/source/__snapshots__/Movix.test.ts.snap +++ b/src/source/__snapshots__/Movix.test.ts.snap @@ -135,4 +135,6 @@ exports[`Movix handle tmdb black mirror s4e2 1`] = ` ] `; -exports[`Movix handles non-existent content gracefully 1`] = `[]`; +exports[`Movix handles non-existent movie gracefully 1`] = `[]`; + +exports[`Movix handles non-existent show gracefully 1`] = `[]`;