fixup! Feat: Experimental support for external videoplayback proxies
Some checks are pending
Invidious CI / build (push) Waiting to run

This commit is contained in:
Fijxu 2024-10-08 16:36:37 -03:00
parent cc8ebf10b7
commit 74bee220e4
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 30 additions and 2 deletions

View file

@ -188,6 +188,10 @@ Invidious::Jobs.register Invidious::Jobs::ClearExpiredItemsJob.new
Invidious::Jobs.register Invidious::Jobs::InstanceListRefreshJob.new
if CONFIG.external_videoplayback_proxy
Invidious::Jobs.register Invidious::Jobs::CheckExternalProxy.new
end
Invidious::Jobs.start_all
def popular_videos

View file

@ -0,0 +1,13 @@
class Invidious::Jobs::CheckExternalProxy < Invidious::Jobs::BaseJob
def initialize
end
def begin
loop do
Invidious::Routes::API::Manifest.check_external_proxy
LOGGER.info("CheckExternalProxy: Done, sleeping for 1 minute")
sleep 1.minutes
Fiber.yield
end
end
end

View file

@ -1,4 +1,15 @@
module Invidious::Routes::API::Manifest
@@proxy_alive : Bool = false
def self.check_external_proxy
begin
response = HTTP::Client.get("#{CONFIG.external_videoplayback_proxy}")
@@proxy_alive = response.status_code == 200
rescue
@@proxy_alive = false
end
end
# /api/manifest/dash/id/:id
def self.get_dash_video_id(env)
env.response.headers.add("Access-Control-Allow-Origin", "*")
@ -35,7 +46,7 @@ module Invidious::Routes::API::Manifest
if local
uri = URI.parse(url)
if CONFIG.external_videoplayback_proxy
if @@proxy_alive
url = "#{CONFIG.external_videoplayback_proxy}#{uri.request_target}host/#{uri.host}/"
else
url = "#{HOST_URL}#{uri.request_target}host/#{uri.host}/"
@ -52,7 +63,7 @@ module Invidious::Routes::API::Manifest
if local
adaptive_fmts.each do |fmt|
if CONFIG.external_videoplayback_proxy
if @@proxy_alive
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}")