forked from midou/invidious
Fix chunk size for livestreams
This commit is contained in:
parent
8033d1ca6d
commit
1277c3d156
@ -4429,6 +4429,7 @@ get "/api/manifest/hls_variant/*" do |env|
|
||||
manifest
|
||||
end
|
||||
|
||||
# TODO: Fix redirect for local streams
|
||||
get "/api/manifest/hls_playlist/*" do |env|
|
||||
client = make_client(YT_URL)
|
||||
manifest = client.get(env.request.path)
|
||||
@ -4641,6 +4642,34 @@ get "/videoplayback" do |env|
|
||||
next
|
||||
end
|
||||
|
||||
if url.includes? "&file=seg.ts"
|
||||
begin
|
||||
client = make_client(URI.parse(host), region)
|
||||
client.get(url, headers) do |response|
|
||||
response.headers.each do |key, value|
|
||||
if !RESPONSE_HEADERS_BLACKLIST.includes?(key)
|
||||
env.response.headers[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
||||
|
||||
if location = response.headers["Location"]?
|
||||
location = URI.parse(location)
|
||||
location = "#{location.full_path}&host=#{location.host}"
|
||||
|
||||
if region
|
||||
location += "®ion=#{region}"
|
||||
end
|
||||
|
||||
next env.redirect location
|
||||
end
|
||||
|
||||
IO.copy(response.body_io, env.response)
|
||||
end
|
||||
rescue ex
|
||||
end
|
||||
else
|
||||
content_length = nil
|
||||
first_chunk = true
|
||||
range_start, range_end = parse_range(env.request.headers["Range"]?)
|
||||
@ -4666,8 +4695,9 @@ get "/videoplayback" do |env|
|
||||
end
|
||||
|
||||
headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}"
|
||||
client = make_client(URI.parse(host), region)
|
||||
|
||||
begin
|
||||
client = make_client(URI.parse(host), region)
|
||||
client.get(url, headers) do |response|
|
||||
if first_chunk
|
||||
if !env.request.headers["Range"]? && response.status_code == 206
|
||||
@ -4714,11 +4744,6 @@ get "/videoplayback" do |env|
|
||||
|
||||
proxy_file(response, env)
|
||||
end
|
||||
|
||||
# For livestream segments, break after first chunk
|
||||
if url.includes? "&file=seg.ts"
|
||||
break
|
||||
end
|
||||
rescue ex
|
||||
if ex.message != "Error reading socket: Connection reset by peer"
|
||||
break
|
||||
@ -4730,6 +4755,7 @@ get "/videoplayback" do |env|
|
||||
first_chunk = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# We need this so the below route works as expected
|
||||
get "/ggpht*" do |env|
|
||||
|
Loading…
Reference in New Issue
Block a user