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
1 changed files with 14 additions and 20 deletions

View File

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