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, + })); + }, + }; +}