summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorNicolas F <ovdev@fratti.ch>2019-10-12 19:04:24 +0200
committerwm4 <1387750+wm4@users.noreply.github.com>2019-10-13 19:08:46 +0200
commit06765e6ac9b734309150acac6d3e18526738ee4e (patch)
treec3af9a9bed47992cbb578f4d5fe2fc626e525937 /player/lua
parent648d7859300562a99f035e06a0d42245c3c46e23 (diff)
downloadmpv-06765e6ac9b734309150acac6d3e18526738ee4e.tar.bz2
mpv-06765e6ac9b734309150acac6d3e18526738ee4e.tar.xz
ytdl_hook: check youtube-dl version if it breaks
Some failures by youtube-dl prompt the user to submit a bug report. If such a failure occurs, we can compare youtube-dl's version to the current calendar date to see how old it is. We don't make this check on every youtube-dl failure, as failing to extract an URL is quite common, and waiting for a second blocking python interpreter startup for every such case would be a bit unpleasant. Here the assumption is made that any youtube-dl version older than 3 months is probably severely out of date. Users will be warned about this. We also output the trimmed stderr of youtube-dl with msg.error, as this appeared to have been the behaviour of utils.subprocess without stderr capturing. Since this uses mp.command_native now, we'll have to do this ourselves where appropriate.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/ytdl_hook.lua34
1 files changed, 32 insertions, 2 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua
index 6b465dcb9a..86f3fe8f77 100644
--- a/player/lua/ytdl_hook.lua
+++ b/player/lua/ytdl_hook.lua
@@ -30,7 +30,10 @@ local safe_protos = Set {
}
local function exec(args)
- local ret = utils.subprocess({args = args})
+ local ret = mp.command_native({name = "subprocess",
+ args = args,
+ capture_stdout = true,
+ capture_stderr = true})
return ret.status, ret.stdout, ret, ret.killed_by_us
end
@@ -446,6 +449,26 @@ local function add_single_video(json)
mp.set_property_native("file-local-options/stream-lavf-o", stream_opts)
end
+local function check_version(ytdl_path)
+ local command = {
+ name = "subprocess",
+ capture_stdout = true,
+ args = {ytdl_path, "--version"}
+ }
+ local version_string = mp.command_native(command).stdout
+ local year, month, day = string.match(version_string, "(%d+).(%d+).(%d+)")
+
+ -- sanity check
+ if (tonumber(year) < 2000) or (tonumber(month) > 12) or
+ (tonumber(day) > 31) then
+ return
+ end
+ local version_ts = os.time{year=year, month=month, day=day}
+ if (os.difftime(os.time(), version_ts) > 60*60*24*90) then
+ msg.warn("It appears that your youtube-dl version is severely out of date.")
+ end
+end
+
function run_ytdl_hook(url)
local start_time = os.clock()
@@ -521,8 +544,11 @@ function run_ytdl_hook(url)
end
if (es < 0) or (json == nil) or (json == "") 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 and result.error == "init" then
+ if result.error_string and result.error_string == "init" then
err = err .. "not found or not enough permissions"
elseif not result.killed_by_us then
err = err .. "unexpected error ocurred"
@@ -530,6 +556,9 @@ function run_ytdl_hook(url)
err = string.format("%s returned '%d'", err, es)
end
msg.error(err)
+ if string.find(ytdl_err, "yt%-dl%.org/bug") then
+ check_version(ytdl.path)
+ end
return
end
@@ -537,6 +566,7 @@ function run_ytdl_hook(url)
if (json == nil) then
msg.error("failed to parse JSON data: " .. err)
+ check_version(ytdl.path)
return
end