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/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"crypto-js": "^4.0.0",
"fuse.js": "^6.4.6",
"hls.js": "^1.0.7",
"json5": "^2.2.0",

View File

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

View File

@ -11,7 +11,7 @@ export function MovieRow(props) {
let progress;
let percentage = null;
if(props.type === "movie") {
progress = progressData?.lookmovie?.movie?.[props.slug]?.full
progress = progressData?.[props.source]?.movie?.[props.slug]?.full
if(progress) {
percentage = Math.floor((progress.currentlyAt / progress.totalDuration) * 100)
}
@ -24,6 +24,7 @@ export function MovieRow(props) {
<span className="year">({props.year})</span>
</div>
<div className="watch">
<span className="attribute">{props.source}</span>
<p>Watch {props.type}</p>
<Arrow/>
</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 BASE_URL = `${CORS_URL}https://gomo.to`;
@ -20,17 +20,18 @@ async function findContent(searchTerm, type) {
title: e.l,
slug: e.id,
type: 'movie',
year: e.y
year: e.y,
source: 'gomostream'
})
});
if (results.length > 1) {
return { options: results };
} else {
return { options: [results[0]] }
return { options: [ { ...results[0], source: 'gomostream' } ] }
}
} catch (err) {
console.log(err);
console.error(err);
throw new Error(err)
}
}
@ -41,6 +42,9 @@ async function getStreamUrl(slug, type, season, episode) {
// Get stream to go with IMDB ID
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 _token = site1.match(/"_token": "(.+)",/)?.[1]
@ -71,4 +75,5 @@ async function getStreamUrl(slug, type, season, episode) {
return { url }
}
export { findContent, getStreamUrl }
const gomostream = { findContent, getStreamUrl }
export default gomostream;

View File

@ -1,16 +1,44 @@
import lookMovie from './lookMovie';
// import gomostream from './gomostream';
import gomostream from './gomostream';
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) {
return await lookMovie.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);
case 'gomostream':
return await gomostream.getStreamUrl(slug, type, season, episode);
default:
return;
}
}
async function getEpisodes(slug) {
return await lookMovie.getEpisodes(slug);
async function getEpisodes(slug, source) {
switch (source) {
case 'lookmovie':
return await lookMovie.getEpisodes(slug);
case 'gomostream':
default:
return;
}
}
export { findContent, getStreamUrl, getEpisodes }

View File

@ -17,23 +17,19 @@ async function getVideoUrl(config) {
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)
const opts = ["1080p", "1080", "720p", "720", "480p", "480", "auto"]
// 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]
}
let videoUrl = "";
for (let res of opts) {
if (videoOpts[res] && !videoOpts[res].includes('dummy') && !videoOpts[res].includes('earth-1984') && !videoUrl) {
videoUrl = videoOpts[res]
}
return videoUrl.startsWith("/") ? getCorsUrl(`https://lookmovie.io/${videoUrl}`) : getCorsUrl(videoUrl);
}
return "Invalid type.";
return videoUrl.startsWith("/") ? `https://lookmovie.io${videoUrl}` : videoUrl;
}
async function getAccessToken(config) {
@ -151,7 +147,8 @@ async function findContent(searchTerm, type) {
title: r.title,
slug: r.slug,
type: r.type,
year: r.year
year: r.year,
source: 'lookmovie'
}));
return res;
@ -159,7 +156,7 @@ async function findContent(searchTerm, type) {
const { title, slug, type, year } = matchedResults[0];
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);
getStreamUrl(streamData.slug, streamData.type, episode.season, episode.episode)
getStreamUrl(streamData.slug, streamData.type, streamData.source, episode.season, episode.episode)
.then(({url}) => {
if (cancel) return;
setStreamUrl(url)
@ -106,6 +106,7 @@ export function MovieView(props) {
slug={streamData.slug}
currentSeason={season}
currentEpisode={episode}
source={streamData.source}
/>
: ''}
</Card>

View File

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

View File

@ -3654,6 +3654,11 @@ crypto-browserify@^3.11.0:
randombytes "^2.0.0"
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:
version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"