mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-19 04:34:23 -05:00
Handle redirects in /videoplayback
This commit is contained in:
parent
0f49d424d3
commit
45ad212459
@ -4840,6 +4840,42 @@ get "/videoplayback" do |env|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
client = make_client(URI.parse(host), region)
|
||||||
|
|
||||||
|
response = HTTP::Client::Response.new(403)
|
||||||
|
5.times do
|
||||||
|
begin
|
||||||
|
response = client.head(url, headers)
|
||||||
|
|
||||||
|
if response.headers["Location"]?
|
||||||
|
location = URI.parse(response.headers["Location"])
|
||||||
|
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
||||||
|
|
||||||
|
host = "#{location.scheme}://#{location.host}"
|
||||||
|
client = make_client(URI.parse(host), region)
|
||||||
|
|
||||||
|
url = "#{location.full_path}&host=#{location.host}#{region ? "®ion=#{region}" : ""}"
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
rescue Socket::Addrinfo::Error
|
||||||
|
if !mns.empty?
|
||||||
|
mn = mns.pop
|
||||||
|
end
|
||||||
|
fvip = "3"
|
||||||
|
|
||||||
|
host = "https://r#{fvip}---#{mn}.googlevideo.com"
|
||||||
|
client = make_client(URI.parse(host), region)
|
||||||
|
rescue ex
|
||||||
|
pp ex
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if response.status_code >= 400
|
||||||
|
env.response.status_code = response.status_code
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
if url.includes? "&file=seg.ts"
|
if url.includes? "&file=seg.ts"
|
||||||
if CONFIG.disabled?("livestreams")
|
if CONFIG.disabled?("livestreams")
|
||||||
env.response.status_code = 403
|
env.response.status_code = 403
|
||||||
@ -4891,6 +4927,8 @@ get "/videoplayback" do |env|
|
|||||||
chunk_end = chunk_start + HTTP_CHUNK_SIZE - 1
|
chunk_end = chunk_start + HTTP_CHUNK_SIZE - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
client = make_client(URI.parse(host), region)
|
||||||
|
|
||||||
# TODO: Record bytes written so we can restart after a chunk fails
|
# TODO: Record bytes written so we can restart after a chunk fails
|
||||||
while true
|
while true
|
||||||
if !range_end && content_length
|
if !range_end && content_length
|
||||||
@ -4908,7 +4946,6 @@ get "/videoplayback" do |env|
|
|||||||
headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}"
|
headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
client = make_client(URI.parse(host), region)
|
|
||||||
client.get(url, headers) do |response|
|
client.get(url, headers) do |response|
|
||||||
if first_chunk
|
if first_chunk
|
||||||
if !env.request.headers["Range"]? && response.status_code == 206
|
if !env.request.headers["Range"]? && response.status_code == 206
|
||||||
@ -4954,6 +4991,8 @@ get "/videoplayback" do |env|
|
|||||||
rescue ex
|
rescue ex
|
||||||
if ex.message != "Error reading socket: Connection reset by peer"
|
if ex.message != "Error reading socket: Connection reset by peer"
|
||||||
break
|
break
|
||||||
|
else
|
||||||
|
client = make_client(URI.parse(host), region)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user