diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr index 49aeade5..bde3e6c3 100644 --- a/src/invidious/routes/embed.cr +++ b/src/invidious/routes/embed.cr @@ -208,6 +208,12 @@ module Invidious::Routes::Embed env.response.headers["Content-Security-Policy"] .gsub("media-src", "media-src #{companion_base_url}") .gsub("connect-src", "connect-src #{companion_base_url}") + if external_videoplayback_proxy = video.invidious_companion.dig?("external_videoplayback_proxy").try &.as_s + env.response.headers["Content-Security-Policy"] = + env.response.headers["Content-Security-Policy"] + .gsub("media-src #{companion_base_url}", "media-src #{companion_base_url} #{external_videoplayback_proxy}") + .gsub("connect-src #{companion_base_url}", "connect-src #{companion_base_url} #{external_videoplayback_proxy}") + end end rendered "embed" diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index c8413cc9..9b63f61e 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -211,11 +211,23 @@ module Invidious::Routes::Watch captions: video.captions ) + begin + video_url = fmt_stream[0]["url"].to_s + rescue + video_url = nil + end + if companion_base_url = video.invidious_companion.try &.["baseUrl"].as_s env.response.headers["Content-Security-Policy"] = env.response.headers["Content-Security-Policy"] .gsub("media-src", "media-src #{companion_base_url}") .gsub("connect-src", "connect-src #{companion_base_url}") + if external_videoplayback_proxy = video.invidious_companion.dig?("external_videoplayback_proxy").try &.as_s + env.response.headers["Content-Security-Policy"] = + env.response.headers["Content-Security-Policy"] + .gsub("media-src #{companion_base_url}", "media-src #{companion_base_url} #{external_videoplayback_proxy}") + .gsub("connect-src #{companion_base_url}", "connect-src #{companion_base_url} #{external_videoplayback_proxy}") + end end templated "watch"