From 983f0bee1f68bfa8cb7d83a40d6a3cec68a3afa6 Mon Sep 17 00:00:00 2001 From: ashley Date: Mon, 1 Sep 2025 22:30:15 +0200 Subject: [PATCH] cool stuff :3 --- src/libpoketube/libpoketube-core.js | 81 +++++++++++------------------ 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/src/libpoketube/libpoketube-core.js b/src/libpoketube/libpoketube-core.js index 4a81c29a..1b8f833a 100644 --- a/src/libpoketube/libpoketube-core.js +++ b/src/libpoketube/libpoketube-core.js @@ -56,47 +56,41 @@ class InnerTubePokeVidious { const headers = { "User-Agent": this.useragent, - }; - + }; const fetchWithRetry = async (url, options = {}, retries = 3) => { - let lastError; + let lastError; + for (let attempt = 0; attempt < retries; attempt++) { + try { + const res = await fetch(url, { + ...options, + headers: { + ...options.headers, + ...headers, + }, + }); - for (let attempt = 0; attempt < retries; attempt++) { - try { - const res = await fetch(url, { - ...options, - headers: { - ...options.headers, - ...headers, - }, - }); + if (res.ok) { + return res; + } - // If success, return immediately - if (res.ok) { - return res; + if ((res.status >= 500 || res.status === 429) && attempt < retries - 1) { + this.initError(`Retrying fetch for ${url}`, res.status); + continue; + } + + return res; + } catch (err) { + lastError = err; + this.initError(`Fetch error for ${url}`, err); + if (attempt < retries - 1) { + continue; + } else { + throw lastError; + } + } } - - // If error but retryable - if ((res.status >= 500 || res.status === 429) && attempt < retries - 1) { - this.initError(`Retrying fetch for ${url}`, res.status); - continue; - } - - // If non-retryable error, return response - return res; - } catch (err) { - lastError = err; - this.initError(`Fetch error for ${url}`, err); - - if (attempt < retries - 1) { - continue; - } else { - throw lastError; - } - } - } -}; + }; try { const [invComments, videoInfo] = await Promise.all([ @@ -123,18 +117,6 @@ class InnerTubePokeVidious { }; } - let p = {}; - if (f === "true" && vid?.authorId) { - try { - const uploads = await fetchWithRetry( - `${this.config.invapi}/channels/${vid.authorId}?hl=${contentlang}®ion=${contentregion}` - ); - p = this.getJson(await uploads.text()); - } catch (err) { - this.initError("Failed to fetch channel uploads", err); - } - } - if (this.checkUnexistingObject(vid)) { let fe = { engagement: null }; try { @@ -161,7 +143,7 @@ class InnerTubePokeVidious { result: { vid, comments, - channel_uploads: p, + channel_uploads: " ", engagement: fe.engagement, wiki: "", desc: "", @@ -174,7 +156,6 @@ class InnerTubePokeVidious { return this.cache[v].result; } else { this.initError("Invalid video object (missing authorId)", vid); - } } catch (error) { this.initError("Error getting video", error);