aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mpv
diff options
context:
space:
mode:
Diffstat (limited to 'mpv')
-rwxr-xr-xmpv/.config/mpv/mpv.conf2
-rw-r--r--mpv/.config/mpv/scripts/autosave.lua87
-rw-r--r--mpv/.config/mpv/scripts/twitch_chat/chat.lua2
-rw-r--r--mpv/.config/mpv/scripts/twitch_chat/main.lua1
4 files changed, 92 insertions, 0 deletions
diff --git a/mpv/.config/mpv/mpv.conf b/mpv/.config/mpv/mpv.conf
index 1e7f1b9..ceff2a1 100755
--- a/mpv/.config/mpv/mpv.conf
+++ b/mpv/.config/mpv/mpv.conf
@@ -23,6 +23,7 @@ slang=eng,en,enUS,en-US
# Playback
script-opts=ytdl_hook-try_ytdl_first=yes
save-position-on-quit=yes
+write-filename-in-watch-later-config=yes
# Caching
cache=yes
@@ -34,5 +35,6 @@ profile-desc=Enable better performance for streaming live video
profile-cond=p.path:match("twitch.tv/") ~= nil or get("media-title", ""):match("twitch.tv/") ~= nil or filename:match("[.]m3u8$") ~= nil
demuxer-max-bytes=8192k
save-position-on-quit=no
+write-filename-in-watch-later-config=no
resume-playback=no
taskbar-progress=no
diff --git a/mpv/.config/mpv/scripts/autosave.lua b/mpv/.config/mpv/scripts/autosave.lua
new file mode 100644
index 0000000..8f09015
--- /dev/null
+++ b/mpv/.config/mpv/scripts/autosave.lua
@@ -0,0 +1,87 @@
+local mp = require("mp")
+local utils = require("mp.utils")
+
+local function init()
+ if not mp.get_property_bool("save-position-on-quit", true) then
+ return
+ end
+
+ local o = {
+ save_period = 60,
+ }
+
+ require("mp.options").read_options(o)
+
+ local state_dir = utils.join_path((os.getenv("XDG_STATE_HOME") or "~/.local/state/"), "mpv/watch_later")
+ local filename, title, path
+
+ local function append_title()
+ if not filename or not title then
+ return
+ end
+
+ local proc = io.popen("printf '%s' '" .. path .. "' | /bin/md5sum -", "r")
+ if not proc then
+ return
+ end
+
+ local output = proc:read("*a")
+ proc:close()
+
+ if not output then
+ return
+ end
+
+ local hash = output:gsub("[\n\r ]", ""):gsub("-", "")
+ local file_path = utils.join_path(state_dir, string.upper(hash))
+
+ local file, err = io.open(file_path, "a+")
+ if file and not err then
+ file:write(string.format("# title: %s\n", title))
+ file:close()
+ end
+ end
+
+ local function save()
+ mp.command("write-watch-later-config")
+
+ filename = mp.get_property_native("filename")
+ title = mp.get_property_native("media-title")
+ path = mp.get_property_native("path")
+
+ if title and path then
+ append_title()
+ end
+ end
+
+ local save_period_timer = mp.add_periodic_timer(o.save_period, save)
+
+ local function pause(_, paused)
+ if paused then
+ save()
+ save_period_timer:kill()
+ else
+ save_period_timer:resume()
+ end
+ end
+
+ local function on_end_file(data)
+ mp.command("write-watch-later-config")
+ append_title()
+ if data.reason == "eof" or data.reason == "stop" then
+ local playlist = mp.get_property_native("playlist")
+ for _, 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.observe_property("pause", "bool", pause)
+ mp.register_event("end-file", on_end_file)
+ save()
+end
+
+mp.register_event("file-loaded", init)
diff --git a/mpv/.config/mpv/scripts/twitch_chat/chat.lua b/mpv/.config/mpv/scripts/twitch_chat/chat.lua
index bab6def..fa3c783 100644
--- a/mpv/.config/mpv/scripts/twitch_chat/chat.lua
+++ b/mpv/.config/mpv/scripts/twitch_chat/chat.lua
@@ -1,3 +1,5 @@
+local mp = require("mp")
+
---@class twitch.Chat
---@field cwd string
---@field channel string
diff --git a/mpv/.config/mpv/scripts/twitch_chat/main.lua b/mpv/.config/mpv/scripts/twitch_chat/main.lua
index 77b2271..b79838f 100644
--- a/mpv/.config/mpv/scripts/twitch_chat/main.lua
+++ b/mpv/.config/mpv/scripts/twitch_chat/main.lua
@@ -1,3 +1,4 @@
+local mp = require("mp")
local Chat = require("chat")
local msg = require("mp.msg")