From 991f329aaf8f22665e59e9cd5068fbd6fe3d571d Mon Sep 17 00:00:00 2001 From: A Farzat Date: Thu, 14 Nov 2024 21:53:57 +0900 Subject: Remove mpv_ prefix from mpv_socket --- .config/mpv/scripts/mpv_socket/LICENSE | 21 ------------- .config/mpv/scripts/mpv_socket/main.lua | 56 --------------------------------- .config/mpv/scripts/socket/LICENSE | 21 +++++++++++++ .config/mpv/scripts/socket/main.lua | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 .config/mpv/scripts/mpv_socket/LICENSE delete mode 100644 .config/mpv/scripts/mpv_socket/main.lua create mode 100644 .config/mpv/scripts/socket/LICENSE create mode 100644 .config/mpv/scripts/socket/main.lua (limited to '.config/mpv') diff --git a/.config/mpv/scripts/mpv_socket/LICENSE b/.config/mpv/scripts/mpv_socket/LICENSE deleted file mode 100644 index db38795..0000000 --- a/.config/mpv/scripts/mpv_socket/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2024 A Farzat - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/.config/mpv/scripts/mpv_socket/main.lua b/.config/mpv/scripts/mpv_socket/main.lua deleted file mode 100644 index cc9da6b..0000000 --- a/.config/mpv/scripts/mpv_socket/main.lua +++ /dev/null @@ -1,56 +0,0 @@ --- mpvSockets, one socket per instance, removes socket on exit - -package.path = mp.command_native({"expand-path", "~~/script-modules/?.lua;"})..package.path -local input = require "user-input-module" -local utils = require 'mp.utils' - -local sock_dir = os.getenv("MPV_SOCKET_DIR") or - utils.join_path(os.getenv("XDG_RUNTIME_DIR"), "mpv/sockets") -mp.command_native({capture_stdout = true, capture_stderr = true, -args = {"mkdir", "-p", sock_dir}, name = "subprocess", playback_only = false}) - -local sock_file = utils.join_path(sock_dir, -mp.get_opt("mpv_socket") or utils.getpid()) - -mp.set_property("options/input-ipc-server", sock_file) - -local function check_active_socket(file_name) - return mp.command_native({ - name = "subprocess", - capture_stdout = true, - capture_stderr = true, - args = {"nc", "-NU", file_name}, - playback_only = false, - stdin_data = '{ "command": ["get_property", "path"] }\n', - }).status == 0 -end - -local function change_sockname() - input.get_user_input(function(line, _) - if line then - local new_sock_file = utils.join_path(sock_dir, line) - if check_active_socket(new_sock_file) then - change_sockname() - else - mp.set_property("options/input-ipc-server", new_sock_file) - end - end - end, { request_text = "set socket name:" }) -end - -mp.add_key_binding("alt+s", "NameIPCSocket", change_sockname) - -local function update_socket_name() - local new_name = mp.get_property("options/input-ipc-server") - if sock_file ~= new_name then - os.remove(sock_file) - end - sock_file = new_name -end - -mp.observe_property("options/input-ipc-server", nil, update_socket_name) - -local function shutdown_handler() - os.remove(mp.get_property("options/input-ipc-server")) -end -mp.register_event("shutdown", shutdown_handler) diff --git a/.config/mpv/scripts/socket/LICENSE b/.config/mpv/scripts/socket/LICENSE new file mode 100644 index 0000000..db38795 --- /dev/null +++ b/.config/mpv/scripts/socket/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 A Farzat + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.config/mpv/scripts/socket/main.lua b/.config/mpv/scripts/socket/main.lua new file mode 100644 index 0000000..0a35eee --- /dev/null +++ b/.config/mpv/scripts/socket/main.lua @@ -0,0 +1,56 @@ +-- mpvSockets, one socket per instance, removes socket on exit + +package.path = mp.command_native({"expand-path", "~~/script-modules/?.lua;"})..package.path +local input = require "user-input-module" +local utils = require 'mp.utils' + +local sock_dir = os.getenv("MPV_SOCKET_DIR") or + utils.join_path(os.getenv("XDG_RUNTIME_DIR"), "mpv/sockets") +mp.command_native({capture_stdout = true, capture_stderr = true, +args = {"mkdir", "-p", sock_dir}, name = "subprocess", playback_only = false}) + +local sock_file = utils.join_path(sock_dir, +mp.get_opt("socket") or utils.getpid()) + +mp.set_property("options/input-ipc-server", sock_file) + +local function check_active_socket(file_name) + return mp.command_native({ + name = "subprocess", + capture_stdout = true, + capture_stderr = true, + args = {"nc", "-NU", file_name}, + playback_only = false, + stdin_data = '{ "command": ["get_property", "path"] }\n', + }).status == 0 +end + +local function change_sockname() + input.get_user_input(function(line, _) + if line then + local new_sock_file = utils.join_path(sock_dir, line) + if check_active_socket(new_sock_file) then + change_sockname() + else + mp.set_property("options/input-ipc-server", new_sock_file) + end + end + end, { request_text = "set socket name:" }) +end + +mp.add_key_binding("alt+s", "NameIPCSocket", change_sockname) + +local function update_socket_name() + local new_name = mp.get_property("options/input-ipc-server") + if sock_file ~= new_name then + os.remove(sock_file) + end + sock_file = new_name +end + +mp.observe_property("options/input-ipc-server", nil, update_socket_name) + +local function shutdown_handler() + os.remove(mp.get_property("options/input-ipc-server")) +end +mp.register_event("shutdown", shutdown_handler) -- cgit v1.2.3-70-g09d2