Merge pull request 'External proxy support' (#3) from external-proxy into master
All checks were successful
Invidious CI / build (push) Successful in 14m52s

Reviewed-on: #3
This commit is contained in:
Fijxu 2024-09-27 19:11:39 -03:00
commit 28e95a2655
4 changed files with 22 additions and 7 deletions

View file

@ -172,6 +172,8 @@ class Config
# List of names of the backends
property backends : Array(String) = [] of String
property external_videoplayback_proxy : String?
# Materialious redirects
property materialious_domain : String?

View file

@ -35,8 +35,12 @@ module Invidious::Routes::API::Manifest
if local
uri = URI.parse(url)
if CONFIG.external_videoplayback_proxy
url = "#{CONFIG.external_videoplayback_proxy}#{uri.request_target}host/#{uri.host}/"
else
url = "#{HOST_URL}#{uri.request_target}host/#{uri.host}/"
end
end
"<BaseURL>#{url}</BaseURL>"
end
@ -48,9 +52,13 @@ module Invidious::Routes::API::Manifest
if local
adaptive_fmts.each do |fmt|
if CONFIG.external_videoplayback_proxy
fmt["url"] = JSON::Any.new("#{CONFIG.external_videoplayback_proxy}#{URI.parse(fmt["url"].as_s).request_target}")
else
fmt["url"] = JSON::Any.new("#{HOST_URL}#{URI.parse(fmt["url"].as_s).request_target}")
end
end
end
audio_streams = video.audio_streams.sort_by { |stream| {stream["bitrate"].as_i} }.reverse!
video_streams = video.video_streams.sort_by { |stream| {stream["width"].as_i, stream["fps"].as_i} }.reverse!
@ -62,7 +70,6 @@ module Invidious::Routes::API::Manifest
end
end
manifest = XML.build(indent: " ", encoding: "UTF-8") do |xml|
xml.element("MPD", "xmlns": "urn:mpeg:dash:schema:mpd:2011",
"profiles": "urn:mpeg:dash:profile:full:2011", minBufferTime: "PT1.5S", type: "static",

View file

@ -28,6 +28,12 @@ module Invidious::Routes::BeforeAll
extra_media_csp = ""
end
if CONFIG.external_videoplayback_proxy
external_videoplayback_proxy = " #{CONFIG.external_videoplayback_proxy}"
else
external_videoplayback_proxy = ""
end
# Only allow the pages at /embed/* to be embedded
if env.request.resource.starts_with?("/embed")
frame_ancestors = "'self' file: http: https:"
@ -43,7 +49,7 @@ module Invidious::Routes::BeforeAll
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data:",
"font-src 'self' data:",
"connect-src 'self'",
"connect-src 'self'" + external_videoplayback_proxy,
"manifest-src 'self'",
"media-src 'self' blob:" + extra_media_csp,
"child-src 'self' blob:",