add proper multiple source support

This commit is contained in:
James Hawkins 2021-07-20 23:49:33 +01:00
parent cfe821d9a8
commit d3d0794307
10 changed files with 79 additions and 38 deletions

View File

@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^5.11.4", "@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0", "@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10", "@testing-library/user-event": "^12.1.10",
"crypto-js": "^4.0.0",
"fuse.js": "^6.4.6", "fuse.js": "^6.4.6",
"hls.js": "^1.0.7", "hls.js": "^1.0.7",
"json5": "^2.2.0", "json5": "^2.2.0",

View File

@ -3,7 +3,7 @@ import { TypeSelector } from './TypeSelector';
import { NumberSelector } from './NumberSelector'; import { NumberSelector } from './NumberSelector';
import './EpisodeSelector.css' import './EpisodeSelector.css'
export function EpisodeSelector({ setSeason, setEpisode, seasons, season, episodes, currentSeason, currentEpisode, slug }) { export function EpisodeSelector({ setSeason, setEpisode, seasons, season, episodes, currentSeason, currentEpisode, slug, source }) {
const choices = episodes.map(v => { const choices = episodes.map(v => {
@ -12,7 +12,7 @@ export function EpisodeSelector({ setSeason, setEpisode, seasons, season, episod
let currentlyAt = 0; let currentlyAt = 0;
let totalDuration = 0; let totalDuration = 0;
const progress = progressData?.lookmovie?.show?.slug?.[`${season}-${v}`] const progress = progressData?.[source]?.show?.slug?.[`${season}-${v}`]
if(progress) { if(progress) {
currentlyAt = progress.currentlyAt currentlyAt = progress.currentlyAt
totalDuration = progress.totalDuration totalDuration = progress.totalDuration

View File

@ -11,7 +11,7 @@ export function MovieRow(props) {
let progress; let progress;
let percentage = null; let percentage = null;
if(props.type === "movie") { if(props.type === "movie") {
progress = progressData?.lookmovie?.movie?.[props.slug]?.full progress = progressData?.[props.source]?.movie?.[props.slug]?.full
if(progress) { if(progress) {
percentage = Math.floor((progress.currentlyAt / progress.totalDuration) * 100) percentage = Math.floor((progress.currentlyAt / progress.totalDuration) * 100)
} }
@ -24,6 +24,7 @@ export function MovieRow(props) {
<span className="year">({props.year})</span> <span className="year">({props.year})</span>
</div> </div>
<div className="watch"> <div className="watch">
<span className="attribute">{props.source}</span>
<p>Watch {props.type}</p> <p>Watch {props.type}</p>
<Arrow/> <Arrow/>
</div> </div>

View File

@ -1,4 +1,4 @@
import { unpack } from './unpacker'; import { unpack } from './util/unpacker';
const CORS_URL = 'https://hidden-inlet-27205.herokuapp.com/'; const CORS_URL = 'https://hidden-inlet-27205.herokuapp.com/';
const BASE_URL = `${CORS_URL}https://gomo.to`; const BASE_URL = `${CORS_URL}https://gomo.to`;
@ -20,17 +20,18 @@ async function findContent(searchTerm, type) {
title: e.l, title: e.l,
slug: e.id, slug: e.id,
type: 'movie', type: 'movie',
year: e.y year: e.y,
source: 'gomostream'
}) })
}); });
if (results.length > 1) { if (results.length > 1) {
return { options: results }; return { options: results };
} else { } else {
return { options: [results[0]] } return { options: [ { ...results[0], source: 'gomostream' } ] }
} }
} catch (err) { } catch (err) {
console.log(err); console.error(err);
throw new Error(err) throw new Error(err)
} }
} }
@ -41,6 +42,9 @@ async function getStreamUrl(slug, type, season, episode) {
// Get stream to go with IMDB ID // Get stream to go with IMDB ID
const site1 = await fetch(`${MOVIE_URL}/${slug}`).then((d) => d.text()); const site1 = await fetch(`${MOVIE_URL}/${slug}`).then((d) => d.text());
if (site1 === "Movie not available.")
return { url: '' };
const tc = site1.match(/var tc = '(.+)';/)?.[1] const tc = site1.match(/var tc = '(.+)';/)?.[1]
const _token = site1.match(/"_token": "(.+)",/)?.[1] const _token = site1.match(/"_token": "(.+)",/)?.[1]
@ -71,4 +75,5 @@ async function getStreamUrl(slug, type, season, episode) {
return { url } return { url }
} }
export { findContent, getStreamUrl } const gomostream = { findContent, getStreamUrl }
export default gomostream;

View File

@ -1,16 +1,44 @@
import lookMovie from './lookMovie'; import lookMovie from './lookMovie';
// import gomostream from './gomostream'; import gomostream from './gomostream';
async function findContent(searchTerm, type) { async function findContent(searchTerm, type) {
return await lookMovie.findContent(searchTerm, type); const results = { options: []};
const content = await Promise.all([
lookMovie.findContent(searchTerm, type),
gomostream.findContent(searchTerm, type)
]);
content.forEach((o) => {
if (!o || !o.options) return;
o.options.forEach((i) => {
if (!i) return;
results.options.push(i)
})
});
return results;
} }
async function getStreamUrl(slug, type, season, episode) { async function getStreamUrl(slug, type, source, season, episode) {
switch (source) {
case 'lookmovie':
return await lookMovie.getStreamUrl(slug, type, season, episode); return await lookMovie.getStreamUrl(slug, type, season, episode);
case 'gomostream':
return await gomostream.getStreamUrl(slug, type, season, episode);
default:
return;
}
} }
async function getEpisodes(slug) { async function getEpisodes(slug, source) {
switch (source) {
case 'lookmovie':
return await lookMovie.getEpisodes(slug); return await lookMovie.getEpisodes(slug);
case 'gomostream':
default:
return;
}
} }
export { findContent, getStreamUrl, getEpisodes } export { findContent, getStreamUrl, getEpisodes }

View File

@ -17,7 +17,6 @@ async function getVideoUrl(config) {
url = getCorsUrl(`https://lookmovie.io/manifests/shows/json/${accessToken}/${now}/${config.id}/master.m3u8`); url = getCorsUrl(`https://lookmovie.io/manifests/shows/json/${accessToken}/${now}/${config.id}/master.m3u8`);
} }
if (url) {
const videoOpts = await fetch(url).then((d) => d.json()); const videoOpts = await fetch(url).then((d) => d.json());
// Find video URL and return it (with a check for a full url if needed) // Find video URL and return it (with a check for a full url if needed)
@ -30,10 +29,7 @@ async function getVideoUrl(config) {
} }
} }
return videoUrl.startsWith("/") ? getCorsUrl(`https://lookmovie.io/${videoUrl}`) : getCorsUrl(videoUrl); return videoUrl.startsWith("/") ? `https://lookmovie.io${videoUrl}` : videoUrl;
}
return "Invalid type.";
} }
async function getAccessToken(config) { async function getAccessToken(config) {
@ -151,7 +147,8 @@ async function findContent(searchTerm, type) {
title: r.title, title: r.title,
slug: r.slug, slug: r.slug,
type: r.type, type: r.type,
year: r.year year: r.year,
source: 'lookmovie'
})); }));
return res; return res;
@ -159,7 +156,7 @@ async function findContent(searchTerm, type) {
const { title, slug, type, year } = matchedResults[0]; const { title, slug, type, year } = matchedResults[0];
return { return {
options: [{ title, slug, type, year }] options: [{ title, slug, type, year, source: 'lookmovie' }]
} }
} }
} }

View File

@ -43,7 +43,7 @@ export function MovieView(props) {
} }
setLoading(true); setLoading(true);
getStreamUrl(streamData.slug, streamData.type, episode.season, episode.episode) getStreamUrl(streamData.slug, streamData.type, streamData.source, episode.season, episode.episode)
.then(({url}) => { .then(({url}) => {
if (cancel) return; if (cancel) return;
setStreamUrl(url) setStreamUrl(url)
@ -106,6 +106,7 @@ export function MovieView(props) {
slug={streamData.slug} slug={streamData.slug}
currentSeason={season} currentSeason={season}
currentEpisode={episode} currentEpisode={episode}
source={streamData.source}
/> />
: ''} : ''}
</Card> </Card>

View File

@ -30,7 +30,7 @@ export function SearchView() {
setFailed(true) setFailed(true)
} }
async function getStream(title, slug, type) { async function getStream(title, slug, type, source) {
setStreamUrl(""); setStreamUrl("");
try { try {
@ -40,14 +40,15 @@ export function SearchView() {
let seasons = []; let seasons = [];
let episodes = []; let episodes = [];
if (type === "show") { if (type === "show") {
const data = await getEpisodes(slug); const data = await getEpisodes(slug, source);
seasons = data.seasons; seasons = data.seasons;
episodes = data.episodes; episodes = data.episodes;
} }
let realUrl = ''; let realUrl = '';
if (type === "movie") { if (type === "movie") {
const { url } = await getStreamUrl(slug, type); // getStreamUrl(slug, type, source, season, episode)
const { url } = await getStreamUrl(slug, type, source);
if (url === '') { if (url === '') {
return fail(`Not found: ${title}`) return fail(`Not found: ${title}`)
@ -62,7 +63,8 @@ export function SearchView() {
type, type,
seasons, seasons,
episodes, episodes,
slug slug,
source
}) })
setText(`Streaming...`) setText(`Streaming...`)
navigate("movie") navigate("movie")
@ -79,7 +81,7 @@ export function SearchView() {
setShowingOptions(false) setShowingOptions(false)
try { try {
const { options } = await findContent(query, contentType) const { options } = await findContent(query, contentType);
if (options.length === 0) { if (options.length === 0) {
return fail(`Could not find that ${contentType}`) return fail(`Could not find that ${contentType}`)
@ -91,9 +93,10 @@ export function SearchView() {
return; return;
} }
const { title, slug, type } = options[0]; const { title, slug, type, source } = options[0];
getStream(title, slug, type); getStream(title, slug, type, source);
} catch (err) { } catch (err) {
console.error(err);
fail(`Failed to watch ${contentType}`) fail(`Failed to watch ${contentType}`)
} }
} }
@ -134,9 +137,9 @@ export function SearchView() {
Whoops, there are a few {type}s like that Whoops, there are a few {type}s like that
</Title> </Title>
{options?.map((v, i) => ( {options?.map((v, i) => (
<MovieRow key={i} title={v.title} slug={v.slug} type={v.type} year={v.year} season={v.season} episode={v.episode} onClick={() => { <MovieRow key={i} title={v.title} slug={v.slug} type={v.type} year={v.year} source={v.source} onClick={() => {
setShowingOptions(false) setShowingOptions(false)
getStream(v.title, v.slug, v.type, v.season, v.episode) getStream(v.title, v.slug, v.type, v.source)
}}/> }}/>
))} ))}
</Card> </Card>

View File

@ -3654,6 +3654,11 @@ crypto-browserify@^3.11.0:
randombytes "^2.0.0" randombytes "^2.0.0"
randomfill "^1.0.3" randomfill "^1.0.3"
crypto-js@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc"
integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==
crypto-random-string@^1.0.0: crypto-random-string@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"