Compare commits
2 commits
015a68d01e
...
6335359272
Author | SHA1 | Date | |
---|---|---|---|
6335359272 | |||
b9468ea6e0 |
10 changed files with 18 additions and 113 deletions
10
README.md
10
README.md
|
@ -37,16 +37,6 @@ https://git.nadeko.net/Fijxu/-/packages/container/invidious/latest
|
|||
|
||||
- [Removal of materialized views on PostgreSQL](github.com/iv-org/invidious/pull/2469): If you don't have this on your Invidious public instance, your SSD will suffer and it will catch on fire https://github.com/iv-org/invidious/pull/2469#issuecomment-2012623454
|
||||
|
||||
- External video playback proxy: Let's you use an external video playback proxy like https://git.nadeko.net/Fijxu/http3-ytproxy or https://github.com/TeamPiped/piped-proxy instead of the one that is bundled with Invidious. It's useful if you are proxying video and your throughput is not low. I did this to distribute the traffic across different servers. If you are selfhosting only for a few amount of people, this is not really useful for you.
|
||||
|
||||
It can be set using this on `config.yml`:
|
||||
```yaml
|
||||
external_videoplayback_proxy: "https://inv-proxy.example.com"
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> If you setup this, Invidious will check if the proxy is alive doing a request to `https://inv-proxy.example.com/health`, and if it doesn't get a response code of 200, Invidious will fallback to the local videoplayback proxy! This is only currently supported by https://git.nadeko.net/Fijxu/http3-ytproxy
|
||||
|
||||
- Limit the DASH resolution sent to the clients: It can be set using `max_dash_resolution` on the config. Example: `max_dash_resolution: 1080`
|
||||
|
||||
- [Limit requests made to Youtube API when pulling subscriptions (feeds)](https://git.nadeko.net/Fijxu/invidious/commit/df94f1c0b82d95846574487231ea251530838ef0): Due to the recent changes of Youtube ("This helps protect out community", "Sign in to confirm you are not a bot"), subscriptions now have limited information, this is because Invidious by default, makes a video request to youtube to be able to get more information about the video, like `length_seconds`, `live_now`, `premiere_timestamp`, and `views`. If you have a lot of users with a ton of subscriptions, Invidious will basically spam youtube API all the time, resulting in a block from youtube.
|
||||
|
|
|
@ -210,14 +210,6 @@ Invidious::Jobs.register Invidious::Jobs::ClearExpiredItemsJob.new
|
|||
|
||||
Invidious::Jobs.register Invidious::Jobs::InstanceListRefreshJob.new
|
||||
|
||||
if !CONFIG.external_videoplayback_proxy.empty?
|
||||
Invidious::Jobs.register Invidious::Jobs::CheckExternalProxy.new
|
||||
else
|
||||
# Invidious will it's own videoplayback proxy unless the admin decides to rewrite
|
||||
# the /videoplayback location in the reverse proxy configuration (NGINX, Caddy, etc)
|
||||
LOGGER.info("jobs: Disabling CheckExternalProxy job. Invidious will it's own videoplayback proxy")
|
||||
end
|
||||
|
||||
if !CONFIG.tokens_server.empty?
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshSessionTokens.new
|
||||
else
|
||||
|
|
|
@ -215,10 +215,6 @@ class Config
|
|||
# of the backend
|
||||
property backends_delimiter : String = "|"
|
||||
|
||||
# External videoplayback proxies list. They should include `https://`
|
||||
# at the start of the URI
|
||||
property external_videoplayback_proxy : Array(String) = [] of String
|
||||
|
||||
property pubsub_domain : String = ""
|
||||
|
||||
property server_id_cookie_name : String = "INVIDIOUS_SERVER_ID"
|
||||
|
|
|
@ -2,12 +2,11 @@ module BackendInfo
|
|||
extend self
|
||||
@@exvpp_url : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
|
||||
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, 0)
|
||||
@@extra_media_csp : String = ""
|
||||
@@extra_connect_csp : String = ""
|
||||
@@csp : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
|
||||
@@mutex : Mutex = Mutex.new
|
||||
|
||||
def check_backends
|
||||
check_companion()
|
||||
generate_csp()
|
||||
end
|
||||
|
||||
private def check_companion
|
||||
|
@ -17,6 +16,7 @@ module BackendInfo
|
|||
response = HTTP::Client.get "#{companion.private_url}/healthz"
|
||||
if response.status_code == 200
|
||||
check_videoplayback_proxy(companion, index)
|
||||
generate_csp(companion.public_url.to_s, @@exvpp_url[index], index)
|
||||
else
|
||||
@@status[index] = 0
|
||||
end
|
||||
|
@ -41,7 +41,7 @@ module BackendInfo
|
|||
exvpp_health = HTTP::Client.get "#{exvpp_url}/health"
|
||||
if exvpp_health.status_code == 200
|
||||
@@status[index] = 2
|
||||
return
|
||||
return exvpp_url
|
||||
else
|
||||
@@status[index] = 1
|
||||
end
|
||||
|
@ -53,20 +53,9 @@ module BackendInfo
|
|||
end
|
||||
end
|
||||
|
||||
private def generate_csp
|
||||
@@extra_media_csp = ""
|
||||
@@extra_connect_csp = ""
|
||||
|
||||
CONFIG.invidious_companion.each do |companion|
|
||||
@@extra_media_csp += " #{companion.public_url}"
|
||||
@@extra_connect_csp += " #{companion.public_url}"
|
||||
end
|
||||
exvpp_urls = self.get_exvpp
|
||||
exvpp_urls.each do |exvpp_url|
|
||||
if !exvpp_url.empty?
|
||||
@@extra_media_csp += " #{exvpp_url}"
|
||||
@@extra_connect_csp += " #{exvpp_url}"
|
||||
end
|
||||
private def generate_csp(companion_url : String, exvpp_url : String, index : Int32)
|
||||
@@mutex.synchronize do
|
||||
@@csp[index] = " #{companion_url} #{exvpp_url}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -78,7 +67,12 @@ module BackendInfo
|
|||
return @@exvpp_url
|
||||
end
|
||||
|
||||
def get_csp
|
||||
return @@extra_media_csp, @@extra_connect_csp
|
||||
def get_csp(index : Int32)
|
||||
# A little mutex to prevent sending a partial CSP header
|
||||
# Not sure if this is necessary. But if the @@csp[index] is being assigned
|
||||
# at the same time when it's being accessed, a data race will appear
|
||||
@@mutex.synchronize do
|
||||
return @@csp[index], @@csp[index]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,30 +4,6 @@ module Invidious::HttpServer
|
|||
module Utils
|
||||
extend self
|
||||
|
||||
@@proxy_alive : String = ""
|
||||
|
||||
def check_external_proxy
|
||||
CONFIG.external_videoplayback_proxy.each do |proxy|
|
||||
begin
|
||||
response = HTTP::Client.get("#{proxy}/health")
|
||||
if response.status_code == 200
|
||||
@@proxy_alive = proxy
|
||||
LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy}'")
|
||||
break
|
||||
end
|
||||
rescue
|
||||
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy}' is not available")
|
||||
end
|
||||
end
|
||||
if @@proxy_alive.empty?
|
||||
LOGGER.warn("CheckExternalProxy: No proxies alive! Using own server proxy")
|
||||
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)
|
||||
|
||||
|
@ -38,11 +14,7 @@ module Invidious::HttpServer
|
|||
url.query_params = params
|
||||
|
||||
if absolute
|
||||
if !@@proxy_alive.empty?
|
||||
return "#{@@proxy_alive}#{url.request_target}"
|
||||
else
|
||||
return "#{HOST_URL}#{url.request_target}"
|
||||
end
|
||||
return "#{HOST_URL}#{url.request_target}"
|
||||
else
|
||||
return url.request_target
|
||||
end
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
class Invidious::Jobs::CheckExternalProxy < Invidious::Jobs::BaseJob
|
||||
def initialize
|
||||
end
|
||||
|
||||
def begin
|
||||
loop do
|
||||
HttpServer::Utils.check_external_proxy
|
||||
LOGGER.info("CheckExternalProxy: Done, sleeping for 10 seconds")
|
||||
sleep 10.seconds
|
||||
Fiber.yield
|
||||
end
|
||||
end
|
||||
end
|
|
@ -222,19 +222,13 @@ module Invidious::Routes::API::Manifest
|
|||
|
||||
raw_params["host"] = uri.host.not_nil!
|
||||
|
||||
proxy = Invidious::HttpServer::Utils.get_external_proxy
|
||||
|
||||
if CONFIG.https_only
|
||||
scheme = "https://"
|
||||
else
|
||||
scheme = "http://"
|
||||
end
|
||||
|
||||
if !proxy.empty?
|
||||
"#{proxy}/videoplayback?#{raw_params}"
|
||||
else
|
||||
"#{scheme}#{env.request.headers["Host"]}/videoplayback?#{raw_params}"
|
||||
end
|
||||
"#{scheme}#{env.request.headers["Host"]}/videoplayback?#{raw_params}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -51,14 +51,7 @@ module Invidious::Routes::BeforeAll
|
|||
env.set "current_companion", current_companion
|
||||
end
|
||||
|
||||
extra_media_csp, extra_connect_csp = BackendInfo.get_csp
|
||||
end
|
||||
|
||||
if !CONFIG.external_videoplayback_proxy.empty?
|
||||
CONFIG.external_videoplayback_proxy.each do |proxy|
|
||||
extra_media_csp += " #{proxy}"
|
||||
extra_connect_csp += " #{proxy}"
|
||||
end
|
||||
extra_media_csp, extra_connect_csp = BackendInfo.get_csp(env.get("current_companion").as(Int32))
|
||||
end
|
||||
|
||||
# Allow media resources to be loaded from google servers
|
||||
|
|
|
@ -313,16 +313,7 @@ module Invidious::Routes::VideoPlayback
|
|||
end
|
||||
|
||||
if local
|
||||
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 = URI.parse(url).request_target.not_nil!
|
||||
url += "&title=#{URI.encode_www_form(title, space_to_plus: false)}" if title
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<%
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
dark_mode = env.get("preferences").as(Preferences).dark_mode
|
||||
current_external_videoplayback_proxy = Invidious::HttpServer::Utils.get_external_proxy()
|
||||
%>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<%= locale %>">
|
||||
|
@ -336,9 +335,6 @@
|
|||
current_backend = env.get?("current_companion").try &.as(Int32)
|
||||
%>
|
||||
<div class="box">You are currently using Backend: <%= current_backend ? CONFIG.invidious_companion[current_backend].public_url : "Unable to get backend, this is bug, please report it!" %></div>
|
||||
<% end %>
|
||||
<% if !current_external_videoplayback_proxy.empty? %>
|
||||
<div class="box">External Videoplayback Proxy: <%= current_external_videoplayback_proxy %></div>
|
||||
<% end %>
|
||||
<span class="left">
|
||||
<% if CONFIG.modified_source_code_url %>
|
||||
|
|
Loading…
Add table
Reference in a new issue