mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 02:25:08 +01:00
Update lookmovie.js
This commit is contained in:
parent
9bf56c0b82
commit
be3f631ca9
@ -50,17 +50,15 @@ async function findContent(searchTerm, type) {
|
||||
}
|
||||
}
|
||||
async function getVideoUrl(config) {
|
||||
const accessInfo = await getAccessToken(config);
|
||||
const accessToken = accessInfo.token;
|
||||
const subtitles = accessInfo.subtitles;
|
||||
const { subtitles, token: accessToken } = await getAccessInfo(config);
|
||||
const now = Math.floor(Date.now() / 1e3);
|
||||
|
||||
let subs;
|
||||
|
||||
if (config.type === "show") {
|
||||
subs = await getEpisodeSubs(config)
|
||||
subs = await getEpisodeSubs(config);
|
||||
} else if (config.type === "movie") {
|
||||
subs = subtitles
|
||||
subs = subtitles;
|
||||
}
|
||||
|
||||
let url = '';
|
||||
@ -83,14 +81,17 @@ async function getVideoUrl(config) {
|
||||
}
|
||||
}
|
||||
|
||||
return {videoUrl: videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl, subs};
|
||||
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) {
|
||||
async function getAccessInfo(config) {
|
||||
let url = '';
|
||||
|
||||
if (config.type === 'movie') {
|
||||
@ -100,11 +101,11 @@ async function getAccessToken(config) {
|
||||
}
|
||||
|
||||
const data = await fetch(url).then((d) => d.json());
|
||||
|
||||
const token = data?.data?.accessToken;
|
||||
let subtitles = data?.data?.subtitles;
|
||||
|
||||
if (token) return {token, subtitles};
|
||||
const token = data?.data?.accessToken;
|
||||
const subtitles = data?.data?.subtitles;
|
||||
|
||||
if (token) return { token, subtitles };
|
||||
|
||||
return "Invalid type provided in config";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user