summary refs log tree commit diff
path: root/bin/play-mpv
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2026-09-27 17:38:39 +0200
committerRobert Günzler <r@gnzler.io>2026-09-27 17:38:39 +0200
commit0860db73ae6fd9a6f6347219d820bf026a6b8b91 (patch)
tree11318c3670d1c32c5aa0bf404c22fba3bf63fc53 /bin/play-mpv
parent4e34cbf9673aeaba252e01df554a0d204e83c5e2 (diff)
downloaddotfiles-0860db73ae6fd9a6f6347219d820bf026a6b8b91.tar.gz
Automated-commit-by: dots
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'bin/play-mpv')
-rwxr-xr-xbin/play-mpv26
1 files changed, 9 insertions, 17 deletions
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)