Skip to content

Commit 74f215a

Browse files
authored
ytdl_hook.lua: trim preceding text before JSON
There might be additional text in the output before the JSON payload if certain options like `--list-format` are specified in the config.
1 parent 764da99 commit 74f215a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

player/lua/ytdl_hook.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,16 @@ local function run_ytdl_hook(url)
10061006
if result.status ~= 0 or json == "" then
10071007
json = nil
10081008
elseif json then
1009+
-- trim any preceding text before JSON
1010+
local start = string.find(json, "{", 1, true)
1011+
if start ~= 1 then
1012+
if start == nil then
1013+
msg.error("youtube-dl failed: couldn't find JSON data")
1014+
return
1015+
end
1016+
json = string.sub(json, start)
1017+
end
1018+
10091019
json, parse_err = utils.parse_json(json)
10101020
end
10111021

0 commit comments

Comments
 (0)