invidious-companion-patches/patches/0004-feat-add-resolution-limit-on-DASH-streams-to-save-ba.patch
Fijxu a47a5e5cd5
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m7s
add 0013-metrics-track-unidentified-innertube-errors.patch and 0014-metrics-add-more-errors.patch
2025-04-15 19:38:33 -04:00

55 lines
2.1 KiB
Diff

From 72b7cc213b4afe510f530990f252913c0003af15 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 19:02:01 -0300
Subject: [PATCH 04/15] feat: add resolution limit on DASH streams to save
bandwidth
---
config/config.example.toml | 1 +
src/lib/helpers/config.ts | 3 +++
src/routes/invidious_routes/dashManifest.ts | 3 ++-
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/config/config.example.toml b/config/config.example.toml
index 4aec8e9..8e2af1c 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -17,6 +17,7 @@
# verify_requests = false
# encrypt_query_params = false # env variable: SERVER_ENCRYPT_QUERY_PARAMS
# enable_metrics = false # env variable: SERVER_ENABLE_METRICS
+# max_dash_resolution = 1080
# [cache]
# enabled = true
diff --git a/src/lib/helpers/config.ts b/src/lib/helpers/config.ts
index a233f83..e559271 100644
--- a/src/lib/helpers/config.ts
+++ b/src/lib/helpers/config.ts
@@ -15,6 +15,9 @@ export const ConfigSchema = z.object({
enable_metrics: z.boolean().default(
Deno.env.get("SERVER_ENABLE_METRICS") === "true" || false,
),
+ max_dash_resolution: z.number().default(
+ Number(Deno.env.get("SERVER_MAX_DASH_RESOLUTION")),
+ ),
}).strict().default({}),
cache: z.object({
enabled: z.boolean().default(true),
diff --git a/src/routes/invidious_routes/dashManifest.ts b/src/routes/invidious_routes/dashManifest.ts
index b4446b6..a691d6e 100644
--- a/src/routes/invidious_routes/dashManifest.ts
+++ b/src/routes/invidious_routes/dashManifest.ts
@@ -55,7 +55,8 @@ dashManifest.get("/:videoId", async (c) => {
videoInfo.streaming_data.adaptive_formats = videoInfo
.streaming_data.adaptive_formats
.filter((i) =>
- i.has_video === false || i.mime_type.includes("mp4")
+ //@ts-ignore: 'i.height' is possibly 'undefined'.
+ i.has_video === false || (i.mime_type.includes("mp4") && (i.height <= config.server.max_dash_resolution))
);
const player_response = videoInfo.page[0];
--
2.49.0