From 976e1ccf5a84e5b10ac7878c70e7139c5ef9a623 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sun, 13 Oct 2024 15:19:49 -0300 Subject: [PATCH] External Proxies: Proxyfi HD720 --- src/invidious/http_server/utils.cr | 4 ++++ src/invidious/routes/before_all.cr | 2 +- src/invidious/routes/video_playback.cr | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/invidious/http_server/utils.cr b/src/invidious/http_server/utils.cr index 86494060..eecfb1cc 100644 --- a/src/invidious/http_server/utils.cr +++ b/src/invidious/http_server/utils.cr @@ -21,6 +21,10 @@ module Invidious::HttpServer end end + def get_external_proxy + return @@proxy_alive + end + def proxy_video_url(raw_url : String, *, region : String? = nil, absolute : Bool = false) url = URI.parse(raw_url) diff --git a/src/invidious/routes/before_all.cr b/src/invidious/routes/before_all.cr index 41a2dd3c..f6a9bb00 100644 --- a/src/invidious/routes/before_all.cr +++ b/src/invidious/routes/before_all.cr @@ -45,7 +45,7 @@ module Invidious::Routes::BeforeAll "font-src 'self' data:", "connect-src 'self'" + EXT_VIDEOP_LIST, "manifest-src 'self'", - "media-src 'self' blob:" + extra_media_csp, + "media-src 'self' blob:" + extra_media_csp + EXT_VIDEOP_LIST, "child-src 'self' blob:", "frame-src 'self'", "frame-ancestors " + frame_ancestors, diff --git a/src/invidious/routes/video_playback.cr b/src/invidious/routes/video_playback.cr index d31a675a..5689b0c8 100644 --- a/src/invidious/routes/video_playback.cr +++ b/src/invidious/routes/video_playback.cr @@ -298,7 +298,16 @@ module Invidious::Routes::VideoPlayback end if local - url = URI.parse(url).request_target.not_nil! + external_proxy = Invidious::HttpServer::Utils.get_external_proxy + if !external_proxy.empty? + url = URI.parse(url) + external_proxy = URI.parse(external_proxy) + url.host = external_proxy.host + url.port = external_proxy.port + url = url.to_s + else + url = URI.parse(url).request_target.not_nil! + end url += "&title=#{URI.encode_www_form(title, space_to_plus: false)}" if title end