From 0860db73ae6fd9a6f6347219d820bf026a6b8b91 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sun, 27 Sep 2026 17:38:39 +0200 Subject: * MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated-commit-by: dots Signed-off-by: Robert Günzler --- bin/play-mpv | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'bin/play-mpv') diff --git a/bin/play-mpv b/bin/play-mpv index 21f20c6..bb85c02 100755 --- a/bin/play-mpv +++ b/bin/play-mpv @@ -35,15 +35,9 @@ import sys from collections.abc import Iterable from typing import BinaryIO -from itertools import tee def notify(files: Iterable[str]) -> None: - for f in files: - subprocess.Popen([ - 'fyi', - 'play-mpv', - f, - ], start_new_session=True) + for f in files: subprocess.Popen(['fyi', 'play-mpv', f], start_new_session=True) def is_url(filename: str) -> bool: parts = filename.split("://", 1) @@ -67,25 +61,22 @@ def get_socket_path() -> str: "Ensure that one of the following environment variables is set: " "UMPV_SOCKET_DIR, XDG_RUNTIME_DIR, HOME or TMPDIR.") - return os.path.join(base_dir, ".umpv") + sockid = "0" + return os.path.join(base_dir, "umpv-" + os.getenv("SOCKID", sockid)) def send_files_to_mpv(conn: socket.socket | BinaryIO, files: Iterable[str]) -> None: - notify(tee(files)[0]) - try: send = conn.send if isinstance(conn, socket.socket) else conn.write for f in files: f = f.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n") - send(f'raw loadfile "{f}" append-play\n'.encode()) + opt = os.getenv("LOADFILE", "append-play") + send(f'raw loadfile "{f}" {opt}\n'.encode()) except Exception: print("mpv is terminating or the connection was lost.", file=sys.stderr) sys.exit(1) def start_mpv(files: Iterable[str], socket_path: str) -> None: - [files, files_copy] = tee(files, 2) - notify(files_copy) - mpv = "mpv" mpv_command = shlex.split(os.getenv("MPV", mpv)) mpv_command.extend([ @@ -94,13 +85,14 @@ def start_mpv(files: Iterable[str], socket_path: str) -> None: "--", ]) mpv_command.extend(files) - print(mpv_command) - # subprocess.Popen(mpv_command, start_new_session=True) + subprocess.Popen(mpv_command, start_new_session=True) def main() -> None: - files = (os.path.abspath(f) if not is_url(f) else f for f in sys.argv[1:]) + files = list(os.path.abspath(f) if not is_url(f) else f for f in sys.argv[1:]) socket_path = get_socket_path() + os.getenv("NONOTIFY") or notify(files) + try: with socket.socket(socket.AF_UNIX) as sock: sock.connect(socket_path) -- cgit 1.4.1