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" &&
@ -46,8 +47,10 @@ class InnerTubePokeVidious {
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,13 +75,14 @@ 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
.get(`${this.config.tubeApi}video?v=${videoId}`, {
httpHeader: Object.entries(headers).map( httpHeader: Object.entries(headers).map(
([k, v]) => `${k}: ${v}` ([k, v]) => `${k}: ${v}`
), ),
}).then((res) => { })
const json = toJson(res.data); .then((res) => {
const parsed = JSON.parse(json); const parsed = JSON.parse(toJson(res.data));
return { json: parsed, video: parsed.video }; return { json: parsed, video: parsed.video };
}), }),
]); ]);
@ -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
storyboards: Array.isArray(vid.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,
descriptionHtml: vid.descriptionRenderers?.description, descriptionHtml: vid.descriptionRenderers?.description,