From fbd0f57a73680987790a16ec49d5108d9e133f1a Mon Sep 17 00:00:00 2001 From: mansoor-roeen-glitch <75437785+mansoor-roeen-glitch@users.noreply.github.com> Date: Mon, 13 Sep 2021 23:55:29 +0530 Subject: [PATCH] Update lookmovie.js --- src/lib/scraper/lookmovie.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/lib/scraper/lookmovie.js b/src/lib/scraper/lookmovie.js index 5b28f120..4e7fe627 100644 --- a/src/lib/scraper/lookmovie.js +++ b/src/lib/scraper/lookmovie.js @@ -50,9 +50,19 @@ async function findContent(searchTerm, type) { } } async function getVideoUrl(config) { - const accessToken = await getAccessToken(config); + const accessInfo = await getAccessToken(config); + const accessToken = accessInfo.token; + const subtitles = accessInfo.subtitles; const now = Math.floor(Date.now() / 1e3); + let subs; + + if (config.type === "show") { + subs = await getEpisodeSubs(config) + } else if (config.type === "movie") { + subs = subtitles + } + let url = ''; if (config.type === 'movie') { @@ -73,7 +83,11 @@ async function getVideoUrl(config) { } } - return videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl; + return {videoUrl: videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl, subs}; +} + +async function getEpisodeSubs (config) { + return await fetch(`${BASE_URL}/api/v1/shows/episode-subtitles/?id_episode=${config.id}`).then(res => res.json()); } async function getAccessToken(config) { @@ -86,9 +100,11 @@ async function getAccessToken(config) { } const data = await fetch(url).then((d) => d.json()); - + const token = data?.data?.accessToken; - if (token) return token; + let subtitles = data?.data?.subtitles; + + if (token) return {token, subtitles}; return "Invalid type provided in config"; } @@ -121,6 +137,7 @@ async function getEpisodes(slug) { } async function getStreamUrl(slug, type, season, episode) { + const url = `${BASE_URL}/${type}s/view/${slug}`; const pageReq = await fetch(url).then((d) => d.text()); @@ -153,11 +170,11 @@ async function getStreamUrl(slug, type, season, episode) { slug: slug, id: id, type: type, - }); + }); - return { url: videoUrl } + return { url: videoUrl.videoUrl, subtitles: videoUrl.subs }; } const lookMovie = { findContent, getStreamUrl, getEpisodes }; -export default lookMovie; \ No newline at end of file +export default lookMovie;