mirror of
https://github.com/mpv-player/mpv
synced 2025-01-22 07:33:14 +00:00
ytdl_hook: resolve relative paths when joining segment urls
FFmpeg/mpv don't do it automatically. See #4827
This commit is contained in:
parent
181b071431
commit
d280b3db93
@ -122,10 +122,30 @@ local function is_blacklisted(url)
|
||||
return false
|
||||
end
|
||||
|
||||
local function make_absolute_url(base_url, url)
|
||||
if url:find("https?://") == 1 then return url end
|
||||
|
||||
local proto, domain, rest =
|
||||
base_url:match("(https?://)([^/]+/)(.*)/?")
|
||||
local segs = {}
|
||||
rest:gsub("([^/]+)", function(c) table.insert(segs, c) end)
|
||||
url:gsub("([^/]+)", function(c) table.insert(segs, c) end)
|
||||
local resolved_url = {}
|
||||
for i, v in ipairs(segs) do
|
||||
if v == ".." then
|
||||
table.remove(resolved_url)
|
||||
elseif v ~= "." then
|
||||
table.insert(resolved_url, v)
|
||||
end
|
||||
end
|
||||
return proto .. domain ..
|
||||
table.concat(resolved_url, "/")
|
||||
end
|
||||
|
||||
local function join_url(base_url, fragment)
|
||||
local res = ""
|
||||
if base_url and fragment.path then
|
||||
res = base_url .. fragment.path
|
||||
res = make_absolute_url(base_url, fragment.path)
|
||||
elseif fragment.url then
|
||||
res = fragment.url
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user