Update src/libpoketube/libpoketube-core.js

This commit is contained in:
ashley 2025-04-29 19:50:23 +00:00
parent 6e1aecaeb4
commit cc3922ad0e

View File

@ -19,15 +19,16 @@ class InnerTubePokeVidious {
this.cache = {}; this.cache = {};
this.language = "hl=en-US"; this.language = "hl=en-US";
this.region = "region=US"; this.region = "region=US";
this.sqp = "-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLBy_x4UUHLNDZtJtH0PXeQGoRFTgw"; this.sqp =
this.useragent = config.useragent || "-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLBy_x4UUHLNDZtJtH0PXeQGoRFTgw";
this.useragent =
config.useragent ||
"PokeTube/2.0.0 (GNU/Linux; Android 14; Trisquel 11; poketube-vidious; like FreeTube)"; "PokeTube/2.0.0 (GNU/Linux; Android 14; Trisquel 11; poketube-vidious; like FreeTube)";
this.youtubeClient = null; this.youtubeClient = null;
} }
// Re-added helper so your callers can do INNERTUBE.isvalidvideo(v) // Re-added helper so you can call INNERTUBE.isvalidvideo(v)
isvalidvideo(id) { isvalidvideo(id) {
// exactly 11-char YouTube IDs, not folder names
return ( return (
id !== "assets" && id !== "assets" &&
id !== "cdn-cgi" && id !== "cdn-cgi" &&
@ -39,15 +40,17 @@ class InnerTubePokeVidious {
async _initYouTube() { async _initYouTube() {
if (!this.youtubeClient) { if (!this.youtubeClient) {
this.youtubeClient = await Innertube.create({ this.youtubeClient = await Innertube.create({
lang: this.language.split("=")[1], // "en-US" lang: this.language.split("=")[1], // "en-US"
location: this.region.split("=")[1], // "US" location: this.region.split("=")[1], // "US"
}); });
} }
return this.youtubeClient; return this.youtubeClient;
} }
// Safe-map thumbnails (empty array if undefined)
_mapThumbnails(thumbnails) { _mapThumbnails(thumbnails) {
return thumbnails.map((t) => ({ const list = Array.isArray(thumbnails) ? thumbnails : [];
return list.map((t) => ({
url: t.url, url: t.url,
width: t.width, width: t.width,
height: t.height, height: t.height,
@ -58,8 +61,10 @@ class InnerTubePokeVidious {
if (!videoId) return { error: "Gib ID" }; if (!videoId) return { error: "Gib ID" };
// cache for 1h // cache for 1h
if (this.cache[videoId] && if (
Date.now() - this.cache[videoId].timestamp < 3_600_000) { this.cache[videoId] &&
Date.now() - this.cache[videoId].timestamp < 3_600_000
) {
return this.cache[videoId].result; return this.cache[videoId].result;
} }
@ -70,15 +75,16 @@ class InnerTubePokeVidious {
const [commentsData, info, legacy] = await Promise.all([ const [commentsData, info, legacy] = await Promise.all([
youtube.getComments(videoId), youtube.getComments(videoId),
youtube.getInfo(videoId), youtube.getInfo(videoId),
curly.get(`${this.config.tubeApi}video?v=${videoId}`, { curly
httpHeader: Object.entries(headers).map( .get(`${this.config.tubeApi}video?v=${videoId}`, {
([k, v]) => `${k}: ${v}` httpHeader: Object.entries(headers).map(
), ([k, v]) => `${k}: ${v}`
}).then((res) => { ),
const json = toJson(res.data); })
const parsed = JSON.parse(json); .then((res) => {
return { json: parsed, video: parsed.video }; const parsed = JSON.parse(toJson(res.data));
}), return { json: parsed, video: parsed.video };
}),
]); ]);
const vid = info; const vid = info;
@ -89,12 +95,15 @@ 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) => ({ // safe default for storyboards
url: sb.url, storyboards: Array.isArray(vid.storyboards)
width: sb.width, ? vid.storyboards.map((sb) => ({
height: sb.height, url: sb.url,
mime: sb.mimeType, width: sb.width,
})), height: sb.height,
mime: sb.mimeType,
}))
: [],
description: vid.description, description: vid.description,
descriptionHtml: vid.descriptionRenderers?.description, descriptionHtml: vid.descriptionRenderers?.description,
@ -157,13 +166,13 @@ 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: invapi_alt:
config.proxylocation === "EU" config.proxylocation === "EU"
? "https://invid-api.poketube.fun/api/v1" ? "https://invid-api.poketube.fun/api/v1"
: "https://iv.ggtyler.dev/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,
}); });