Skip to content

Commit 908efea

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 908efea

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

player/lua/ytdl_hook.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,15 @@ 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 = json:find("{", 1, true)
1011+
if start == nil then
1012+
msg.error("youtube-dl failed: couldn't find JSON data")
1013+
return
1014+
elseif start > 1 then
1015+
json = json:sub(start)
1016+
end
1017+
10091018
json, parse_err = utils.parse_json(json)
10101019
end
10111020

0 commit comments

Comments
 (0)