diff --git a/src/lib/scraper/lookmovie.js b/src/lib/scraper/lookmovie.js index 2ae6a5e6..9fafd3ce 100644 --- a/src/lib/scraper/lookmovie.js +++ b/src/lib/scraper/lookmovie.js @@ -1,121 +1,11 @@ import Fuse from 'fuse.js' import JSON5 from 'json5' -function getCorsUrl(url) { - return `https://movie-web-proxy.herokuapp.com/${url}`; -} - -async function getVideoUrl(config) { - const accessToken = await getAccessToken(config); - const now = Math.floor(Date.now() / 1e3); - - let url = ''; - - if (config.type === 'movie') { - url = getCorsUrl(`https://lookmovie.io/manifests/movies/json/${config.id}/${now}/${accessToken}/master.m3u8`); - } else if (config.type === 'show') { - url = getCorsUrl(`https://lookmovie.io/manifests/shows/json/${accessToken}/${now}/${config.id}/master.m3u8`); - } - - const videoOpts = await fetch(url).then((d) => d.json()); - - // Find video URL and return it (with a check for a full url if needed) - const opts = ["1080p", "1080", "720p", "720", "480p", "480", "auto"] - - let videoUrl = ""; - for (let res of opts) { - if (videoOpts[res] && !videoOpts[res].includes('dummy') && !videoOpts[res].includes('earth-1984') && !videoUrl) { - videoUrl = videoOpts[res] - } - } - - return videoUrl.startsWith("/") ? `https://lookmovie.io${videoUrl}` : videoUrl; -} - -async function getAccessToken(config) { - let url = ''; - - if (config.type === 'movie') { - url = getCorsUrl(`https://lookmovie.io/api/v1/security/movie-access?id_movie=${config.id}&token=1&sk=&step=1`); - } else if (config.type === 'show') { - url = getCorsUrl(`https://lookmovie.io/api/v1/security/show-access?slug=${config.slug}&token=&step=2`); - } - - const data = await fetch(url).then((d) => d.json()); - - const token = data?.data?.accessToken; - if (token) return token; - - return "Invalid type provided in config"; -} - -async function getEpisodes(slug) { - const url = getCorsUrl(`https://lookmovie.io/shows/view/${slug}`); - const pageReq = await fetch(url).then((d) => d.text()); - - const data = JSON5.parse("{" + - pageReq - .slice(pageReq.indexOf(`show_storage`)) - .split("};")[0] - .split("= {")[1] - .trim() + - "}" - ); - - let seasons = []; - let episodes = []; - data.seasons.forEach((e) => { - if (!seasons.includes(e.season)) - seasons.push(e.season); - - if (!episodes[e.season]) - episodes[e.season] = [] - episodes[e.season].push(e.episode) - }) - - return { seasons, episodes } -} - -async function getStreamUrl(slug, type, season, episode) { - const url = getCorsUrl(`https://lookmovie.io/${type}s/view/${slug}`); - const pageReq = await fetch(url).then((d) => d.text()); - - const data = JSON5.parse("{" + - pageReq - .slice(pageReq.indexOf(`${type}_storage`)) - .split("};")[0] - .split("= {")[1] - .trim() + - "}" - ); - - let id = ''; - - if (type === "movie") { - id = data.id_movie; - } else if (type === "show") { - const episodeObj = data.seasons.find((v) => { return v.season === season && v.episode === episode; }); - - if (episodeObj) { - id = episodeObj.id_episode; - } - } - - if (id === '') { - return { url: '' } - } - - const videoUrl = await getVideoUrl({ - slug: slug, - id: id, - type: type, - }); - - return { url: videoUrl } -} +const CORS_URL = `https://movie-web-proxy.herokuapp.com`; +const BASE_URL = `${CORS_URL}/https://lookmovie.io`; async function findContent(searchTerm, type) { - const searchUrl = getCorsUrl(`https://lookmovie.io/${type}s/search/?q=${encodeURIComponent(searchTerm)}`); + const searchUrl = `${BASE_URL}/${type}s/search/?q=${encodeURIComponent(searchTerm)}`; const searchRes = await fetch(searchUrl).then((d) => d.text()); // Parse DOM to find search results on full search page @@ -160,6 +50,115 @@ async function findContent(searchTerm, type) { } } } +async function getVideoUrl(config) { + const accessToken = await getAccessToken(config); + const now = Math.floor(Date.now() / 1e3); + + let url = ''; + + if (config.type === 'movie') { + url = `${BASE_URL}/manifests/movies/json/${config.id}/${now}/${accessToken}/master.m3u8`; + } else if (config.type === 'show') { + url = `${BASE_URL}/manifests/shows/json/${accessToken}/${now}/${config.id}/master.m3u8`; + } + + const videoOpts = await fetch(url).then((d) => d.json()); + + // Find video URL and return it (with a check for a full url if needed) + const opts = ["1080p", "1080", "720p", "720", "480p", "480", "auto"] + + let videoUrl = ""; + for (let res of opts) { + if (videoOpts[res] && !videoOpts[res].includes('dummy') && !videoOpts[res].includes('earth-1984') && !videoUrl) { + videoUrl = videoOpts[res] + } + } + + return videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl; +} + +async function getAccessToken(config) { + let url = ''; + + if (config.type === 'movie') { + url = `${BASE_URL}/api/v1/security/movie-access?id_movie=${config.id}&token=1&sk=&step=1`; + } else if (config.type === 'show') { + url = `${BASE_URL}/api/v1/security/show-access?slug=${config.slug}&token=&step=2`; + } + + const data = await fetch(url).then((d) => d.json()); + + const token = data?.data?.accessToken; + if (token) return token; + + return "Invalid type provided in config"; +} + +async function getEpisodes(slug) { + const url = `${BASE_URL}/shows/view/${slug}`; + const pageReq = await fetch(url).then((d) => d.text()); + + const data = JSON5.parse("{" + + pageReq + .slice(pageReq.indexOf(`show_storage`)) + .split("};")[0] + .split("= {")[1] + .trim() + + "}" + ); + + let seasons = []; + let episodes = []; + data.seasons.forEach((e) => { + if (!seasons.includes(e.season)) + seasons.push(e.season); + + if (!episodes[e.season]) + episodes[e.season] = [] + episodes[e.season].push(e.episode) + }) + + return { seasons, episodes } +} + +async function getStreamUrl(slug, type, season, episode) { + const url = `${BASE_URL}/${type}s/view/${slug}`; + const pageReq = await fetch(url).then((d) => d.text()); + + const data = JSON5.parse("{" + + pageReq + .slice(pageReq.indexOf(`${type}_storage`)) + .split("};")[0] + .split("= {")[1] + .trim() + + "}" + ); + + let id = ''; + + if (type === "movie") { + id = data.id_movie; + } else if (type === "show") { + const episodeObj = data.seasons.find((v) => { return v.season === season && v.episode === episode; }); + + if (episodeObj) { + id = episodeObj.id_episode; + } + } + + if (id === '') { + return { url: '' } + } + + const videoUrl = await getVideoUrl({ + slug: slug, + id: id, + type: type, + }); + + return { url: videoUrl } +} + const lookMovie = { findContent, getStreamUrl, getEpisodes }; export default lookMovie; \ No newline at end of file