Added proxiyng for videos with a given list of domains

This commit is contained in:
11tuvork28 2023-02-23 17:13:58 +01:00
parent 1c87da7050
commit 10c06ded90
3 changed files with 33 additions and 7 deletions

View File

@ -7,6 +7,11 @@ module Invidious::Routes::API::Manifest
local = env.params.query["local"]?.try &.== "true"
id = env.params.url["id"]
region = env.params.query["region"]?
proxy_url = HOST_URL
if CONFIG.proxy_domains.size > 0 && local
proxy_url = ("https:///" + CONFIG.proxy_domains.[Random.rand(CONFIG.proxy_domains.size)])
end
# Since some implementations create playlists based on resolution regardless of different codecs,
# we can opt to only add a source to a representation if it has a unique height within that representation
@ -29,7 +34,7 @@ module Invidious::Routes::API::Manifest
if local
uri = URI.parse(url)
url = "#{HOST_URL}#{uri.request_target}host/#{uri.host}/"
url = "#{proxy_url}#{uri.request_target}host/#{uri.host}/"
end
"<BaseURL>#{url}</BaseURL>"
@ -42,7 +47,7 @@ module Invidious::Routes::API::Manifest
if local
adaptive_fmts.each do |fmt|
fmt["url"] = JSON::Any.new("#{HOST_URL}#{URI.parse(fmt["url"].as_s).request_target}")
fmt["url"] = JSON::Any.new("#{proxy_url}#{URI.parse(fmt["url"].as_s).request_target}")
end
end
@ -164,6 +169,11 @@ module Invidious::Routes::API::Manifest
end
local = env.params.query["local"]?.try &.== "true"
proxy_url = HOST_URL
if CONFIG.proxy_domains.size > 0 && local
proxy_url = ("https:///" + CONFIG.proxy_domains.[Random.rand(CONFIG.proxy_domains.size)])
end
env.response.content_type = "application/x-mpegURL"
env.response.headers.add("Access-Control-Allow-Origin", "*")
@ -203,7 +213,7 @@ module Invidious::Routes::API::Manifest
raw_params["local"] = "true"
"#{HOST_URL}/videoplayback?#{raw_params}"
"#{proxy_url}/videoplayback?#{raw_params}"
end
end
@ -219,6 +229,11 @@ module Invidious::Routes::API::Manifest
end
local = env.params.query["local"]?.try &.== "true"
proxy_url = HOST_URL
if CONFIG.proxy_domains.size > 0 && local
proxy_url = ("https:///" + CONFIG.proxy_domains.[Random.rand(CONFIG.proxy_domains.size)])
end
env.response.content_type = "application/x-mpegURL"
env.response.headers.add("Access-Control-Allow-Origin", "*")
@ -226,7 +241,7 @@ module Invidious::Routes::API::Manifest
manifest = response.body
if local
manifest = manifest.gsub("https://www.youtube.com", HOST_URL)
manifest = manifest.gsub("https://www.youtube.com", proxy_url)
manifest = manifest.gsub("index.m3u8", "index.m3u8?local=true")
end

View File

@ -262,6 +262,11 @@ module Invidious::Routes::VideoPlayback
region = env.params.query["region"]?
local = (env.params.query["local"]? == "true")
proxy_url = HOST_URL
if CONFIG.proxy_domains.size > 0 && local
proxy_url = ("https:///" + CONFIG.proxy_domains.[Random.rand(CONFIG.proxy_domains.size)])
end
title = env.params.query["title"]?
@ -285,7 +290,7 @@ module Invidious::Routes::VideoPlayback
end
if local
url = URI.parse(url).request_target.not_nil!
url = proxy_url + URI.parse(url).request_target.not_nil!
url += "&title=#{URI.encode_www_form(title, space_to_plus: false)}" if title
end

View File

@ -129,8 +129,14 @@ module Invidious::Routes::Watch
adaptive_fmts = video.adaptive_fmts
if params.local
fmt_stream.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) }
adaptive_fmts.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) }
proxy_url = HOST_URL
if CONFIG.proxy_domains.size > 0 && params.local
proxy_url = ("https:///" + CONFIG.proxy_domains.[Random.rand(CONFIG.proxy_domains.size)])
end
fmt_stream.each { |fmt| fmt["url"] = JSON::Any.new(proxy_url + URI.parse(fmt["url"].as_s).request_target) }
adaptive_fmts.each { |fmt| fmt["url"] = JSON::Any.new(proxy_url + URI.parse(fmt["url"].as_s).request_target) }
end
video_streams = video.video_streams