2021-07-21 00:49:33 +02:00
|
|
|
import { unpack } from './util/unpacker';
|
2021-07-19 23:26:49 +02:00
|
|
|
|
2021-07-21 11:22:40 +02:00
|
|
|
const CORS_URL = 'https://safe-reaches-91175.herokuapp.com/';
|
2021-07-19 16:32:40 +02:00
|
|
|
const BASE_URL = `${CORS_URL}https://gomo.to`;
|
|
|
|
const MOVIE_URL = `${BASE_URL}/movie`
|
|
|
|
const DECODING_URL = `${BASE_URL}/decoding_v3.php`
|
|
|
|
|
2021-07-20 12:20:56 +02:00
|
|
|
async function findContent(searchTerm, type) {
|
2021-07-19 16:32:40 +02:00
|
|
|
try {
|
|
|
|
if (type !== 'movie') return;
|
|
|
|
|
|
|
|
const term = searchTerm.toLowerCase()
|
|
|
|
const imdbRes = await fetch(`${CORS_URL}https://v2.sg.media-imdb.com/suggestion/${term.slice(0, 1)}/${term}.json`).then(d => d.json())
|
2021-07-19 23:26:49 +02:00
|
|
|
|
|
|
|
const results = [];
|
|
|
|
imdbRes.d.forEach((e) => {
|
|
|
|
if (!e.id.startsWith('tt')) return;
|
2021-07-19 16:32:40 +02:00
|
|
|
|
2021-07-21 00:57:25 +02:00
|
|
|
// Block tv shows
|
|
|
|
if (e.q === "TV series") return;
|
|
|
|
if (e.q === "TV mini-series") return;
|
|
|
|
if (e.q === "video game") return;
|
|
|
|
if (e.q === "TV movie") return;
|
|
|
|
if (e.q === "TV special") return;
|
|
|
|
|
2021-07-19 23:26:49 +02:00
|
|
|
results.push({
|
|
|
|
title: e.l,
|
|
|
|
slug: e.id,
|
|
|
|
type: 'movie',
|
2021-07-21 00:49:33 +02:00
|
|
|
year: e.y,
|
|
|
|
source: 'gomostream'
|
2021-07-19 23:26:49 +02:00
|
|
|
})
|
|
|
|
});
|
2021-07-19 16:32:40 +02:00
|
|
|
|
2021-07-19 23:26:49 +02:00
|
|
|
if (results.length > 1) {
|
|
|
|
return { options: results };
|
|
|
|
} else {
|
2021-07-21 00:49:33 +02:00
|
|
|
return { options: [ { ...results[0], source: 'gomostream' } ] }
|
2021-07-19 23:26:49 +02:00
|
|
|
}
|
2021-07-19 16:32:40 +02:00
|
|
|
} catch (err) {
|
2021-07-21 00:49:33 +02:00
|
|
|
console.error(err);
|
2021-07-19 16:32:40 +02:00
|
|
|
throw new Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-20 12:20:56 +02:00
|
|
|
async function getStreamUrl(slug, type, season, episode) {
|
2021-07-19 23:26:49 +02:00
|
|
|
if (type !== 'movie') return;
|
|
|
|
|
|
|
|
// Get stream to go with IMDB ID
|
|
|
|
const site1 = await fetch(`${MOVIE_URL}/${slug}`).then((d) => d.text());
|
|
|
|
|
2021-07-21 00:49:33 +02:00
|
|
|
if (site1 === "Movie not available.")
|
|
|
|
return { url: '' };
|
|
|
|
|
2021-07-19 23:26:49 +02:00
|
|
|
const tc = site1.match(/var tc = '(.+)';/)?.[1]
|
|
|
|
const _token = site1.match(/"_token": "(.+)",/)?.[1]
|
|
|
|
|
|
|
|
const fd = new FormData()
|
|
|
|
fd.append('tokenCode', tc)
|
|
|
|
fd.append('_token', _token)
|
|
|
|
|
|
|
|
const src = await fetch(DECODING_URL, {
|
|
|
|
method: "POST",
|
|
|
|
body: fd,
|
|
|
|
headers: {
|
|
|
|
'x-token': tc.slice(5, 13).split("").reverse().join("") + "13574199"
|
|
|
|
}
|
|
|
|
}).then((d) => d.json());
|
|
|
|
|
|
|
|
const embedUrl = src.find(url => url.includes('gomo.to'));
|
|
|
|
const site2 = await fetch(`${CORS_URL}${embedUrl}`).then((d) => d.text());
|
|
|
|
|
|
|
|
const parser = new DOMParser();
|
|
|
|
const site2Dom = parser.parseFromString(site2, "text/html");
|
2021-07-21 00:57:25 +02:00
|
|
|
|
|
|
|
if (site2Dom.body.innerText === "File was deleted")
|
|
|
|
return { url: '' }
|
|
|
|
|
2021-07-19 23:26:49 +02:00
|
|
|
const script = site2Dom.querySelectorAll("script")[8].innerHTML;
|
|
|
|
|
2021-07-20 12:20:56 +02:00
|
|
|
let unpacked = unpack(script).split('');
|
2021-07-19 23:26:49 +02:00
|
|
|
unpacked.splice(0, 43);
|
|
|
|
let index = unpacked.findIndex((e) => e === '"');
|
|
|
|
const url = unpacked.slice(0, index).join('');
|
|
|
|
|
|
|
|
return { url }
|
|
|
|
}
|
|
|
|
|
2021-07-21 00:49:33 +02:00
|
|
|
const gomostream = { findContent, getStreamUrl }
|
|
|
|
export default gomostream;
|