ytdl_hook: make path and json available to other scripts

It's useful for user scripts to be able to use the same ytdl binary that
ytdl_hook uses without having to replicate ytdl_hook's process of
searching for the ytdl binary.

Some user scripts might also find it useful to be able to access ytdl's
json output that the ytdl_hook already receives, sparing user scripts
from having to make a duplicate ytdl binary invocation to get the json
output.

Providing just the json output is not enough though, as ytdl doesn't communicate
errors though it -- if an error occurs, ytdl provides no json output and instead
prints to stderr. So without stderr, there is no way for user scripts to figure
out why ytdl has failed: no such username / video id, the channel is not live
yet, etc. Because of that, the entire result of the subprocess call is provided
to the user scripts, containing stdout (json), stderr, ytdl's exit code, etc.
This commit is contained in:
Maxim Biro
2024-05-09 10:43:54 -04:00
committed by Kacper Michajłow
parent e3eeaec813
commit ff47926d6a
3 changed files with 22 additions and 0 deletions

View File

@@ -993,12 +993,16 @@ local function run_ytdl_hook(url)
end
ytdl.searched = true
mp.set_property("user-data/mpv/ytdl/path", ytdl.path or "")
end
if result.killed_by_us then
return
end
mp.set_property_native("user-data/mpv/ytdl/json-subprocess-result", result)
local json = result.stdout
local parse_err = nil
@@ -1202,3 +1206,7 @@ mp.add_hook("on_preloaded", 10, function ()
chapter_list = {}
end
end)
mp.add_hook("on_after_end_file", 50, function ()
mp.del_property("user-data/mpv/ytdl/json-subprocess-result")
end)