-
-
Save datsfilipe/dba1921b8f7ed0393b98af6eebba3c9c to your computer and use it in GitHub Desktop.
It's a fork from a fork. The intent is to don't save the state while playing mp3 audio files.
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 script | |
-- Fork from: https://gist.github.com/CyberShadow/2f71a97fb85ed42146f6d9f522bc34ef | |
local options = require 'mp.options' | |
local o = { | |
save_period = 60 | |
} | |
options.read_options(o) | |
local mp = require 'mp' | |
local function save() | |
local filename = mp.get_property("filename") | |
-- Just save if there is a filename and it doesn't finish with .mp3 | |
if filename and not filename:match(".mp3$") then | |
mp.commandv("set", "msg-level", "cplayer=warn") | |
mp.command("write-watch-later-config") | |
mp.commandv("set", "msg-level", "cplayer=status") | |
end | |
end | |
local save_period_timer = mp.add_periodic_timer(o.save_period, save) | |
local function pause(name, paused) | |
save() | |
if paused then | |
save_period_timer:stop() | |
else | |
save_period_timer:resume() | |
end | |
end | |
mp.observe_property("pause", "bool", pause) | |
mp.register_event("file-loaded", save) | |
local function end_file(data) | |
if data.reason == 'eof' or data.reason == 'stop' then | |
local playlist = mp.get_property_native('playlist') | |
for i, entry in pairs(playlist) do | |
if entry.id == data.playlist_entry_id then | |
mp.commandv("delete-watch-later-config", entry.filename) | |
return | |
end | |
end | |
end | |
end | |
mp.register_event("end-file", end_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment