From 10c4b7530a953a8a2fccdeeda7b6d84d72ac3b61 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Wed, 19 Jan 2022 23:12:43 +0100 Subject: Add mpv config --- .config/mpv/script_modules/mpvSockets.lua | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .config/mpv/script_modules/mpvSockets.lua (limited to '.config/mpv/script_modules') diff --git a/.config/mpv/script_modules/mpvSockets.lua b/.config/mpv/script_modules/mpvSockets.lua new file mode 100644 index 0000000..df8d078 --- /dev/null +++ b/.config/mpv/script_modules/mpvSockets.lua @@ -0,0 +1,36 @@ +-- mpvSockets, one socket per instance, removes socket on exit + +local utils = require 'mp.utils' + +local function get_temp_path() + local directory_seperator = package.config:match("([^\n]*)\n?") + local example_temp_file_path = os.tmpname() + + -- remove generated temp file + pcall(os.remove, example_temp_file_path) + + local seperator_idx = example_temp_file_path:reverse():find(directory_seperator) + local temp_path_length = #example_temp_file_path - seperator_idx + + return example_temp_file_path:sub(1, temp_path_length) +end + +tempDir = get_temp_path() + +function join_paths(...) + local arg={...} + path = "" + for i,v in ipairs(arg) do + path = utils.join_path(path, tostring(v)) + end + return path; +end + +ppid = utils.getpid() +os.execute("mkdir " .. join_paths(tempDir, "mpvSockets") .. " 2>/dev/null") +mp.set_property("options/input-ipc-server", join_paths(tempDir, "mpvSockets", ppid)) + +function shutdown_handler() + os.remove(join_paths(tempDir, "mpvSockets", ppid)) +end +mp.register_event("shutdown", shutdown_handler) -- cgit v1.2.3-70-g09d2