sudo-archive/src/lib/lookMovie.js

125 lines
3.8 KiB
JavaScript
Raw Normal View History

2021-07-13 22:31:37 +00:00
import Fuse from 'fuse.js'
import JSON5 from 'json5'
2021-07-13 17:15:56 +00:00
function getCorsUrl(url) {
return `https://hidden-inlet-27205.herokuapp.com/${url}`;
2021-07-13 15:45:44 +00:00
}
async function getVideoUrl(config) {
2021-07-14 16:31:35 +00:00
// return getCorsUrl('https://vdoc1.sallenes.space/_eTeNnlOAFdWb-gPYTiQfg/1626297249/storage3/shows/0413573-greys-anatomy-2005/6-S1E1-1553949090/720p/v2-index.m3u8');
2021-07-13 15:45:44 +00:00
const accessToken = await getAccessToken(config);
const now = Math.floor(Date.now() / 1e3);
2021-07-14 16:31:35 +00:00
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`);
}
2021-07-13 15:45:44 +00:00
if (url) {
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]
}
}
2021-07-13 17:15:56 +00:00
return videoUrl.startsWith("/") ? getCorsUrl(`https://lookmovie.io/${videoUrl}`) : getCorsUrl(videoUrl);
2021-07-13 15:45:44 +00:00
}
return "Invalid type.";
}
async function getAccessToken(config) {
2021-07-14 16:31:35 +00:00
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`);
}
2021-07-13 15:45:44 +00:00
const data = await fetch(url).then((d) => d.json());
const token = data?.data?.accessToken;
if (token) return token;
return "Invalid type provided in config";
}
2021-07-14 16:31:35 +00:00
async function getStreamUrl(slug, type, season, episode) {
2021-07-13 22:31:37 +00:00
const url = getCorsUrl(`https://lookmovie.io/${type}s/view/${slug}`);
2021-07-13 15:45:44 +00:00
const pageReq = await fetch(url).then((d) => d.text());
2021-07-13 17:15:56 +00:00
const data = JSON5.parse("{" +
2021-07-13 15:45:44 +00:00
pageReq
2021-07-13 22:31:37 +00:00
.slice(pageReq.indexOf(`${type}_storage`))
2021-07-13 15:45:44 +00:00
.split("};")[0]
.split("= {")[1]
.trim() +
2021-07-13 17:15:56 +00:00
"}"
);
2021-07-13 15:45:44 +00:00
2021-07-14 16:31:35 +00:00
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;
}
}
2021-07-13 17:15:56 +00:00
const videoUrl = await getVideoUrl({
2021-07-13 22:31:37 +00:00
slug: slug,
2021-07-14 16:31:35 +00:00
id: id,
type: type,
2021-07-13 17:15:56 +00:00
});
2021-07-13 15:45:44 +00:00
2021-07-13 22:31:37 +00:00
return { url: videoUrl }
2021-07-13 17:15:56 +00:00
}
2021-07-13 15:45:44 +00:00
2021-07-14 16:31:35 +00:00
async function findContent(searchTerm, type) {
const searchUrl = getCorsUrl(`https://lookmovie.io/api/v1/${type}s/search/?q=${encodeURIComponent(searchTerm)}`);
2021-07-13 22:31:37 +00:00
const searchRes = await fetch(searchUrl).then((d) => d.json());
2021-07-14 16:31:35 +00:00
const results = [...searchRes.result.map((v) => ({ ...v, type: type}))];
2021-07-13 22:31:37 +00:00
const fuse = new Fuse(results, { threshold: 0.3, distance: 200, keys: ["title"] });
const matchedResults = fuse
.search(searchTerm.toString())
.map((result) => result.item);
2021-07-13 15:45:44 +00:00
2021-07-13 22:31:37 +00:00
if (matchedResults.length === 0) {
return { options: [] }
}
2021-07-13 17:15:56 +00:00
2021-07-13 22:31:37 +00:00
if (matchedResults.length > 1) {
const res = { options: [] };
matchedResults.forEach((r) => res.options.push({
title: r.title,
slug: r.slug,
type: r.type,
year: r.year
2021-07-13 22:31:37 +00:00
}));
return res;
} else {
const { title, slug, type, year } = matchedResults[0];
2021-07-13 22:31:37 +00:00
return {
options: [{ title, slug, type, year }]
2021-07-13 22:31:37 +00:00
}
2021-07-13 15:45:44 +00:00
}
2021-07-13 22:31:37 +00:00
}
2021-07-14 15:15:25 +00:00
export { findContent, getStreamUrl };