mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Fix redirect for livestream segments
This commit is contained in:
parent
1277c3d156
commit
5a455ec4f7
1 changed files with 34 additions and 7 deletions
|
@ -4429,7 +4429,6 @@ 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)
|
||||||
|
@ -4449,13 +4448,41 @@ get "/api/manifest/hls_playlist/*" do |env|
|
||||||
manifest = manifest.body
|
manifest = manifest.body
|
||||||
|
|
||||||
if local
|
if local
|
||||||
manifest = manifest.gsub("https://www.youtube.com", host_url)
|
manifest = manifest.gsub(/^https:\/\/r\d---.{11}\.c\.youtube\.com[^\n]*/m) do |match|
|
||||||
manifest = manifest.gsub(/https:\/\/r\d---.{11}\.c\.youtube\.com/, host_url)
|
path = URI.parse(match).path
|
||||||
manifest = manifest.gsub("seg.ts", "seg.ts?local=true")
|
|
||||||
|
path = path.lchop("/videoplayback/")
|
||||||
|
path = path.rchop("/")
|
||||||
|
|
||||||
|
path = path.gsub(/mime\/\w+\/\w+/) do |mimetype|
|
||||||
|
mimetype = mimetype.split("/")
|
||||||
|
mimetype[0] + "/" + mimetype[1] + "%2F" + mimetype[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
fvip = manifest.match(/hls_chunk_host\/r(?<fvip>\d+)---/).not_nil!["fvip"]
|
path = path.split("/")
|
||||||
manifest = manifest.gsub("seg.ts", "seg.ts/fvip/#{fvip}")
|
|
||||||
|
raw_params = {} of String => Array(String)
|
||||||
|
path.each_slice(2) do |pair|
|
||||||
|
key, value = pair
|
||||||
|
value = URI.unescape(value)
|
||||||
|
|
||||||
|
if raw_params[key]?
|
||||||
|
raw_params[key] << value
|
||||||
|
else
|
||||||
|
raw_params[key] = [value]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
raw_params = HTTP::Params.new(raw_params)
|
||||||
|
if fvip = raw_params["hls_chunk_host"].match(/r(?<fvip>\d+)---/)
|
||||||
|
raw_params["fvip"] = fvip["fvip"]
|
||||||
|
end
|
||||||
|
|
||||||
|
raw_params["local"] = "true"
|
||||||
|
|
||||||
|
"#{host_url}/videoplayback?#{raw_params}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
manifest
|
manifest
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue