From 428db0810f1d912b302952266b35abd5b4249587 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sat, 14 Dec 2024 03:17:34 -0300 Subject: [PATCH] add support for an external videoplayback proxy --- config/default.toml | 4 +++- deno.lock | 10 ++++++++++ src/lib/helpers/youtubePlayerHandling.ts | 2 ++ src/routes/invidious_routes/dashManifest.ts | 3 ++- src/routes/invidious_routes/latestVersion.ts | 4 +++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/config/default.toml b/config/default.toml index c1d43f8..bc05c2f 100644 --- a/config/default.toml +++ b/config/default.toml @@ -1,7 +1,7 @@ [server] port = 8282 host = "127.0.0.1" -secret_key = "CHANGE_ME" +secret_key = "myBeautifulKey" base_url = "http://localhost:8282" verify_requests = false @@ -15,6 +15,8 @@ directory = "/var/tmp" #proxy = "" # Enable YouTube new video format UMP ump = false +# Some external videoplayback +# external_videoplayback_proxy = "" [jobs] diff --git a/deno.lock b/deno.lock index bb00c55..d2654d8 100644 --- a/deno.lock +++ b/deno.lock @@ -13,6 +13,7 @@ "npm:@willsoto/node-konfig-file@3.0.0": "3.0.0_@willsoto+node-konfig-core@5.0.0", "npm:@willsoto/node-konfig-toml-parser@3.0.0": "3.0.0_@willsoto+node-konfig-core@5.0.0", "npm:acorn@^8.8.0": "8.14.0", + "npm:googlevideo@2.0.0": "2.0.0", "npm:jsdom@25.0.1": "25.0.1" }, "jsr": { @@ -40,6 +41,9 @@ } }, "npm": { + "@bufbuild/protobuf@2.2.3": { + "integrity": "sha512-tFQoXHJdkEOSwj5tRIZSPNUuXK3RaR7T1nUrPgbYX1pUbvqqaaZAsfo+NXBPsz5rZMSKVFrgK1WL8Q/MSLvprg==" + }, "@types/estree@1.0.6": { "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==" }, @@ -123,6 +127,12 @@ "mime-types" ] }, + "googlevideo@2.0.0": { + "integrity": "sha512-OVlNWZ07TPIelaEII6mH9od+Cxljl7P4AzhEYVNN5d4FhFT9L5otpcLtgvraTE9u69KfVVw+L4pVeczArcD33w==", + "dependencies": [ + "@bufbuild/protobuf" + ] + }, "html-encoding-sniffer@4.0.0": { "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", "dependencies": [ diff --git a/src/lib/helpers/youtubePlayerHandling.ts b/src/lib/helpers/youtubePlayerHandling.ts index a545e12..64f4b10 100644 --- a/src/lib/helpers/youtubePlayerHandling.ts +++ b/src/lib/helpers/youtubePlayerHandling.ts @@ -114,6 +114,8 @@ export const youtubePlayerParsing = async ( invidiousCompanion: { "baseUrl": Deno.env.get("SERVER_BASE_URL") || konfigStore.get("server.base_url") as string, + "external_videoplayback_proxy": Deno.env.get("EXTERNAL_VIDEOPLAYBACK_PROXY") || + konfigStore.get("networking.external_videoplayback_proxy") as string, }, }))(videoData); diff --git a/src/routes/invidious_routes/dashManifest.ts b/src/routes/invidious_routes/dashManifest.ts index b0dcc0e..91397f1 100644 --- a/src/routes/invidious_routes/dashManifest.ts +++ b/src/routes/invidious_routes/dashManifest.ts @@ -91,11 +91,12 @@ dashManifest.get("/:videoId", async (c) => { let dashUrl = url; if (local) { // Can't create URL type without host part - dashUrl = (dashUrl.pathname + dashUrl.search + "&host=" + + dashUrl = (konfigStore.get("networking.external_videoplayback_proxy") as string ?? "") + (dashUrl.pathname + dashUrl.search + "&host=" + dashUrl.host) as unknown as URL; if (konfigStore.get("networking.ump") as boolean) { dashUrl = dashUrl + "&ump=1" as unknown as URL; } + console.log(dashUrl) return dashUrl; } else { return dashUrl; diff --git a/src/routes/invidious_routes/latestVersion.ts b/src/routes/invidious_routes/latestVersion.ts index 2562534..1ae6470 100644 --- a/src/routes/invidious_routes/latestVersion.ts +++ b/src/routes/invidious_routes/latestVersion.ts @@ -69,9 +69,11 @@ latestVersion.get("/", async (c) => { } else if (selectedItagFormat) { const itagUrl = selectedItagFormat[0].url as string; const itagUrlParsed = new URL(itagUrl); + console.log(itagUrlParsed) let urlToRedirect = itagUrlParsed.toString(); if (local) { - urlToRedirect = itagUrlParsed.pathname + urlToRedirect.search + + urlToRedirect = konfigStore.get("networking.external_videoplayback_proxy") as string ?? "" + + itagUrlParsed.pathname + urlToRedirect.search + "&host=" + itagUrlParsed.host; } return c.redirect(urlToRedirect);