mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-24 04:31:51 +01:00
Update lookmovie.js
This commit is contained in:
parent
4878238143
commit
fbd0f57a73
@ -50,9 +50,19 @@ async function findContent(searchTerm, type) {
|
||||
}
|
||||
}
|
||||
async function getVideoUrl(config) {
|
||||
const accessToken = await getAccessToken(config);
|
||||
const accessInfo = await getAccessToken(config);
|
||||
const accessToken = accessInfo.token;
|
||||
const subtitles = accessInfo.subtitles;
|
||||
const now = Math.floor(Date.now() / 1e3);
|
||||
|
||||
let subs;
|
||||
|
||||
if (config.type === "show") {
|
||||
subs = await getEpisodeSubs(config)
|
||||
} else if (config.type === "movie") {
|
||||
subs = subtitles
|
||||
}
|
||||
|
||||
let url = '';
|
||||
|
||||
if (config.type === 'movie') {
|
||||
@ -73,7 +83,11 @@ async function getVideoUrl(config) {
|
||||
}
|
||||
}
|
||||
|
||||
return videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl;
|
||||
return {videoUrl: videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl, subs};
|
||||
}
|
||||
|
||||
async function getEpisodeSubs (config) {
|
||||
return await fetch(`${BASE_URL}/api/v1/shows/episode-subtitles/?id_episode=${config.id}`).then(res => res.json());
|
||||
}
|
||||
|
||||
async function getAccessToken(config) {
|
||||
@ -86,9 +100,11 @@ async function getAccessToken(config) {
|
||||
}
|
||||
|
||||
const data = await fetch(url).then((d) => d.json());
|
||||
|
||||
|
||||
const token = data?.data?.accessToken;
|
||||
if (token) return token;
|
||||
let subtitles = data?.data?.subtitles;
|
||||
|
||||
if (token) return {token, subtitles};
|
||||
|
||||
return "Invalid type provided in config";
|
||||
}
|
||||
@ -121,6 +137,7 @@ async function getEpisodes(slug) {
|
||||
}
|
||||
|
||||
async function getStreamUrl(slug, type, season, episode) {
|
||||
|
||||
const url = `${BASE_URL}/${type}s/view/${slug}`;
|
||||
const pageReq = await fetch(url).then((d) => d.text());
|
||||
|
||||
@ -153,11 +170,11 @@ async function getStreamUrl(slug, type, season, episode) {
|
||||
slug: slug,
|
||||
id: id,
|
||||
type: type,
|
||||
});
|
||||
});
|
||||
|
||||
return { url: videoUrl }
|
||||
return { url: videoUrl.videoUrl, subtitles: videoUrl.subs };
|
||||
}
|
||||
|
||||
|
||||
const lookMovie = { findContent, getStreamUrl, getEpisodes };
|
||||
export default lookMovie;
|
||||
export default lookMovie;
|
||||
|
Loading…
Reference in New Issue
Block a user