fix stuff + add stuff

This commit is contained in:
ashley 2025-09-28 01:17:34 +02:00
parent 7a9d6d3c17
commit c1e5ec698c

View File

@ -184,6 +184,16 @@ class InnerTubePokeVidious {
} }
}; };
// pick API based on system time minute window
const minute = new Date().getMinutes();
const inFallbackWindow = minute % 20 >= 10; // 09 primary, 1019 fallback
const primaryUrl = `${this.config.invapi}/videos/${v}?hl=${contentlang}&region=${contentregion}&h=${btoa(Date.now())}`;
const fallbackUrl = `${this.config.inv_fallback}${v}?hl=${contentlang}&region=${contentregion}&h=${btoa(Date.now())}`;
const chooseFirst = inFallbackWindow ? fallbackUrl : primaryUrl;
const chooseSecond = inFallbackWindow ? primaryUrl : fallbackUrl;
try { try {
const [invComments, videoInfo] = await Promise.all([ const [invComments, videoInfo] = await Promise.all([
fetchWithRetry( fetchWithRetry(
@ -192,26 +202,14 @@ class InnerTubePokeVidious {
)}` )}`
).then((res) => res?.text()), ).then((res) => res?.text()),
(async () => { (async () => {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 5000);
try { try {
const res = await fetchWithRetry( const r = await fetchWithRetry(chooseFirst);
`${this.config.invapi}/videos/${v}?hl=${contentlang}&region=${contentregion}&h=${btoa( if (r.ok) return await r.text();
Date.now() throw new Error(`First API ${chooseFirst} failed with ${r.status}`);
)}`,
{ signal: controller.signal }
);
return await res.text();
} catch (err) { } catch (err) {
this.initError("Primary video fetch failed, trying fallback", err); this.initError("Primary choice failed, trying secondary", err);
const fallbackRes = await fetchWithRetry( const r2 = await fetchWithRetry(chooseSecond);
`${this.config.inv_fallback}${v}?hl=${contentlang}&region=${contentregion}&h=${btoa( return await r2.text();
Date.now()
)}`
);
return await fallbackRes.text();
} finally {
clearTimeout(timeout);
} }
})(), })(),
]); ]);