Files
invidious/patches/companion/0004-add-proxy-retries-on-innertube-error.patch
T
2025-06-27 13:54:34 +02:00

79 lines
3.0 KiB
Diff

From 8d35596d51350b959d724638fb703661992e1cc4 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net>
Date: Tue, 25 Mar 2025 00:04:47 -0300
Subject: [PATCH 04/12] add proxy retries on innertube error
---
config/config.example.toml | 1 +
src/lib/helpers/config.ts | 3 +++
src/lib/helpers/youtubePlayerHandling.ts | 23 ++++++++++++++++++++++-
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/config/config.example.toml b/config/config.example.toml
index 84c4f02..2112564 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -33,6 +33,7 @@
# ump = false # env variable: NETWORKING_VIDEOPLAYBACK_UMP
# # size of chunks to request from google servers for rate limiting reductions
# video_fetch_chunk_size_mb = 5 # env variable: NETWORKING_VIDEOPLAYBACK_VIDEO_FETCH_CHUNK_SIZE_MB
+# max_proxy_retries = 2 # env variable: NETWORKING_MAX_PROXY_RETRIES
###
# Network call timeouts when talking to YouTube.
diff --git a/src/lib/helpers/config.ts b/src/lib/helpers/config.ts
index 3990214..01dda24 100644
--- a/src/lib/helpers/config.ts
+++ b/src/lib/helpers/config.ts
@@ -70,6 +70,9 @@ export const ConfigSchema = z.object({
) || 5,
),
}).strict().default({}),
+ max_proxy_retries: z.number().default(
+ Number(Deno.env.get("NETWORKING_MAX_PROXY_RETIRES") || 2),
+ ),
}).strict().default({}),
jobs: z.object({
youtube_session: z.object({
diff --git a/src/lib/helpers/youtubePlayerHandling.ts b/src/lib/helpers/youtubePlayerHandling.ts
index 6565d06..d809c09 100644
--- a/src/lib/helpers/youtubePlayerHandling.ts
+++ b/src/lib/helpers/youtubePlayerHandling.ts
@@ -43,12 +43,33 @@ export const youtubePlayerParsing = async ({
if (videoCached != null && cacheEnabled) {
return JSON.parse(new TextDecoder().decode(decompress(videoCached)));
} else {
- const youtubePlayerResponse = await youtubePlayerReq(
+ let youtubePlayerResponse = await youtubePlayerReq(
innertubeClient,
videoId,
config,
tokenMinter,
);
+
+ const maxRetries = config.networking.max_proxy_retries;
+ for (let retries = 1; retries <= (maxRetries as number); retries++) {
+ if (
+ !youtubePlayerResponse.data.playabilityStatus?.errorScreen
+ ?.playerErrorMessageRenderer?.subreason?.runs?.[0]?.text
+ ?.includes("This helps protect our community")
+ ) {
+ break;
+ }
+ console.log(
+ `[DEBUG] Got 'This helps protect our community', retrying request for ${videoId}. Retry ${retries} of ${maxRetries}`,
+ );
+ youtubePlayerResponse = await youtubePlayerReq(
+ innertubeClient,
+ videoId,
+ config,
+ tokenMinter,
+ );
+ }
+
const videoData = youtubePlayerResponse.data;
if (videoData.playabilityStatus.status === "ERROR") {
--
2.49.0