summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorRetusthese <84878539+Retusthese@users.noreply.github.com>2021-05-27 15:25:48 -0400
committeravih <avih@users.noreply.github.com>2021-05-29 19:54:03 +0300
commitfd8c673cfc1ee51f0bb05c8247a35d44003366da (patch)
tree9d637f9d82a9194cd3f956762c1de5065a955888 /player/lua
parentd7f3d1fff75a07bef91eef0edb9ae7db6d590637 (diff)
downloadmpv-fd8c673cfc1ee51f0bb05c8247a35d44003366da.tar.bz2
mpv-fd8c673cfc1ee51f0bb05c8247a35d44003366da.tar.xz
ytdl_hook: improve handling of json parsing errors
This moves the JSON parsing above the main youtube-dl error-handling block and integrates parsing errors into that block. Now, if a parsing error occurs, youtube-dl's stderr will be logged as it is with other errors. This also catches errors that cause youtube-dl to output "null", which would previously be mishandled as a parsing error and crash ytdl_hook when it attempted to concatenate the error string from parse_json.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/ytdl_hook.lua22
1 files changed, 12 insertions, 10 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua
index 2c728455b8..b9cb04645e 100644
--- a/player/lua/ytdl_hook.lua
+++ b/player/lua/ytdl_hook.lua
@@ -793,33 +793,35 @@ function run_ytdl_hook(url)
return
end
- if (es < 0) or (json == nil) or (json == "") then
+ local parse_err = nil
+
+ if (es < 0) or (json == "") then
+ json = nil
+ elseif json then
+ json, parse_err = utils.parse_json(json)
+ end
+
+ if (json == nil) then
-- trim our stderr to avoid spurious newlines
ytdl_err = result.stderr:gsub("^%s*(.-)%s*$", "%1")
msg.error(ytdl_err)
local err = "youtube-dl failed: "
if result.error_string and result.error_string == "init" then
err = err .. "not found or not enough permissions"
+ elseif parse_err then
+ err = err .. "failed to parse JSON data: " .. parse_err
elseif not result.killed_by_us then
err = err .. "unexpected error occurred"
else
err = string.format("%s returned '%d'", err, es)
end
msg.error(err)
- if string.find(ytdl_err, "yt%-dl%.org/bug") then
+ if parse_err or string.find(ytdl_err, "yt%-dl%.org/bug") then
check_version(ytdl.path)
end
return
end
- local json, err = utils.parse_json(json)
-
- if (json == nil) then
- msg.error("failed to parse JSON data: " .. err)
- check_version(ytdl.path)
- return
- end
-
msg.verbose("youtube-dl succeeded!")
msg.debug('ytdl parsing took '..os.clock()-start_time..' seconds')