mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-30 02:32:56 +05:30
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
|
manifest
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: Fix redirect for local streams
|
||||||
get "/api/manifest/hls_playlist/*" do |env|
|
get "/api/manifest/hls_playlist/*" do |env|
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
manifest = client.get(env.request.path)
|
manifest = client.get(env.request.path)
|
||||||
@ -4641,6 +4642,34 @@ get "/videoplayback" do |env|
|
|||||||
next
|
next
|
||||||
end
|
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
|
content_length = nil
|
||||||
first_chunk = true
|
first_chunk = true
|
||||||
range_start, range_end = parse_range(env.request.headers["Range"]?)
|
range_start, range_end = parse_range(env.request.headers["Range"]?)
|
||||||
@ -4666,8 +4695,9 @@ get "/videoplayback" do |env|
|
|||||||
end
|
end
|
||||||
|
|
||||||
headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}"
|
headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}"
|
||||||
client = make_client(URI.parse(host), region)
|
|
||||||
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
|
||||||
@ -4714,11 +4744,6 @@ get "/videoplayback" do |env|
|
|||||||
|
|
||||||
proxy_file(response, env)
|
proxy_file(response, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
# For livestream segments, break after first chunk
|
|
||||||
if url.includes? "&file=seg.ts"
|
|
||||||
break
|
|
||||||
end
|
|
||||||
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
|
||||||
@ -4729,6 +4754,7 @@ get "/videoplayback" do |env|
|
|||||||
chunk_end += HTTP_CHUNK_SIZE
|
chunk_end += HTTP_CHUNK_SIZE
|
||||||
first_chunk = false
|
first_chunk = false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# We need this so the below route works as expected
|
# We need this so the below route works as expected
|
||||||
|
Loading…
Reference in New Issue
Block a user