[download]

config/mpv/scripts/autosave.lua

   1 -- autosave.lua
   2 --
   3 -- Periodically saves "watch later" data during playback, rather than only saving on quit.
   4 -- This lets you easily recover your position in the case of an ungraceful shutdown of mpv (crash, power failure, etc.).
   5 --
   6 -- You can configure the save period by creating a "lua-settings" directory inside your mpv configuration directory.
   7 -- Inside the "lua-settings" directory, create a file named "autosave.conf".
   8 -- The save period can be set like so:
   9 --
  10 -- save_period=60
  11 --
  12 -- This will set the save period to once every 60 seconds of playback, time while paused is not counted towards the save period timer.
  13 -- The default save period is 30 seconds.
  14 local options = require 'mp.options'
  15 
  16 local o = {
  17 	save_period = 30
  18 }
  19 
  20 options.read_options(o)
  21 
  22 local mp = require 'mp'
  23 
  24 local function save()
  25 	mp.command("write-watch-later-config")
  26 end
  27 
  28 local save_period_timer = mp.add_periodic_timer(o.save_period, save)
  29 
  30 local function pause(name, paused)
  31 	if paused then
  32 		save_period_timer:stop()
  33 	else
  34 		save_period_timer:resume()
  35 	end
  36 end
  37 
  38 mp.observe_property("pause", "bool", pause)