SmartHistory.lua code can be refactor by NOT using boilerplate code like mp.add_periodic_timer and pause and end-file event.
Instead, by using on_unload hook.
document:
on_unload
Run before closing a file, and before actually
uninitializing everything.
It's not possible to resume playback in this state.
Ordered BEFORE end-file.
Will also happen in the error case (then after on_load_fail).
sample code:
mp.add_hook('on_unload', 50, function()
local path = mp.get_property('path')
local time = mp.get_property('time-pos')
local historyLog = io.open("mpvHistory.log", 'a+')
historyLog:write(('%s%s\n'):format(path, '#time=' .. tostring(math.floor(time))))
historyLog:close()
end)
SmartHistory.lua
code can be refactor by NOT using boilerplate code likemp.add_periodic_timer
andpause
andend-file
event.Instead, by using
on_unload
hook.document:
sample code:
see https://github.com/mpv-player/mpv/issues/9148 for more details