From be3f631ca93d6a6c30359a75aa13afd6c8740145 Mon Sep 17 00:00:00 2001 From: mansoor-roeen-glitch <75437785+mansoor-roeen-glitch@users.noreply.github.com> Date: Tue, 14 Sep 2021 01:56:29 +0530 Subject: [PATCH] Update lookmovie.js --- src/lib/scraper/lookmovie.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/scraper/lookmovie.js b/src/lib/scraper/lookmovie.js index a7cc1779..f7afb07e 100644 --- a/src/lib/scraper/lookmovie.js +++ b/src/lib/scraper/lookmovie.js @@ -50,17 +50,15 @@ async function findContent(searchTerm, type) { } } async function getVideoUrl(config) { - const accessInfo = await getAccessToken(config); - const accessToken = accessInfo.token; - const subtitles = accessInfo.subtitles; + const { subtitles, token: accessToken } = await getAccessInfo(config); const now = Math.floor(Date.now() / 1e3); let subs; if (config.type === "show") { - subs = await getEpisodeSubs(config) + subs = await getEpisodeSubs(config); } else if (config.type === "movie") { - subs = subtitles + subs = subtitles; } let url = ''; @@ -83,14 +81,17 @@ async function getVideoUrl(config) { } } - return {videoUrl: videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl, subs}; + 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) { +async function getAccessInfo(config) { let url = ''; if (config.type === 'movie') { @@ -100,11 +101,11 @@ async function getAccessToken(config) { } const data = await fetch(url).then((d) => d.json()); - - const token = data?.data?.accessToken; - let subtitles = data?.data?.subtitles; - if (token) return {token, subtitles}; + const token = data?.data?.accessToken; + const subtitles = data?.data?.subtitles; + + if (token) return { token, subtitles }; return "Invalid type provided in config"; }