2021-07-13 19:15:56 +02:00
|
|
|
function getCorsUrl(url) {
|
|
|
|
return `https://hidden-inlet-27205.herokuapp.com/${url}`;
|
2021-07-13 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getVideoUrl(config) {
|
|
|
|
const accessToken = await getAccessToken(config);
|
|
|
|
const now = Math.floor(Date.now() / 1e3);
|
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
let url = getCorsUrl(`https://lookmovie.io/manifests/movies/json/${config.movieId}/${now}/${accessToken}/master.m3u8`);
|
2021-07-13 17:45:44 +02: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 19:15:56 +02:00
|
|
|
return videoUrl.startsWith("/") ? getCorsUrl(`https://lookmovie.io/${videoUrl}`) : getCorsUrl(videoUrl);
|
2021-07-13 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "Invalid type.";
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getAccessToken(config) {
|
2021-07-13 19:15:56 +02:00
|
|
|
let url = getCorsUrl(`https://lookmovie.io/api/v1/security/movie-access?id_movie=${config.movieId}&token=1&sk=&step=1`);
|
2021-07-13 17:45:44 +02: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";
|
|
|
|
}
|
|
|
|
|
|
|
|
async function findMovie() {
|
|
|
|
const searchTerm = document.getElementById('search').value;
|
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
sendMessage('info', `Searching for "${searchTerm}"`)
|
|
|
|
|
|
|
|
const searchUrl = getCorsUrl(`https://lookmovie.io/api/v1/movies/search/?q=${encodeURIComponent(searchTerm)}`);
|
|
|
|
const searchRes = await fetch(searchUrl).then((d) => d.json());
|
|
|
|
let results = [ ...searchRes.result.map((v) => ({ ...v, type: "movie" })) ];
|
|
|
|
|
|
|
|
const fuse = new Fuse(results, { threshold: 0.3, distance: 200, keys: ["title"] });
|
2021-07-13 17:45:44 +02:00
|
|
|
const matchedResults = fuse
|
|
|
|
.search(searchTerm.toString())
|
|
|
|
.map((result) => result.item);
|
|
|
|
|
|
|
|
let toShow;
|
|
|
|
if (matchedResults.length > 1) {
|
|
|
|
const response = window.prompt(`Pick a movie from:\n${matchedResults.map((i, v) => `${v}) ${i.title}`).join('\n')}`, 'Enter number');
|
|
|
|
toShow = matchedResults[response];
|
|
|
|
} else {
|
|
|
|
toShow = matchedResults[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!toShow) {
|
2021-07-13 19:15:56 +02:00
|
|
|
sendMessage('error', 'Unable to find that, sorry!')
|
2021-07-13 17:45:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
sendMessage('info', `Scraping the ${toShow.type} "${toShow.title}"`)
|
2021-07-13 17:45:44 +02:00
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
const url = getCorsUrl(`https://lookmovie.io/${toShow.type}s/view/${toShow.slug}`);
|
2021-07-13 17:45:44 +02:00
|
|
|
const pageReq = await fetch(url).then((d) => d.text());
|
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
const data = JSON5.parse("{" +
|
2021-07-13 17:45:44 +02:00
|
|
|
pageReq
|
|
|
|
.slice(pageReq.indexOf(`${toShow.type}_storage`))
|
|
|
|
.split("};")[0]
|
|
|
|
.split("= {")[1]
|
|
|
|
.trim() +
|
2021-07-13 19:15:56 +02:00
|
|
|
"}"
|
|
|
|
);
|
2021-07-13 17:45:44 +02:00
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
const videoUrl = await getVideoUrl({
|
|
|
|
slug: toShow.slug,
|
|
|
|
movieId: data.id_movie,
|
|
|
|
type: "movie",
|
|
|
|
});
|
2021-07-13 17:45:44 +02:00
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
sendMessage('info', `Streaming "${toShow.title}"`)
|
|
|
|
streamVideo(videoUrl)
|
|
|
|
}
|
2021-07-13 17:45:44 +02:00
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
function sendMessage(type, message) {
|
|
|
|
if (!['info', 'error'].includes(type)) return;
|
|
|
|
document.getElementById(type).innerHTML += `${message}<br>`;
|
|
|
|
}
|
2021-07-13 17:45:44 +02:00
|
|
|
|
2021-07-13 19:15:56 +02:00
|
|
|
function streamVideo(url) {
|
2021-07-13 17:45:44 +02:00
|
|
|
var video = document.getElementById('video');
|
2021-07-13 19:15:56 +02:00
|
|
|
|
2021-07-13 17:45:44 +02:00
|
|
|
if (Hls.isSupported()) {
|
|
|
|
var video = document.getElementById('video');
|
|
|
|
var hls = new Hls();
|
|
|
|
hls.attachMedia(video);
|
2021-07-13 19:15:56 +02:00
|
|
|
hls.loadSource(url);
|
2021-07-13 17:45:44 +02:00
|
|
|
}
|
|
|
|
}
|