add support for i2p backends and onion numbered backends
All checks were successful
Invidious CI / build (push) Successful in 5m29s
All checks were successful
Invidious CI / build (push) Successful in 5m29s
This commit is contained in:
parent
bbec111997
commit
46dbf353ff
8 changed files with 62 additions and 44 deletions
|
@ -83,8 +83,11 @@ class Config
|
|||
@[YAML::Field(converter: Preferences::URIConverter)]
|
||||
property public_url : URI = URI.parse("")
|
||||
|
||||
@[YAML::Field(converter: Preferences::URIConverter)]
|
||||
property i2p_public_url : URI = URI.parse("")
|
||||
|
||||
property note : String = ""
|
||||
property domain : String = ""
|
||||
property domain : Array(String) = [] of String
|
||||
end
|
||||
|
||||
# Number of threads to use for crawling videos from channels (for updating subscriptions)
|
||||
|
|
|
@ -16,7 +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)
|
||||
generate_csp([companion.public_url.to_s, companion.i2p_public_url.to_s], @@exvpp_url[index], index)
|
||||
else
|
||||
@@status[index] = 0
|
||||
end
|
||||
|
@ -31,31 +31,38 @@ module BackendInfo
|
|||
begin
|
||||
info = HTTP::Client.get "#{companion.private_url}/info"
|
||||
exvpp_url = JSON.parse(info.body)["external_videoplayback_proxy"]?.try &.to_s
|
||||
exvpp_url = "" if exvpp_url.nil?
|
||||
@@exvpp_url[index] = exvpp_url
|
||||
if exvpp_url.empty?
|
||||
@@status[index] = 2
|
||||
return
|
||||
else
|
||||
begin
|
||||
exvpp_health = HTTP::Client.get "#{exvpp_url}/health"
|
||||
if exvpp_health.status_code == 200
|
||||
@@status[index] = 2
|
||||
return exvpp_url
|
||||
else
|
||||
@@status[index] = 1
|
||||
end
|
||||
rescue
|
||||
rescue JSON::ParseException
|
||||
@@status[index] = 2
|
||||
return
|
||||
end
|
||||
|
||||
exvpp_url = "" if exvpp_url.nil?
|
||||
@@exvpp_url[index] = exvpp_url
|
||||
if exvpp_url.empty?
|
||||
@@status[index] = 2
|
||||
return
|
||||
else
|
||||
begin
|
||||
exvpp_health = HTTP::Client.get "#{exvpp_url}/health"
|
||||
if exvpp_health.status_code == 200
|
||||
@@status[index] = 2
|
||||
return exvpp_url
|
||||
else
|
||||
@@status[index] = 1
|
||||
end
|
||||
rescue
|
||||
@@status[index] = 1
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
|
||||
private def generate_csp(companion_url : String, exvpp_url : String, index : Int32)
|
||||
private def generate_csp(companion_url : Array(String), exvpp_url : String? = nil, index : Int32? = nil)
|
||||
@@mutex.synchronize do
|
||||
@@csp[index] = " #{companion_url} #{exvpp_url}"
|
||||
@@csp[index] = ""
|
||||
companion_url.each do |url|
|
||||
@@csp[index] += " #{url}"
|
||||
end
|
||||
@@csp[index] += " #{exvpp_url}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,9 +9,8 @@ module Invidious::Routes::API::Manifest
|
|||
region = env.params.query["region"]?
|
||||
|
||||
if CONFIG.invidious_companion.present?
|
||||
current_companion = env.get("current_companion").as(Int32)
|
||||
invidious_companion = CONFIG.invidious_companion[current_companion]
|
||||
return env.redirect "#{invidious_companion.public_url}/api/manifest/dash/id/#{id}?#{env.params.query}"
|
||||
companion_public_url = env.get("companion_public_url").as(String)
|
||||
return env.redirect "#{companion_public_url}/api/manifest/dash/id/#{id}?#{env.params.query}"
|
||||
end
|
||||
|
||||
# Since some implementations create playlists based on resolution regardless of different codecs,
|
||||
|
|
|
@ -25,11 +25,19 @@ module Invidious::Routes::BeforeAll
|
|||
|
||||
if CONFIG.invidious_companion.present?
|
||||
CONFIG.invidious_companion.each_with_index do |companion, index|
|
||||
if companion.domain == env.request.headers["Host"]
|
||||
env.set "current_companion", index
|
||||
env.set "domain", true
|
||||
break
|
||||
if companion.domain.each_with_index do |domain, domain_index|
|
||||
if domain == env.request.headers["Host"]
|
||||
env.set "current_companion", index
|
||||
env.set "companion_public_url", companion.public_url.to_s
|
||||
env.set "domain_index", domain_index
|
||||
if domain_index == 2
|
||||
env.set "companion_public_url", companion.i2p_public_url.to_s
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
break if env.get?("current_companion")
|
||||
end
|
||||
|
||||
if env.get?("current_companion").try &.as(Int32) == nil
|
||||
|
@ -49,6 +57,7 @@ module Invidious::Routes::BeforeAll
|
|||
end
|
||||
|
||||
env.set "current_companion", current_companion
|
||||
env.set "companion_public_url", CONFIG.invidious_companion[current_companion].public_url.to_s
|
||||
end
|
||||
|
||||
extra_media_csp, extra_connect_csp = BackendInfo.get_csp(env.get("current_companion").as(Int32))
|
||||
|
|
|
@ -267,9 +267,8 @@ module Invidious::Routes::VideoPlayback
|
|||
# so we have a mechanism here to redirect to the latest version
|
||||
def self.latest_version(env)
|
||||
if CONFIG.invidious_companion.present?
|
||||
current_companion = env.get("current_companion").as(Int32)
|
||||
invidious_companion = CONFIG.invidious_companion[current_companion]
|
||||
return env.redirect "#{invidious_companion.public_url}/latest_version?#{env.params.query}"
|
||||
companion_public_url = env.get("companion_public_url").as(String)
|
||||
return env.redirect "#{companion_public_url}/latest_version?#{env.params.query}"
|
||||
end
|
||||
|
||||
id = env.params.query["id"]?
|
||||
|
|
|
@ -348,9 +348,8 @@ module Invidious::Routes::Watch
|
|||
|
||||
if (CONFIG.invidious_companion.present?)
|
||||
video = get_video(video_id, env: env)
|
||||
current_companion = env.get("current_companion").as(Int32)
|
||||
invidious_companion = CONFIG.invidious_companion[current_companion]
|
||||
return env.redirect "#{invidious_companion.public_url}/latest_version?#{env.params.query}"
|
||||
companion_public_url = env.get("companion_public_url").as(String)
|
||||
return env.redirect "#{companion_public_url}/latest_version?#{env.params.query}"
|
||||
else
|
||||
return Invidious::Routes::VideoPlayback.latest_version(env)
|
||||
end
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
audio_streams.each_with_index do |fmt, i|
|
||||
src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}"
|
||||
src_url += "&local=true" if params.local
|
||||
src_url = invidious_companion.public_url.to_s + src_url +
|
||||
companion_public_url = env.get("companion_public_url").as(String)
|
||||
src_url = companion_public_url + src_url +
|
||||
"&check=#{invidious_companion_encrypt(video.id)}" if (invidious_companion)
|
||||
|
||||
bitrate = fmt["bitrate"]
|
||||
|
@ -38,7 +39,8 @@
|
|||
<% else %>
|
||||
<% if params.quality == "dash"
|
||||
src_url = "/api/manifest/dash/id/" + video.id + "?local=true&unique_res=1"
|
||||
src_url = invidious_companion.public_url.to_s + src_url +
|
||||
companion_public_url = env.get("companion_public_url").as(String)
|
||||
src_url = companion_public_url + src_url +
|
||||
"&check=#{invidious_companion_encrypt(video.id)}" if (invidious_companion)
|
||||
%>
|
||||
<source src="<%= src_url %>" type='application/dash+xml' label="dash">
|
||||
|
@ -50,7 +52,8 @@
|
|||
fmt_stream.each_with_index do |fmt, i|
|
||||
src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}"
|
||||
src_url += "&local=true" if params.local
|
||||
src_url = invidious_companion.public_url.to_s + src_url +
|
||||
companion_public_url = env.get("companion_public_url").as(String)
|
||||
src_url = companion_public_url + src_url +
|
||||
"&check=#{invidious_companion_encrypt(video.id)}" if (invidious_companion)
|
||||
|
||||
quality = fmt["quality"]
|
||||
|
|
|
@ -109,16 +109,16 @@
|
|||
<%
|
||||
if CONFIG.invidious_companion.present?
|
||||
current_backend = env.get?("current_companion").try &.as(Int32)
|
||||
domain = env.get?("domain").try &.as(Bool)
|
||||
domain_index = env.get?("domain_index").try &.as(Int32)
|
||||
scheme = env.get("scheme")
|
||||
status = BackendInfo.get_status
|
||||
%>
|
||||
<div class="h-box" style="margin-bottom: 10px;">
|
||||
<b>Switch Backend:</b>
|
||||
<% if domain %>
|
||||
<% if domain_index %>
|
||||
<% CONFIG.invidious_companion.each_with_index do | companion, index | %>
|
||||
<% is_current_backend_host = companion.domain == env.request.headers["Host"] %>
|
||||
<a href="<%= scheme %>://<%= companion.domain %><%= env.request.resource %>" style="<%= is_current_backend_host ? "text-decoration-line: underline;" : "" %> display: inline-block;">
|
||||
<% is_current_backend_host = companion.domain[domain_index] == env.request.headers["Host"] %>
|
||||
<a href="<%= scheme %>://<%= companion.domain[domain_index] %><%= env.request.resource %>" style="<%= is_current_backend_host ? "text-decoration-line: underline;" : "" %> display: inline-block;">
|
||||
Backend<%= HTML.escape((index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||
<span style="color:
|
||||
<% if status[index] == 0 %> #fd4848; <% end %>
|
||||
|
@ -132,8 +132,7 @@
|
|||
<% end %>
|
||||
<% else %>
|
||||
<% CONFIG.invidious_companion.each_with_index do | companion, index | %>
|
||||
<% is_current_backend_index = current_backend == index %>
|
||||
<a href="/switchbackend?backend_id=<%= index.to_s %>" style="<%= is_current_backend_index ? "text-decoration-line: underline;" : "" %> display: inline-block;">
|
||||
<a href="/switchbackend?backend_id=<%= index.to_s %>" style="<%= current_backend == index ? "text-decoration-line: underline;" : "" %> display: inline-block;">
|
||||
Backend<%= HTML.escape((index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||
<span style="color:
|
||||
<% if status[index] == 0 %> #fd4848; <% end %>
|
||||
|
@ -332,9 +331,9 @@
|
|||
<div class="footer-footer">
|
||||
<%
|
||||
if CONFIG.invidious_companion.present?
|
||||
current_backend = env.get?("current_companion").try &.as(Int32)
|
||||
companion_public_url = env.get("companion_public_url").as(String)
|
||||
%>
|
||||
<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>
|
||||
<div class="box">You are currently using Backend: <%= current_backend ? companion_public_url : "Unable to get backend, this is bug, please report it!" %></div>
|
||||
<% end %>
|
||||
<span class="left">
|
||||
<% if CONFIG.modified_source_code_url %>
|
||||
|
|
Loading…
Add table
Reference in a new issue