Added proxiyng for videos with a given list of domains

pull/3658/head
11tuvork28 2 years ago
parent 1c87da7050
commit 10c06ded90

@ -7,6 +7,11 @@ module Invidious::Routes::API::Manifest
local = env.params.query["local"]?.try &.== "true" local = env.params.query["local"]?.try &.== "true"
id = env.params.url["id"] id = env.params.url["id"]
region = env.params.query["region"]? 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, # 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 # 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 if local
uri = URI.parse(url) uri = URI.parse(url)
url = "#{HOST_URL}#{uri.request_target}host/#{uri.host}/" url = "#{proxy_url}#{uri.request_target}host/#{uri.host}/"
end end
"<BaseURL>#{url}</BaseURL>" "<BaseURL>#{url}</BaseURL>"
@ -42,7 +47,7 @@ module Invidious::Routes::API::Manifest
if local if local
adaptive_fmts.each do |fmt| 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
end end
@ -164,6 +169,11 @@ module Invidious::Routes::API::Manifest
end end
local = env.params.query["local"]?.try &.== "true" 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.content_type = "application/x-mpegURL"
env.response.headers.add("Access-Control-Allow-Origin", "*") env.response.headers.add("Access-Control-Allow-Origin", "*")
@ -203,7 +213,7 @@ module Invidious::Routes::API::Manifest
raw_params["local"] = "true" raw_params["local"] = "true"
"#{HOST_URL}/videoplayback?#{raw_params}" "#{proxy_url}/videoplayback?#{raw_params}"
end end
end end
@ -219,6 +229,11 @@ module Invidious::Routes::API::Manifest
end end
local = env.params.query["local"]?.try &.== "true" 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.content_type = "application/x-mpegURL"
env.response.headers.add("Access-Control-Allow-Origin", "*") env.response.headers.add("Access-Control-Allow-Origin", "*")
@ -226,7 +241,7 @@ module Invidious::Routes::API::Manifest
manifest = response.body manifest = response.body
if local 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") manifest = manifest.gsub("index.m3u8", "index.m3u8?local=true")
end end

@ -262,6 +262,11 @@ module Invidious::Routes::VideoPlayback
region = env.params.query["region"]? region = env.params.query["region"]?
local = (env.params.query["local"]? == "true") 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"]? title = env.params.query["title"]?
@ -285,7 +290,7 @@ module Invidious::Routes::VideoPlayback
end end
if local 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 url += "&title=#{URI.encode_www_form(title, space_to_plus: false)}" if title
end end

@ -129,8 +129,14 @@ module Invidious::Routes::Watch
adaptive_fmts = video.adaptive_fmts adaptive_fmts = video.adaptive_fmts
if params.local if params.local
fmt_stream.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) } proxy_url = HOST_URL
adaptive_fmts.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) }
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 end
video_streams = video.video_streams video_streams = video.video_streams

Loading…
Cancel
Save