From bc0f9a6abff9ab90b7106456f852de9fffbf8276 Mon Sep 17 00:00:00 2001 From: Jordaar <69628820+Jordaar@users.noreply.github.com> Date: Fri, 16 Jun 2023 16:15:41 +0530 Subject: [PATCH] feat(kissasian): additional mp4upload embed scraper --- src/backend/providers/kissasian.ts | 54 ++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/backend/providers/kissasian.ts b/src/backend/providers/kissasian.ts index 8d4e50c4..90708970 100644 --- a/src/backend/providers/kissasian.ts +++ b/src/backend/providers/kissasian.ts @@ -5,6 +5,17 @@ import { MWMediaType } from "../metadata/types"; const kissasianBase = "https://kissasian.li"; +const embedProviders = [ + { + type: MWEmbedType.MP4UPLOAD, + id: "mp", + }, + { + type: MWEmbedType.STREAMSB, + id: "sb", + }, +]; + registerProvider({ id: "kissasian", displayName: "KissAsian", @@ -65,37 +76,44 @@ registerProvider({ ?.querySelector("td.episodeSub a") ?.textContent?.split("Episode")[1] ?.trim(); - const href = ep?.querySelector("td.episodeSub a")?.getAttribute("href"); - return { number, href }; + const url = ep?.querySelector("td.episodeSub a")?.getAttribute("href"); + return { number, url }; }) - .filter((e) => !!e.href); + .filter((e) => !!e.url); const targetEpisode = media.meta.type === MWMediaType.MOVIE ? episodes[0] : episodes.find((e) => e.number === `${episodeNumber}`); - if (!targetEpisode?.href) throw new Error("Episode not found"); + if (!targetEpisode?.url) throw new Error("Episode not found"); progress(70); - const watch = await proxiedFetch(`${targetEpisode.href}&s=sb`, { - baseURL: kissasianBase, - }); + let embeds = await Promise.all( + embedProviders.map(async (provider) => { + const watch = await proxiedFetch( + `${targetEpisode.url}&s=${provider.id}`, + { + baseURL: kissasianBase, + } + ); - const watchPage = new DOMParser().parseFromString(watch, "text/html"); + const watchPage = new DOMParser().parseFromString(watch, "text/html"); - const streamsbUrl = watchPage - .querySelector("iframe[id=my_video_1]") - ?.getAttribute("src"); - if (!streamsbUrl) throw new Error("Streamsb embed not found"); + const embedUrl = watchPage + .querySelector("iframe[id=my_video_1]") + ?.getAttribute("src"); + + return { + type: provider.type, + url: embedUrl ?? "", + }; + }) + ); + embeds = embeds.filter((e) => e.url !== ""); return { - embeds: [ - { - type: MWEmbedType.STREAMSB, - url: streamsbUrl, - }, - ], + embeds, }; }, });