From d280b3db930eadb49646eac2b523adee5ced58a3 Mon Sep 17 00:00:00 2001 From: Ricardo Constantino Date: Sun, 3 Sep 2017 12:11:49 +0100 Subject: ytdl_hook: resolve relative paths when joining segment urls FFmpeg/mpv don't do it automatically. See #4827 --- player/lua/ytdl_hook.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'player/lua/ytdl_hook.lua') diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 9a95657d5b..82679a2aa8 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -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 -- cgit v1.2.3