diff options
author | Tharre <tharre3@gmail.com> | 2018-02-06 17:32:11 +0100 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2018-02-06 17:32:11 +0100 |
commit | edab612bd41ab2fdfb123cb8030b77c372a81dc6 (patch) | |
tree | 3f6c05ae1a03b21d4079873324cb291faf67d33a /.config | |
parent | 8e8dcd216116793f51c08e31be0fe4cb6002c204 (diff) | |
download | dotfiles-edab612bd41ab2fdfb123cb8030b77c372a81dc6.tar.gz dotfiles-edab612bd41ab2fdfb123cb8030b77c372a81dc6.tar.xz dotfiles-edab612bd41ab2fdfb123cb8030b77c372a81dc6.zip |
mpv: add autosave.lua (resume-playback)
Diffstat (limited to '.config')
-rw-r--r-- | .config/mpv/scripts/autosave.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/.config/mpv/scripts/autosave.lua b/.config/mpv/scripts/autosave.lua new file mode 100644 index 0000000..60609b2 --- /dev/null +++ b/.config/mpv/scripts/autosave.lua @@ -0,0 +1,45 @@ +-- autosave.lua +-- based on https://gist.github.com/Hakkin/5489e511bd6c8068a0fc09304c9c5a82 +-- +-- Periodically saves "watch later" data during playback, rather than only saving on quit. +-- This lets you easily recover your position in the case of an ungraceful shutdown of mpv (crash, power failure, etc.). +-- +-- You can configure the save period by creating a "lua-settings" directory inside your mpv configuration directory. +-- Inside the "lua-settings" directory, create a file named "autosave.conf". +-- The save period can be set like so: +-- +-- save_period=60 +-- +-- This will set the save period to once every 60 seconds of playback, time while paused is not counted towards the save period timer. +-- The default save period is 30 seconds. +local options = require 'mp.options' + +local o = { + save_period = 30 +} + +options.read_options(o) + +local mp = require 'mp' + +local function save() + if mp.get_property_bool("resume-playback") then + -- ugly hack to avoid the "Saving state." spam + local savelog = mp.get_property("msg-level") + mp.set_property("msg-level", "cplayer=warn") + mp.command("write-watch-later-config") + mp.set_property("msg-level", savelog) + end +end + +local save_period_timer = mp.add_periodic_timer(o.save_period, save) + +local function pause(name, paused) + if paused then + save_period_timer:stop() + else + save_period_timer:resume() + end +end + +mp.observe_property("pause", "bool", pause) |