From 3e15a967f8adcf8fa3874e73e6b9811340687f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Fri, 14 Jul 2017 14:56:44 +0200 Subject: [PATCH] Implement video killing feature --- soundboard.py | 16 ++++++++++++++-- static/main.css | 1 + templates/index.html | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/soundboard.py b/soundboard.py index 70e0205..5ab2961 100644 --- a/soundboard.py +++ b/soundboard.py @@ -11,6 +11,8 @@ app = Flask(__name__) app.jinja_env.trim_blocks = True app.jinja_env.lstrip_blocks = True +processlist = [] + @app.route("/") @app.route("/play/") @app.route("/say/", methods=["POST"]) @@ -39,7 +41,17 @@ def index(sound=None, text=None, video=None): if video is not None: url = subprocess.check_output(["youtube-dl", "-g", "-f", "mp4", video]).decode() - subprocess.Popen(["omxplayer", url.split("\n")[1]]) - subprocess.Popen(["omxplayer", "-b", url.split("\n")[0]]) + audioproc = subprocess.Popen(["omxplayer", url.split("\n")[1]]) + videoproc = subprocess.Popen(["omxplayer", "-b", url.split("\n")[0]]) + + processlist.append(audioproc) + processlist.append(videoproc) + + killvideo = request.args.get("killvideo") + + if killvideo is not None and killvideo in ["1", "true", "yes"]: + for process in processlist: + process.terminate() + processlist.remove(process) return render_template("index.html", sounds=sounds) diff --git a/static/main.css b/static/main.css index 6934739..5dd5835 100644 --- a/static/main.css +++ b/static/main.css @@ -20,6 +20,7 @@ h1 { } form { + padding: 5px; text-align: center; } diff --git a/templates/index.html b/templates/index.html index 637d78f..56b76ab 100644 --- a/templates/index.html +++ b/templates/index.html @@ -25,6 +25,10 @@ +
+ + +