1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 00:42:57 +00:00

ytdl_hook.lua: allow changing try_ytdl_first during runtime

Check value in hook instead of hooking conditionally.
This commit is contained in:
Kacper Michajłow 2024-06-21 17:40:36 +02:00
parent 00f43e0916
commit acbd537dac

View File

@ -1153,18 +1153,22 @@ local function run_ytdl_hook(url)
msg.debug('script running time: '..os.clock()-start_time..' seconds')
end
if not o.try_ytdl_first then
mp.add_hook("on_load", 10, function ()
msg.verbose('ytdl:// hook')
local url = mp.get_property("stream-open-filename", "")
if url:find("ytdl://") ~= 1 then
msg.verbose('not a ytdl:// url')
return
end
run_ytdl_hook(url)
end)
local function on_load_hook(load_fail)
local url = mp.get_property("stream-open-filename", "")
local force = url:find("^ytdl://")
local early = force or o.try_ytdl_first
if early and load_fail then
return
end
if not force and (not url:find("^https?://") or is_blacklisted(url)) then
return
end
run_ytdl_hook(url)
end
mp.add_hook("on_load", 10, function() on_load_hook() end)
mp.add_hook("on_load_fail", 10, function() on_load_hook(true) end)
mp.add_hook("on_load", 20, function ()
msg.verbose('playlist hook')
local url = mp.get_property("stream-open-filename", "")
@ -1173,16 +1177,6 @@ mp.add_hook("on_load", 20, function ()
end
end)
mp.add_hook(o.try_ytdl_first and "on_load" or "on_load_fail", 10, function()
msg.verbose('full hook')
local url = mp.get_property("stream-open-filename", "")
if url:find("ytdl://") ~= 1 and
not ((url:find("https?://") == 1) and not is_blacklisted(url)) then
return
end
run_ytdl_hook(url)
end)
mp.add_hook("on_preloaded", 10, function ()
if next(chapter_list) ~= nil then
msg.verbose("Setting chapters")