fixup! Feat: Experimental support for external videoplayback proxies
Some checks are pending
Invidious CI / build (push) Waiting to run
Some checks are pending
Invidious CI / build (push) Waiting to run
This commit is contained in:
parent
cc8ebf10b7
commit
367f6d8eac
2 changed files with 26 additions and 2 deletions
13
src/invidious/jobs/check_external_proxy.cr
Normal file
13
src/invidious/jobs/check_external_proxy.cr
Normal 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
|
|
@ -1,4 +1,15 @@
|
||||||
module Invidious::Routes::API::Manifest
|
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
|
# /api/manifest/dash/id/:id
|
||||||
def self.get_dash_video_id(env)
|
def self.get_dash_video_id(env)
|
||||||
env.response.headers.add("Access-Control-Allow-Origin", "*")
|
env.response.headers.add("Access-Control-Allow-Origin", "*")
|
||||||
|
@ -35,7 +46,7 @@ module Invidious::Routes::API::Manifest
|
||||||
|
|
||||||
if local
|
if local
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
if CONFIG.external_videoplayback_proxy
|
if @@proxy_alive
|
||||||
url = "#{CONFIG.external_videoplayback_proxy}#{uri.request_target}host/#{uri.host}/"
|
url = "#{CONFIG.external_videoplayback_proxy}#{uri.request_target}host/#{uri.host}/"
|
||||||
else
|
else
|
||||||
url = "#{HOST_URL}#{uri.request_target}host/#{uri.host}/"
|
url = "#{HOST_URL}#{uri.request_target}host/#{uri.host}/"
|
||||||
|
@ -52,7 +63,7 @@ module Invidious::Routes::API::Manifest
|
||||||
|
|
||||||
if local
|
if local
|
||||||
adaptive_fmts.each do |fmt|
|
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}")
|
fmt["url"] = JSON::Any.new("#{CONFIG.external_videoplayback_proxy}#{URI.parse(fmt["url"].as_s).request_target}")
|
||||||
else
|
else
|
||||||
fmt["url"] = JSON::Any.new("#{HOST_URL}#{URI.parse(fmt["url"].as_s).request_target}")
|
fmt["url"] = JSON::Any.new("#{HOST_URL}#{URI.parse(fmt["url"].as_s).request_target}")
|
||||||
|
|
Loading…
Reference in a new issue