Commit 1fd0cf63 authored by Jonas Jelten's avatar Jonas Jelten

wheeee: videoscreen created

parents
# editor-specific files
\#*
.#*
*~
.*.swp
# ELF files
*.o
*.a
*.so
# python bytecode
*.pyc
*.pyo
__pycache__
# workflow
*.orig
"""
The video screen.
"""
import socket
import subprocess
MPV_INVOCATION = ["mpv"]
class VideoScreen:
"""
video screen state class
"""
def __init__(self, address, port):
self.address = address
self.port = port
self.sock = None
self.current_mpv = None
def display(self, data):
""" show a new video and kill the old one """
print(" showing '%s'" % data)
# kill the existing mpv:
if self.current_mpv:
try:
self.current_mpv.wait(timeout=0.1)
except subprocess.TimeoutExpired:
self.current_mpv.kill()
try:
self.current_mpv.wait(timeout=0.5)
except subprocess.TimeoutExpired:
raise Exception("process doesn't die :(")
self.current_mpv = subprocess.Popen(MPV_INVOCATION + [data])
def launch(self):
""" run the videoscreen """
self.sock = socket.socket()
self.sock.bind((self.address, self.port))
self.sock.listen(1)
while True:
(conn, addr) = self.sock.accept()
print("new link from '%s'" % (addr,))
buf = bytearray()
while True:
buf += conn.recv(2048)
npos = buf.find(b"\n")
if npos != -1:
data = buf[:npos]
self.display(data.decode())
conn.close()
break
#!/usr/bin/env python3
"""
videoscreen launcher
"""
import argparse
from . import VideoScreen
def main():
""" launch the screen """
cli = argparse.ArgumentParser()
cli.add_argument("-p", "--port", default=60601,
type=int, help="port to listen on")
cli.add_argument("-l", "--listen", default="0.0.0.0",
help="ip to listen on")
args = cli.parse_args()
screen = VideoScreen(args.listen, args.port)
screen.launch()
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment