Eisa01 / mpv-scripts

This repository contain scripts I have made for mpv media player...
BSD 2-Clause "Simplified" License
507 stars 35 forks source link

FYI: the played video time could get from `on_unload` hook #19

Closed snowman closed 2 years ago

snowman commented 2 years ago

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)

see https://github.com/mpv-player/mpv/issues/9148 for more details