Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- 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 = 30
}
options.read_options(o)
local mp = require 'mp'
local function save()
mp.command("write-watch-later-config")
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)
@gwarser

This comment has been minimized.

gwarser commented Oct 30, 2017

My watch-later config file is not cleaned on the end of movie, when player window is not active.
Often happens for music videos.

@Hakkin

This comment has been minimized.

Owner

Hakkin commented Nov 1, 2017

@gwarser Unfortunately there's no way to delete watch-later data from user scripts as far as I know, only save it. A "work around" is to re-open the movie (mpv removes the watch-later data when you open the file), then ctrl+c out of mpv, which should exit without re-creating the watch later data.
It might be worth opening an issue to request a way to remove the watch-later data programmatically.

@TheAMM

This comment has been minimized.

TheAMM commented Dec 31, 2017

You can (ab)use the undocumented mp.find_config_file() to get paths to files near or about the mpv executable or config directories. Here's how mp.options uses it - if you replicate the MD5sum process for generating the watch-later filename, you can find_config_file it and remove it (or, if lazy, clear all files in the watch_later directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment