-
-
Save gwarser/c6cd1f2f9e3ed98883db8a9bd2227d13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- autosave.lua | |
-- | |
-- 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 = 60, | |
skip_first = 600 | |
} | |
options.read_options(o) | |
local mp = require 'mp' | |
local function save() | |
if mp.get_property_number("time-pos", 0) > o.skip_first then | |
mp.command("write-watch-later-config") | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment