add load-file even listener for adding to history db
Some checks failed
Luacheck / luacheck (push) Failing after 4s

This commit is contained in:
ksyasuda 2024-09-06 02:43:09 -07:00
parent 7916e3a1bc
commit 89cf199a87
No known key found for this signature in database

View File

@ -29,7 +29,7 @@ local marked_index = nil
local current_video = nil local current_video = nil
local destroyer = nil local destroyer = nil
local timeout local timeout
local debug = false local debug = true
local options = { local options = {
add_to_queue = "ctrl+a", add_to_queue = "ctrl+a",
@ -658,13 +658,18 @@ local function on_track_changed()
YouTubeQueue.update_current_index() YouTubeQueue.update_current_index()
end end
local function on_file_loaded()
if debug then print("Load file event triggered.") end
YouTubeQueue.update_current_index(true)
end
-- Function to be called when the playback-restart event is triggered -- Function to be called when the playback-restart event is triggered
local function on_playback_restart() local function on_playback_restart()
if debug then print("Playback restart event triggered.") end if debug then print("Playback restart event triggered.") end
local playlist_size = mp.get_property_number("playlist-count", 0) local playlist_size = mp.get_property_number("playlist-count", 0)
if current_video ~= nil and playlist_size > 1 then -- if current_video ~= nil and playlist_size > 1 then
YouTubeQueue.update_current_index(true) -- YouTubeQueue.update_current_index()
elseif current_video == nil then if current_video == nil then
local url = mp.get_property("path") local url = mp.get_property("path")
YouTubeQueue.add_to_queue(url) YouTubeQueue.add_to_queue(url)
YouTubeQueue._add_to_history_db(current_video) YouTubeQueue._add_to_history_db(current_video)
@ -707,6 +712,7 @@ mp.add_key_binding(options.remove_from_queue, "delete_video",
mp.register_event("end-file", on_end_file) mp.register_event("end-file", on_end_file)
mp.register_event("track-changed", on_track_changed) mp.register_event("track-changed", on_track_changed)
mp.register_event("playback-restart", on_playback_restart) mp.register_event("playback-restart", on_playback_restart)
mp.register_event("file-loaded", on_file_loaded)
-- keep for backwards compatibility -- keep for backwards compatibility
mp.register_script_message("add_to_queue", YouTubeQueue.add_to_queue) mp.register_script_message("add_to_queue", YouTubeQueue.add_to_queue)