From 84db2add0f0c4e3ab299d999e85966029f8d3c53 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Mon, 24 Mar 2025 19:02:01 -0300 Subject: [PATCH 04/13] 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