This commit is contained in:
James Hawkins 2021-07-20 11:20:56 +01:00
parent 0528531bb5
commit 8c78cec211
7 changed files with 101 additions and 82 deletions

View File

@ -1,5 +1,4 @@
import React from 'react';
// import { Arrow } from './Arrow';
import './TypeSelector.css'
// setType: (txt: string) => void

View File

@ -1,11 +1,11 @@
import { unpacker } from './unpacker';
import { unpack } from './unpacker';
const CORS_URL = 'https://hidden-inlet-27205.herokuapp.com/';
const BASE_URL = `${CORS_URL}https://gomo.to`;
const MOVIE_URL = `${BASE_URL}/movie`
const DECODING_URL = `${BASE_URL}/decoding_v3.php`
async function findContentGomo(searchTerm, type) {
async function findContent(searchTerm, type) {
try {
if (type !== 'movie') return;
@ -29,17 +29,13 @@ async function findContentGomo(searchTerm, type) {
} else {
return { options: [results[0]] }
}
// const movieId = imdbRes.d[0]?.id
// if (!movieId) return;
} catch (err) {
console.log(err);
throw new Error(err)
}
}
async function getStreamUrlGomo(slug, type, season, episode) {
async function getStreamUrl(slug, type, season, episode) {
if (type !== 'movie') return;
// Get stream to go with IMDB ID
@ -67,7 +63,7 @@ async function getStreamUrlGomo(slug, type, season, episode) {
const site2Dom = parser.parseFromString(site2, "text/html");
const script = site2Dom.querySelectorAll("script")[8].innerHTML;
let unpacked = unpacker.unpack(script).split('');
let unpacked = unpack(script).split('');
unpacked.splice(0, 43);
let index = unpacked.findIndex((e) => e === '"');
const url = unpacked.slice(0, index).join('');
@ -75,4 +71,4 @@ async function getStreamUrlGomo(slug, type, season, episode) {
return { url }
}
export { findContentGomo, getStreamUrlGomo }
export { findContent, getStreamUrl }

16
src/lib/index.js Normal file
View File

@ -0,0 +1,16 @@
import lookMovie from './lookMovie';
// import gomostream from './gomostream';
async function findContent(searchTerm, type) {
return await lookMovie.findContent(searchTerm, type);
}
async function getStreamUrl(slug, type, season, episode) {
return await lookMovie.getStreamUrl(slug, type, season, episode);
}
async function getEpisodes(slug) {
return await lookMovie.getEpisodes(slug);
}
export { findContent, getStreamUrl, getEpisodes }

View File

@ -66,9 +66,9 @@ async function getEpisodes(slug) {
"}"
);
let seasons, episodes = [];
data.forEach((e) => {
let seasons = [];
let episodes = [];
data.seasons.forEach((e) => {
if (!seasons.includes(e.season))
seasons.push(e.season);
@ -119,7 +119,6 @@ async function getStreamUrl(slug, type, season, episode) {
}
async function findContent(searchTerm, type) {
// const searchUrl = getCorsUrl(`https://lookmovie.io/api/v1/${type}s/search/?q=${encodeURIComponent(searchTerm)}`);
const searchUrl = getCorsUrl(`https://lookmovie.io/${type}s/search/?q=${encodeURIComponent(searchTerm)}`);
const searchRes = await fetch(searchUrl).then((d) => d.text());
@ -165,4 +164,5 @@ async function findContent(searchTerm, type) {
}
}
export { findContent, getStreamUrl, getEpisodes };
const lookMovie = { findContent, getStreamUrl, getEpisodes };
export default lookMovie;

View File

@ -1,46 +1,53 @@
/* port of https://github.com/beautify-web/js-beautify/blob/master/python/jsbeautifier/unpackers/packer.py (MIT) */
const unpacker = {
unpack: function (str) {
var params = unpacker.filterargs(str);
var payload = params[0], symtab = params[1], radix = params[2], count = params[3];
if (count !== symtab.length) {
throw new Error("Malformed p.a.c.k.e.r. symtab. (" + count + " != " + symtab.length + ")");
}
var unbase = unpacker.unbaser(radix);
var lookup = (word) => symtab[unbase(word)] || word;
var source = payload.replace(/\b\w+\b/g, lookup);
return source;
},
filterargs: function(str) {
/* [\s\S] insteadof . because javascript has no dotall modifier */
const alphabet = {
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
95: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
};
function _filterargs(str) {
var juicers = [
/}\('([\s\S]*)', *(\d+), *(\d+), *'([\s\S]*)'\.split\('\|'\), *(\d+), *([\s\S]*)\)\)/,
/}\('([\s\S]*)', *(\d+), *(\d+), *'([\s\S]*)'\.split\('\|'\)/
];
for (var c = 0; c < juicers.length; ++c) {
var m, juicer = juicers[c];
// eslint-disable-next-line no-cond-assign
if (m = juicer.exec(str)) {
return [m[1], m[4].split('|'), parseInt(m[2]), parseInt(m[3])];
}
}
throw new Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)");
},
alphabet: {
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
95: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
},
unbaser: function(base)
{
if (2 <= base <= 36) return (str) => parseInt(str, base);
var dictionary = {};
var alphabet = unpacker.alphabet[base];
if (!alphabet) throw new Error("Unsupported encoding");
for (var c = 0; c < alphabet.length; ++alphabet) {
dictionary[alphabet[c]] = c;
}
return (str) => str.split("").reverse().reduce((cipher, ind) => Math.pow(base, ind) * dictionary[cipher]);
}
};
export { unpacker };
throw new Error("Could not make sense of p.a.c.k.e.r data (unexpected code structure)");
}
function _unbaser(base) {
if (2 <= base <= 36) return (str) => parseInt(str, base);
const dictionary = {};
var alpha = alphabet[base];
if (!alpha) throw new Error("Unsupported encoding");
for (let c = 0; c < alpha.length; ++alpha) {
dictionary[alpha[c]] = c;
}
return (str) => str.split("").reverse().reduce((cipher, ind) => Math.pow(base, ind) * dictionary[cipher]);
}
function unpack(str) {
var params = _filterargs(str);
var payload = params[0], symtab = params[1], radix = params[2], count = params[3];
if (count !== symtab.length) {
throw new Error("Malformed p.a.c.k.e.r. symtab. (" + count + " != " + symtab.length + ")");
}
var unbase = _unbaser(radix);
var lookup = (word) => symtab[unbase(word)] || word;
var source = payload.replace(/\b\w+\b/g, lookup);
return source;
}
export { unpack };

View File

@ -4,8 +4,9 @@ import { Card } from '../components/Card'
import { useMovie } from '../hooks/useMovie'
import { VideoElement } from '../components/VideoElement'
import { EpisodeSelector } from '../components/EpisodeSelector'
import { getStreamUrl } from '../lib/index'
import './Movie.css'
import { getStreamUrl } from '../lib/lookMovie'
export function MovieView(props) {
const { streamUrl, streamData, setStreamUrl } = useMovie();

View File

@ -1,17 +1,16 @@
import React from 'react';
import { InputBox } from '../components/InputBox'
import { Title } from '../components/Title'
import { Card } from '../components/Card'
import { ErrorBanner } from '../components/ErrorBanner'
import { MovieRow } from '../components/MovieRow'
import { Arrow } from '../components/Arrow'
import { Progress } from '../components/Progress'
import { findContent, getStreamUrl, getEpisodes } from '../lib/lookMovie'
// import { findContentGomo, getStreamUrlGomo } from '../lib/gomostream';
import { InputBox } from '../components/InputBox';
import { Title } from '../components/Title';
import { Card } from '../components/Card';
import { ErrorBanner } from '../components/ErrorBanner';
import { MovieRow } from '../components/MovieRow';
import { Arrow } from '../components/Arrow';
import { Progress } from '../components/Progress';
import { findContent, getStreamUrl, getEpisodes } from '../lib/index';
import { useMovie } from '../hooks/useMovie';
import { TypeSelector } from '../components/TypeSelector'
import { TypeSelector } from '../components/TypeSelector';
import './Search.css'
import './Search.css';
export function SearchView() {
const { navigate, setStreamUrl, setStreamData } = useMovie();
@ -68,6 +67,7 @@ export function SearchView() {
setText(`Streaming...`)
navigate("movie")
} catch (err) {
console.error(err);
fail("Failed to get stream")
}
}