forked from Fijxu/invidious
Revert "External Proxies: Rotate between proxies with balance
enabled"
This reverts commit 26bee068eb
.
It's broken and it doesn't work when a proxy comes back up.
This commit is contained in:
parent
e2276ace1b
commit
67998d1f36
3 changed files with 12 additions and 39 deletions
|
@ -390,7 +390,7 @@ def gen_videoplayback_proxy_list
|
||||||
if !CONFIG.external_videoplayback_proxy.empty?
|
if !CONFIG.external_videoplayback_proxy.empty?
|
||||||
external_videoplayback_proxy = ""
|
external_videoplayback_proxy = ""
|
||||||
CONFIG.external_videoplayback_proxy.each do |proxy|
|
CONFIG.external_videoplayback_proxy.each do |proxy|
|
||||||
external_videoplayback_proxy += " #{proxy[:url]}"
|
external_videoplayback_proxy += " #{proxy}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
external_videoplayback_proxy = ""
|
external_videoplayback_proxy = ""
|
||||||
|
|
|
@ -4,51 +4,25 @@ module Invidious::HttpServer
|
||||||
module Utils
|
module Utils
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
@@proxy_list : Array(String) = [] of String
|
@@proxy_alive : String = ""
|
||||||
@@current_proxy : String = ""
|
|
||||||
@@count : Int64 = Time.utc.to_unix
|
|
||||||
|
|
||||||
def check_external_proxy
|
def check_external_proxy
|
||||||
CONFIG.external_videoplayback_proxy.each do |proxy|
|
CONFIG.external_videoplayback_proxy.each do |proxy|
|
||||||
begin
|
begin
|
||||||
response = HTTP::Client.get("#{proxy[:url]}/health")
|
response = HTTP::Client.get(proxy)
|
||||||
if response.status_code == 200
|
if response.status_code == 200
|
||||||
if @@proxy_list.includes?(proxy[:url])
|
@@proxy_alive = proxy
|
||||||
next
|
LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy}'")
|
||||||
end
|
break
|
||||||
if proxy[:balance]
|
|
||||||
@@proxy_list << proxy[:url]
|
|
||||||
LOGGER.debug("CheckExternalProxy: Adding proxy '#{proxy[:url]}' to the list of proxies")
|
|
||||||
end
|
|
||||||
break if proxy[:balance] == false && !@@proxy_list.empty?
|
|
||||||
@@proxy_list << proxy[:url]
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
if @@proxy_list.includes?(proxy[:url])
|
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy}' is not available")
|
||||||
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy[:url]}' is not available, removing it from the list of proxies")
|
|
||||||
@@proxy_list.delete(proxy[:url])
|
|
||||||
end
|
|
||||||
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy[:url]}' is not available")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
LOGGER.trace("CheckExternalProxy: List of proxies:")
|
|
||||||
LOGGER.trace("#{@@proxy_list.inspect}")
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: If the function is called many times, it will return a random
|
|
||||||
# proxy from the list. That is not how it should be.
|
|
||||||
# It should return the same proxy, in multiple function calls
|
|
||||||
def select_proxy
|
|
||||||
if (@@count - (Time.utc.to_unix - 30)) <= 0
|
|
||||||
return if @@proxy_list.size <= 0
|
|
||||||
@@current_proxy = @@proxy_list[Random.rand(@@proxy_list.size)]
|
|
||||||
LOGGER.debug("Current proxy is: '#{@@current_proxy}'")
|
|
||||||
@@count = Time.utc.to_unix
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_external_proxy
|
def get_external_proxy
|
||||||
return @@current_proxy
|
return @@proxy_alive
|
||||||
end
|
end
|
||||||
|
|
||||||
def proxy_video_url(raw_url : String, *, region : String? = nil, absolute : Bool = false)
|
def proxy_video_url(raw_url : String, *, region : String? = nil, absolute : Bool = false)
|
||||||
|
@ -61,8 +35,8 @@ module Invidious::HttpServer
|
||||||
url.query_params = params
|
url.query_params = params
|
||||||
|
|
||||||
if absolute
|
if absolute
|
||||||
if !(proxy = get_external_proxy()).empty?
|
if !@@proxy_alive.empty?
|
||||||
return "#{proxy}#{url.request_target}"
|
return "#{@@proxy_alive}#{url.request_target}"
|
||||||
else
|
else
|
||||||
return "#{HOST_URL}#{url.request_target}"
|
return "#{HOST_URL}#{url.request_target}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,8 @@ class Invidious::Jobs::CheckExternalProxy < Invidious::Jobs::BaseJob
|
||||||
def begin
|
def begin
|
||||||
loop do
|
loop do
|
||||||
HttpServer::Utils.check_external_proxy
|
HttpServer::Utils.check_external_proxy
|
||||||
HttpServer::Utils.select_proxy
|
LOGGER.info("CheckExternalProxy: Done, sleeping for 1 minute")
|
||||||
LOGGER.info("CheckExternalProxy: Done, sleeping for 15 seconds")
|
sleep 1.minutes
|
||||||
sleep 15.seconds
|
|
||||||
Fiber.yield
|
Fiber.yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue