umpv: Update to work with new mpv version
Moved umpv script to updated version available here:
eeb711f5f3/TOOLS/umpv
Switches deprecated `--input-file` argument for `--input-ipc-server`,
making use of socket instead of FIFO file ---
though it should work the same in practice.
This commit is contained in:
parent
06e67213ac
commit
429d0ec687
1 changed files with 17 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This script emulates "unique application" functionality on Linux. When starting
|
This script emulates "unique application" functionality on Linux. When starting
|
||||||
|
@ -19,10 +19,6 @@ will typically just fill ~/.xsession-errors with garbage.
|
||||||
mpv will terminate if there are no more files to play, and running the umpv
|
mpv will terminate if there are no more files to play, and running the umpv
|
||||||
script after that will start a new mpv instance.
|
script after that will start a new mpv instance.
|
||||||
|
|
||||||
Note that you can control the mpv instance by writing to the command fifo:
|
|
||||||
|
|
||||||
echo "cycle fullscreen" > ~/.umpv_fifo
|
|
||||||
|
|
||||||
Note: you can supply custom mpv path and options with the MPV environment
|
Note: you can supply custom mpv path and options with the MPV environment
|
||||||
variable. The environment variable will be split on whitespace, and the
|
variable. The environment variable will be split on whitespace, and the
|
||||||
first item is used as path to mpv binary and the rest is passed as options
|
first item is used as path to mpv binary and the rest is passed as options
|
||||||
|
@ -32,6 +28,7 @@ Note: you can supply custom mpv path and options with the MPV environment
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import socket
|
||||||
import errno
|
import errno
|
||||||
import subprocess
|
import subprocess
|
||||||
import fcntl
|
import fcntl
|
||||||
|
@ -57,47 +54,42 @@ def make_abs(filename):
|
||||||
return filename
|
return filename
|
||||||
files = [make_abs(f) for f in files]
|
files = [make_abs(f) for f in files]
|
||||||
|
|
||||||
FIFO = os.path.join(os.getenv("HOME"), ".umpv_fifo")
|
SOCK = os.path.join(os.getenv("HOME"), ".umpv_socket")
|
||||||
|
|
||||||
fifo_fd = -1
|
sock = None
|
||||||
try:
|
try:
|
||||||
fifo_fd = os.open(FIFO, os.O_NONBLOCK | os.O_WRONLY)
|
sock = socket.socket(socket.AF_UNIX)
|
||||||
except OSError as e:
|
sock.connect(SOCK)
|
||||||
if e.errno == errno.ENXIO:
|
except socket.error as e:
|
||||||
pass # pipe has no writer
|
if e.errno == errno.ECONNREFUSED:
|
||||||
|
sock = None
|
||||||
|
pass # abandoned socket
|
||||||
elif e.errno == errno.ENOENT:
|
elif e.errno == errno.ENOENT:
|
||||||
|
sock = None
|
||||||
pass # doesn't exist
|
pass # doesn't exist
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if fifo_fd >= 0:
|
if sock:
|
||||||
# Unhandled race condition: what if mpv is terminating right now?
|
# Unhandled race condition: what if mpv is terminating right now?
|
||||||
fcntl.fcntl(fifo_fd, fcntl.F_SETFL, 0) # set blocking mode
|
|
||||||
fifo = os.fdopen(fifo_fd, "w")
|
|
||||||
for f in files:
|
for f in files:
|
||||||
# escape: \ \n "
|
# escape: \ \n "
|
||||||
f = f.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n")
|
f = f.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n")
|
||||||
f = "\"" + f + "\""
|
f = "\"" + f + "\""
|
||||||
fifo.write("raw loadfile " + f + " append\n")
|
sock.send(("raw loadfile " + f + " append\n").encode("utf-8"))
|
||||||
else:
|
else:
|
||||||
# Recreate pipe if it doesn't already exist.
|
# Let mpv recreate socket if it doesn't already exist.
|
||||||
# Also makes sure it's safe, and no other user can create a bogus pipe
|
|
||||||
# that breaks security.
|
|
||||||
try:
|
|
||||||
os.unlink(FIFO)
|
|
||||||
except OSError as e:
|
|
||||||
pass
|
|
||||||
os.mkfifo(FIFO, 0o600)
|
|
||||||
|
|
||||||
opts = (os.getenv("MPV") or "mpv").split()
|
opts = (os.getenv("MPV") or "mpv").split()
|
||||||
opts.extend(["--no-terminal",
|
opts.extend(["--no-terminal",
|
||||||
"--on-all-workspaces",
|
"--force-window",
|
||||||
|
"--input-ipc-server=" + SOCK,
|
||||||
# position on lower left screen corner
|
# position on lower left screen corner
|
||||||
# contains funky fix for slight resizings depending on video
|
# contains funky fix for slight resizings depending on video
|
||||||
# move it 10px more left than it wants; 5px more up
|
# move it 10px more left than it wants; 5px more up
|
||||||
"--geometry=15%+-10-+5",
|
"--geometry=15%+-10-+5",
|
||||||
|
"--on-all-workspaces",
|
||||||
"--force-window=immediate",
|
"--force-window=immediate",
|
||||||
"--input-file=" + FIFO,
|
|
||||||
"--"])
|
"--"])
|
||||||
opts.extend(files)
|
opts.extend(files)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue