From 80cad8f8f2a34618dbed0122511b4e39a7ea5924 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Thu, 17 Feb 2022 18:24:21 +0100 Subject: [PATCH] implemented theflix scrapers + better search component Co-authored-by: James Hawkins --- src/scrapers/wrapper.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/scrapers/wrapper.ts diff --git a/src/scrapers/wrapper.ts b/src/scrapers/wrapper.ts new file mode 100644 index 00000000..60b8bf08 --- /dev/null +++ b/src/scrapers/wrapper.ts @@ -0,0 +1,30 @@ +import { MWMedia, MWMediaProvider, MWPortableMedia, MWQuery } from "./types"; + +export interface MWWrappedMediaProvider extends MWMediaProvider { + getMediaFromPortable(media: MWPortableMedia): Promise; + searchForMedia(query: MWQuery): Promise; +} + +export function WrapProvider( + provider: MWMediaProvider +): MWWrappedMediaProvider { + return { + ...provider, + + async getMediaFromPortable(media: MWPortableMedia): Promise { + return { + ...(await provider.getMediaFromPortable(media)), + providerId: provider.id, + mediaType: media.mediaType, + }; + }, + + async searchForMedia(query: MWQuery): Promise { + return (await provider.searchForMedia(query)).map((m) => ({ + ...m, + providerId: provider.id, + mediaType: query.type, + })); + }, + }; +}