mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-23 02:17:47 +01:00
mhm
This commit is contained in:
parent
35e06ef2e8
commit
49c03bf3c0
1 changed files with 70 additions and 69 deletions
|
@ -67,7 +67,7 @@ class InnerTubePokeVidious {
|
||||||
* @param {string} v - Video ID.
|
* @param {string} v - Video ID.
|
||||||
* @returns {Promise<object>} Promise resolving to the video information.
|
* @returns {Promise<object>} Promise resolving to the video information.
|
||||||
*/
|
*/
|
||||||
async getYouTubeApiVideo(f, v, contentlang, contentregion) {
|
async getYouTubeApiVideo(f, v, contentlang, contentregion) {
|
||||||
|
|
||||||
const { fetch } = await import("undici");
|
const { fetch } = await import("undici");
|
||||||
|
|
||||||
|
@ -75,82 +75,83 @@ async getYouTubeApiVideo(f, v, contentlang, contentregion) {
|
||||||
|
|
||||||
// Check if result is already cached
|
// Check if result is already cached
|
||||||
if (this.cache[v] && Date.now() - this.cache[v].timestamp < 3600000) {
|
if (this.cache[v] && Date.now() - this.cache[v].timestamp < 3600000) {
|
||||||
return this.cache[v].result;
|
return this.cache[v].result;
|
||||||
}
|
}
|
||||||
const headers = {};
|
const headers = {};
|
||||||
|
|
||||||
let desc = "";
|
let desc = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [invComments, videoInfo, videoData] = await Promise.all([
|
const [invComments, videoInfo, videoData] = await Promise.all([
|
||||||
fetch(`${this.config.invapi}/comments/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
fetch(`${this.config.invapi}/comments/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
||||||
fetch(`${this.config.invapi}/videos/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
fetch(`${this.config.invapi}/videos/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
||||||
curly
|
curly
|
||||||
.get(`${this.config.tubeApi}video?v=${v}`, {
|
.get(`${this.config.tubeApi}video?v=${v}`, {
|
||||||
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`),
|
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`),
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const json = toJson(res.data);
|
const json = toJson(res.data);
|
||||||
const video = this.getJson(json);
|
const video = this.getJson(json);
|
||||||
return { json, video };
|
return { json, video };
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const comments = await this.getJson(invComments);
|
|
||||||
let vid = await this.getJson(videoInfo);
|
|
||||||
const { json, video } = videoData;
|
|
||||||
|
|
||||||
var channel_uploads = {};
|
|
||||||
if (f == "true") {
|
|
||||||
channel_uploads = await fetch(
|
|
||||||
`${this.config.invapi}/channels/${vid.authorId}?hl=${contentlang}®ion=${contentregion}`
|
|
||||||
);
|
|
||||||
var p = this.getJson(await channel_uploads.text());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!vid) {
|
const comments = await this.getJson(invComments);
|
||||||
console.log(
|
|
||||||
`Sorry nya, we couldn't find any information about that video qwq`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.checkUnexistingObject(vid)) {
|
const vid = await this.getJson(videoInfo);
|
||||||
const fe = await getdislikes(v);
|
const { json, video } = videoData;
|
||||||
|
|
||||||
try {
|
var channel_uploads = { };
|
||||||
const headers = {};
|
if (f == "true") {
|
||||||
|
channel_uploads = await fetch(
|
||||||
|
`${this.config.invapi}/channels/${vid.authorId}?hl=${contentlang}®ion=${contentregion}`
|
||||||
|
);
|
||||||
|
var p = this.getJson(await channel_uploads.text());
|
||||||
|
}
|
||||||
|
|
||||||
// Store result in cache
|
if (!vid) {
|
||||||
this.cache[v] = {
|
console.log(
|
||||||
result: {
|
`Sorry nya, we couldn't find any information about that video qwq`
|
||||||
json: json?.video,
|
);
|
||||||
video,
|
}
|
||||||
vid,
|
|
||||||
comments,
|
|
||||||
channel_uploads: p,
|
|
||||||
engagement: fe.engagement,
|
|
||||||
wiki: "",
|
|
||||||
desc: "",
|
|
||||||
color: await getColors(
|
|
||||||
`https://vid.puffyan.us/vi/${v}/hqdefault.jpg?sqp=${this.sqp}`
|
|
||||||
).then((colors) => colors[0].hex()),
|
|
||||||
color2: await getColors(
|
|
||||||
`https://vid.puffyan.us/vi/${v}/hqdefault.jpg?sqp=${this.sqp}`
|
|
||||||
).then((colors) => colors[1].hex()),
|
|
||||||
},
|
|
||||||
timestamp: Date.now(),
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.cache[v].result;
|
if (this.checkUnexistingObject(vid)) {
|
||||||
} catch (error) {
|
const fe = await getdislikes(v);
|
||||||
this.initError("Error getting video", error);
|
|
||||||
}
|
try {
|
||||||
}
|
const headers = {};
|
||||||
|
|
||||||
|
// Store result in cache
|
||||||
|
this.cache[v] = {
|
||||||
|
result: {
|
||||||
|
json: json?.video,
|
||||||
|
video,
|
||||||
|
vid,
|
||||||
|
comments,
|
||||||
|
channel_uploads: p,
|
||||||
|
engagement: fe.engagement,
|
||||||
|
wiki: "",
|
||||||
|
desc: "",
|
||||||
|
color: await getColors(
|
||||||
|
`https://vid.puffyan.us/vi/${v}/hqdefault.jpg?sqp=${this.sqp}`
|
||||||
|
).then((colors) => colors[0].hex()),
|
||||||
|
color2: await getColors(
|
||||||
|
`https://vid.puffyan.us/vi/${v}/hqdefault.jpg?sqp=${this.sqp}`
|
||||||
|
).then((colors) => colors[1].hex()),
|
||||||
|
},
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.cache[v].result;
|
||||||
|
} catch (error) {
|
||||||
|
this.initError("Error getting video", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue