aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mpv/.config
diff options
context:
space:
mode:
Diffstat (limited to 'mpv/.config')
-rw-r--r--mpv/.config/mpv/input.conf27
-rw-r--r--mpv/.config/mpv/scripts/twitch_chat/.neoconf.json9
-rw-r--r--mpv/.config/mpv/scripts/twitch_chat/chat.lua70
-rw-r--r--mpv/.config/mpv/scripts/twitch_chat/main.lua48
-rw-r--r--mpv/.config/mpv/scripts/twitch_chat/selene.toml1
5 files changed, 143 insertions, 12 deletions
diff --git a/mpv/.config/mpv/input.conf b/mpv/.config/mpv/input.conf
index 72f301b..8f0e958 100644
--- a/mpv/.config/mpv/input.conf
+++ b/mpv/.config/mpv/input.conf
@@ -1,16 +1,19 @@
-WHEEL_UP seek 5
-WHEEL_DOWN seek -5
-Ctrl+l drop-buffers
+WHEEL_UP seek 5
+WHEEL_DOWN seek -5
+Ctrl+l drop-buffers
-Alt+= add video-zoom 0.1
-Alt++ add video-zoom 0.05
-Alt+- add video-zoom -0.1
-Alt+_ add video-zoom -0.05
+Alt+= add video-zoom 0.1
+Alt++ add video-zoom 0.05
+Alt+- add video-zoom -0.1
+Alt+_ add video-zoom -0.05
-Shift+Alt+UP add video-pan-y 0.05
-Shift+Alt+DOWN add video-pan-y -0.05
-Shift+Alt+LEFT add video-pan-x 0.05
+Shift+Alt+UP add video-pan-y 0.05
+Shift+Alt+DOWN add video-pan-y -0.05
+Shift+Alt+LEFT add video-pan-x 0.05
Shift+Alt+RIGHT add video-pan-x -0.05
-UP add volume 5
-DOWN add volume -5
+UP add volume 5
+DOWN add volume -5
+
+MBTN_MID script-binding chat_toggle
+c-c script-binding chat_toggle
diff --git a/mpv/.config/mpv/scripts/twitch_chat/.neoconf.json b/mpv/.config/mpv/scripts/twitch_chat/.neoconf.json
new file mode 100644
index 0000000..4dedf00
--- /dev/null
+++ b/mpv/.config/mpv/scripts/twitch_chat/.neoconf.json
@@ -0,0 +1,9 @@
+{
+ "lspconfig": {
+ "lua_ls": {
+ "Lua.diagnostics.globals": [
+ "mp"
+ ]
+ }
+ }
+}
diff --git a/mpv/.config/mpv/scripts/twitch_chat/chat.lua b/mpv/.config/mpv/scripts/twitch_chat/chat.lua
new file mode 100644
index 0000000..bab6def
--- /dev/null
+++ b/mpv/.config/mpv/scripts/twitch_chat/chat.lua
@@ -0,0 +1,70 @@
+---@class twitch.Chat
+---@field cwd string
+---@field channel string
+---@field process table
+local Chat = {}
+
+---@param channel string
+---@return self
+function Chat:new(channel)
+ if not channel then
+ error("channel name required")
+ end
+
+ self.__index = self
+
+ return setmetatable({
+ channel = channel,
+ process = nil,
+ }, self)
+end
+
+function Chat:register_bindings(bindings)
+ local names = {}
+ for name, callback in pairs(bindings) do
+ mp.add_key_binding(nil, name, function()
+ callback(self)
+ end)
+ table.insert(names, name)
+ end
+ return names
+end
+
+function Chat:open()
+ if self.process then
+ return
+ end
+
+ local opts = {
+ name = "subprocess",
+ capture_stdout = false,
+ playback_only = false,
+ args = {
+ "/usr/bin/chatterino",
+ ("--channels=t:%s"):format(self.channel),
+ },
+ }
+
+ self.process = mp.command_native_async(opts, function()
+ self.process = nil
+ end)
+end
+
+function Chat:close()
+ if not self.process then
+ return
+ end
+
+ mp.abort_async_command(self.process)
+ self.process = nil
+end
+
+function Chat:toggle()
+ if self.process then
+ self:close()
+ else
+ self:open()
+ end
+end
+
+return Chat
diff --git a/mpv/.config/mpv/scripts/twitch_chat/main.lua b/mpv/.config/mpv/scripts/twitch_chat/main.lua
new file mode 100644
index 0000000..77b2271
--- /dev/null
+++ b/mpv/.config/mpv/scripts/twitch_chat/main.lua
@@ -0,0 +1,48 @@
+local Chat = require("chat")
+local msg = require("mp.msg")
+
+---@param chat twitch.Chat
+---@param bindings table<string, fun(self: twitch.Chat)>
+---@return string[] script_bindings list bindable 'script-binding' names
+local function register_bindings(chat, bindings)
+ local names = {}
+ for name, callback in pairs(bindings) do
+ mp.add_key_binding(nil, name, function()
+ callback(chat)
+ end)
+ table.insert(names, name)
+ end
+ return names
+end
+
+local function get_channel()
+ local path = mp.get_property_native("path")
+ if path == "-" then
+ return mp.get_property_native("media-title"):match("twitch.tv/(%S+)")
+ else
+ return path:match("twitch%.tv/([^/]+)$")
+ end
+end
+
+local function setup()
+ local channel = get_channel()
+
+ if not channel then
+ msg.debug("Twitch channel not found")
+ return
+ end
+
+ msg.info(("Found twitch channel: %s"):format(channel))
+
+ local chat = Chat:new(channel)
+
+ local names = register_bindings(chat, {
+ chat_open = Chat.open,
+ chat_close = Chat.close,
+ chat_toggle = Chat.toggle,
+ })
+
+ msg.verbose(("Registering script-bindings: %s"):format(table.concat(names, ", ")))
+end
+
+mp.register_event("start-file", setup)
diff --git a/mpv/.config/mpv/scripts/twitch_chat/selene.toml b/mpv/.config/mpv/scripts/twitch_chat/selene.toml
new file mode 100644
index 0000000..7e68df6
--- /dev/null
+++ b/mpv/.config/mpv/scripts/twitch_chat/selene.toml
@@ -0,0 +1 @@
+std = "mp"