mirror of
https://codeberg.org/ashley/poke
synced 2025-05-30 02:59:43 +00:00
Update src/libpoketube/libpoketube-core.js
This commit is contained in:
parent
c9e8b8f85d
commit
6e1aecaeb4
@ -25,6 +25,17 @@ class InnerTubePokeVidious {
|
|||||||
this.youtubeClient = null;
|
this.youtubeClient = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-added helper so your callers can do INNERTUBE.isvalidvideo(v)
|
||||||
|
isvalidvideo(id) {
|
||||||
|
// exactly 11-char YouTube IDs, not folder names
|
||||||
|
return (
|
||||||
|
id !== "assets" &&
|
||||||
|
id !== "cdn-cgi" &&
|
||||||
|
id !== "404" &&
|
||||||
|
/^([A-Za-z0-9_-]{11})$/.test(id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async _initYouTube() {
|
async _initYouTube() {
|
||||||
if (!this.youtubeClient) {
|
if (!this.youtubeClient) {
|
||||||
this.youtubeClient = await Innertube.create({
|
this.youtubeClient = await Innertube.create({
|
||||||
@ -35,7 +46,6 @@ class InnerTubePokeVidious {
|
|||||||
return this.youtubeClient;
|
return this.youtubeClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to map thumbnails to {url,width,height}
|
|
||||||
_mapThumbnails(thumbnails) {
|
_mapThumbnails(thumbnails) {
|
||||||
return thumbnails.map((t) => ({
|
return thumbnails.map((t) => ({
|
||||||
url: t.url,
|
url: t.url,
|
||||||
@ -44,7 +54,6 @@ class InnerTubePokeVidious {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The one unified method
|
|
||||||
async getYouTubeApiVideo(f, videoId, contentlang, contentregion) {
|
async getYouTubeApiVideo(f, videoId, contentlang, contentregion) {
|
||||||
if (!videoId) return { error: "Gib ID" };
|
if (!videoId) return { error: "Gib ID" };
|
||||||
|
|
||||||
@ -58,19 +67,20 @@ class InnerTubePokeVidious {
|
|||||||
const youtube = await this._initYouTube();
|
const youtube = await this._initYouTube();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// fetch:
|
const [commentsData, info, legacy] = await Promise.all([
|
||||||
const [ commentsData, info, legacy ] = await Promise.all([
|
youtube.getComments(videoId),
|
||||||
youtube.getComments(videoId), // raw comments from yt
|
youtube.getInfo(videoId),
|
||||||
youtube.getInfo(videoId), // raw info from yt
|
|
||||||
curly.get(`${this.config.tubeApi}video?v=${videoId}`, {
|
curly.get(`${this.config.tubeApi}video?v=${videoId}`, {
|
||||||
httpHeader: Object.entries(headers).map(([k,v]) => `${k}: ${v}`)
|
httpHeader: Object.entries(headers).map(
|
||||||
}).then(res => {
|
([k, v]) => `${k}: ${v}`
|
||||||
|
),
|
||||||
|
}).then((res) => {
|
||||||
const json = toJson(res.data);
|
const json = toJson(res.data);
|
||||||
return { json: JSON.parse(json), video: JSON.parse(json).video };
|
const parsed = JSON.parse(json);
|
||||||
|
return { json: parsed, video: parsed.video };
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Invidious-style JSON:
|
|
||||||
const vid = info;
|
const vid = info;
|
||||||
const resp = {
|
const resp = {
|
||||||
type: vid.type,
|
type: vid.type,
|
||||||
@ -79,11 +89,11 @@ class InnerTubePokeVidious {
|
|||||||
error: vid.info?.reason || null,
|
error: vid.info?.reason || null,
|
||||||
|
|
||||||
videoThumbnails: this._mapThumbnails(vid.thumbnails),
|
videoThumbnails: this._mapThumbnails(vid.thumbnails),
|
||||||
storyboards: vid.storyboards?.map(sb => ({
|
storyboards: vid.storyboards?.map((sb) => ({
|
||||||
url: sb.url,
|
url: sb.url,
|
||||||
width: sb.width,
|
width: sb.width,
|
||||||
height: sb.height,
|
height: sb.height,
|
||||||
mime: sb.mimeType
|
mime: sb.mimeType,
|
||||||
})),
|
})),
|
||||||
|
|
||||||
description: vid.description,
|
description: vid.description,
|
||||||
@ -122,21 +132,23 @@ class InnerTubePokeVidious {
|
|||||||
? Math.floor(new Date(vid.premiereTimestamp).getTime() / 1000)
|
? Math.floor(new Date(vid.premiereTimestamp).getTime() / 1000)
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
// keep legacy fields too:
|
// legacy fields
|
||||||
json: legacy.json,
|
json: legacy.json,
|
||||||
video: legacy.video,
|
video: legacy.video,
|
||||||
comments: commentsData,
|
comments: commentsData,
|
||||||
engagement: (await getdislikes(videoId)).engagement,
|
engagement: (await getdislikes(videoId)).engagement,
|
||||||
wiki: "",
|
wiki: "",
|
||||||
channel_uploads: f === "true"
|
channel_uploads:
|
||||||
? (await fetch(`${this.config.invapi}/channels/${vid.channelId}?hl=${contentlang}®ion=${contentregion}`, { headers }))
|
f === "true"
|
||||||
.then(r => r.json())
|
? await fetch(
|
||||||
: {}
|
`${this.config.invapi}/channels/${vid.channelId}?hl=${contentlang}®ion=${contentregion}`,
|
||||||
|
{ headers }
|
||||||
|
).then((r) => r.json())
|
||||||
|
: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cache[videoId] = { result: resp, timestamp: Date.now() };
|
this.cache[videoId] = { result: resp, timestamp: Date.now() };
|
||||||
return resp;
|
return resp;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[LIBPT CORE ERROR] Error getting video", err);
|
console.error("[LIBPT CORE ERROR] Error getting video", err);
|
||||||
return { error: err.message };
|
return { error: err.message };
|
||||||
@ -147,9 +159,10 @@ class InnerTubePokeVidious {
|
|||||||
module.exports = new InnerTubePokeVidious({
|
module.exports = new InnerTubePokeVidious({
|
||||||
tubeApi: "https://inner-api.poketube.fun/api/",
|
tubeApi: "https://inner-api.poketube.fun/api/",
|
||||||
invapi: "https://invid-api.poketube.fun/bHj665PpYhUdPWuKPfZuQGoX/api/v1",
|
invapi: "https://invid-api.poketube.fun/bHj665PpYhUdPWuKPfZuQGoX/api/v1",
|
||||||
invapi_alt: config.proxylocation === "EU"
|
invapi_alt:
|
||||||
? "https://invid-api.poketube.fun/api/v1"
|
config.proxylocation === "EU"
|
||||||
: "https://iv.ggtyler.dev/api/v1",
|
? "https://invid-api.poketube.fun/api/v1"
|
||||||
|
: "https://iv.ggtyler.dev/api/v1",
|
||||||
dislikes: "https://returnyoutubedislikeapi.com/votes?videoId=",
|
dislikes: "https://returnyoutubedislikeapi.com/votes?videoId=",
|
||||||
t_url: "https://t.poketube.fun/",
|
t_url: "https://t.poketube.fun/",
|
||||||
useragent: config.useragent,
|
useragent: config.useragent,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user