diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2022-10-03 21:42:20 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2022-10-03 21:42:20 +0530 |
commit | af120ab348f2e1a5a39dec035ed9dcf84189a64e (patch) | |
tree | 2a3aadd7ce1b7b771dfe3fe7c983569726c8d7ed /mpv | |
download | dotfiles-af120ab348f2e1a5a39dec035ed9dcf84189a64e.tar.gz dotfiles-af120ab348f2e1a5a39dec035ed9dcf84189a64e.tar.bz2 dotfiles-af120ab348f2e1a5a39dec035ed9dcf84189a64e.zip |
dotfiles
Diffstat (limited to 'mpv')
-rw-r--r-- | mpv/input.conf | 5 | ||||
-rw-r--r-- | mpv/mpv.conf | 2 | ||||
-rw-r--r-- | mpv/script_modules/mpvSockets/LICENSE | 21 | ||||
-rw-r--r-- | mpv/script_modules/mpvSockets/README.md | 76 | ||||
-rw-r--r-- | mpv/script_modules/mpvSockets/mpvSockets.lua | 36 | ||||
-rw-r--r-- | mpv/scripts/modules.lua | 3 |
6 files changed, 143 insertions, 0 deletions
diff --git a/mpv/input.conf b/mpv/input.conf new file mode 100644 index 0000000..d614b15 --- /dev/null +++ b/mpv/input.conf @@ -0,0 +1,5 @@ +l seek 5 +h seek -5 +j seek -60 +k seek 60 +S cycle sub diff --git a/mpv/mpv.conf b/mpv/mpv.conf new file mode 100644 index 0000000..43fb7e2 --- /dev/null +++ b/mpv/mpv.conf @@ -0,0 +1,2 @@ +no-osc +script-opts=ytdl_hook-ytdl_path=/usr/bin/yt-dlp diff --git a/mpv/script_modules/mpvSockets/LICENSE b/mpv/script_modules/mpvSockets/LICENSE new file mode 100644 index 0000000..c5551bb --- /dev/null +++ b/mpv/script_modules/mpvSockets/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Wis + +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/mpv/script_modules/mpvSockets/README.md b/mpv/script_modules/mpvSockets/README.md new file mode 100644 index 0000000..9d3e1fb --- /dev/null +++ b/mpv/script_modules/mpvSockets/README.md @@ -0,0 +1,76 @@ +# mpvSockets +create one sockets per mpv instance (with the instance's process **ID** (PID), (**unique**)), instead of one socket for the last started instance + +dangling sockets for crashed or killed instances is an issue, +not sure if this script should handle/remove them or the clients/users, or both. + +# Installation +Download the single script file to your mpv-scripts-directory +## Linux / unixes: +``` bash +curl "https://raw.githubusercontent.com/wis/mpvSockets/master/mpvSockets.lua" --create-dirs -o "$Your_Mpv_Scripts_Directory_Location/mpvSockets.lua" +``` +if you're on Linux, most likely the location is `~/.config/mpv/scripts`, so run this before: +``` bash +$Your_Mpv_Scripts_Directory_Location=$HOME/config/mpv/scripts +``` +## Windows (untested) +powershell: +``` powershell +Invoke-WebRequest -OutFile "$env:LOCALAPPDATA\mpv\scripts\mpvSockets.lua" "https://raw.githubusercontent.com/wis/mpvSockets/master/mpvSockets.lua" +``` + +# Usage, with Mpv's [JSON IPC](https://github.com/mpv-player/mpv/blob/master/DOCS/man/ipc.rst) +## Linux / unixes (unix sockets): +a script that pauses all running mpv instances: +bash: +``` bash +#!/bin/bash +for i in $(ls /tmp/mpvSockets/*); do + echo '{ "command": ["set_property", "pause", true] }' | socat - "$i"; +done +# Socat is a command line based utility that establishes two bidirec-tional byte streams and transfers data between them. +# available on Linux and FreeBSD, propably most unixes. you can also use +``` + +## Windows (named pipes): +quote from https://mpv.io/manual/stable/#command-prompt-example +> Unfortunately, it's not as easy to test the IPC protocol on Windows, since Windows ports of socat (in Cygwin and MSYS2) don't understand named pipes. In the absence of a simple tool to send and receive from bidirectional pipes, the echo command can be used to send commands, but not receive replies from the command prompt. +> +> Assuming mpv was started with: +> +> `mpv file.mkv --input-ipc-server=\\.\pipe\mpvsocket` +> You can send commands from a command prompt: +> +> `echo show-text ${playback-time} >\\.\pipe\mpvsocket` +To be able to simultaneously read and write from the IPC pipe, like on Linux, it's necessary to write an external program that uses overlapped file I/O (or some wrapper like .NET's NamedPipeClientStream.) + +powershell client writer and reader (untested): +``` powershell +# socat.ps1 +# usage: socat.ps1 <Pipe-name> <Message> +$sockedName = args[0] +$message = args[1] + +$npipeClient = new-object System.IO.Pipes.NamedPipeClientStream('.', $socketName, [System.IO.Pipes.PipeDirection]::InOut, [System.IO.Pipes.PipeOptions]::None, [System.Security.Principal.TokenImpersonationLevel]::Impersonation) + +$pipeReader = $pipeWriter = $null +try { + $npipeClient.Connect() + $pipeReader = new-object System.IO.StreamReader($npipeClient) + $pipeWriter = new-object System.IO.StreamWriter($npipeClient) + $pipeWriter.AutoFlush = $true + + $pipeWriter.WriteLine($message) + + while (($data = $pipeReader.ReadLine()) -ne $null) { + $data + } +} +catch { + "An error occurred that could not be resolved." +} +finally { + $npipeClient.Dispose() +} +```
\ No newline at end of file diff --git a/mpv/script_modules/mpvSockets/mpvSockets.lua b/mpv/script_modules/mpvSockets/mpvSockets.lua new file mode 100644 index 0000000..df8d078 --- /dev/null +++ b/mpv/script_modules/mpvSockets/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) diff --git a/mpv/scripts/modules.lua b/mpv/scripts/modules.lua new file mode 100644 index 0000000..703f372 --- /dev/null +++ b/mpv/scripts/modules.lua @@ -0,0 +1,3 @@ +local mpv_config_dir_path = require("mp").command_native({"expand-path", "~~/"}) +function load(relative_path) dofile(mpv_config_dir_path .. "/script_modules/" .. relative_path) end +load("mpvSockets/mpvSockets.lua") |