From f570309d9cc64b761aa2354da885be9cdf8d1b42 Mon Sep 17 00:00:00 2001 From: clemens Date: Mon, 23 Oct 2017 21:04:52 +0200 Subject: [PATCH] add images --- requirements.txt | 1 + soundboard.py | 19 +++++++++++++++++++ static/main.js | 17 +++++++++++++++++ templates/index.html | 11 +++++++++++ 4 files changed, 48 insertions(+) diff --git a/requirements.txt b/requirements.txt index 6aee249..639537d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ itsdangerous==0.24 Jinja2==2.9.6 MarkupSafe==1.0 Werkzeug==0.12.2 +requests \ No newline at end of file diff --git a/soundboard.py b/soundboard.py index d6d7616..f6417b4 100644 --- a/soundboard.py +++ b/soundboard.py @@ -1,6 +1,9 @@ import os +import shutil import subprocess +import tempfile +import requests from flask import Flask, render_template, request, redirect, url_for, send_from_directory import config @@ -53,3 +56,19 @@ def index(sound=None, text=None, video=None): @app.route("/sounds/") def sounds(name): return send_from_directory(config.path, name) + +@app.route("/image/") +def image(imageurl=None): + if not imageurl: + return False + with tempfile.NamedTemporaryFile(mode="wb", buffering=True) as tmp: + image = requests.get(imageurl, stream=True) + if not image.ok: + return False + shutil.copyfileobj(image.raw, tmp) + subprocess.Popen(["killall", "pngview"]) + subprocess.Popen(["/opt/raspidmx/pngview/pngview", "-b", "0", "-d", "0", "-n", tmp.name]) + +@app.route("/kill/images") +def killImages(): + subprocess.Popen(["killall", "pngview"]) diff --git a/static/main.js b/static/main.js index 01f86b4..0adffca 100644 --- a/static/main.js +++ b/static/main.js @@ -197,3 +197,20 @@ function killAllAudio() { ajaxRequest("/?killvideo=yes"); } } + + + +/* +* Reads the stream url from input with id #streaming-url and forwards it to the server using AJAX. +*/ +function showImage() { + var streamUrl = document.querySelector("#streaming-url").value; + ajaxRequest("/image/?imageurl="+encodeURI(streamUrl)); +} + +/* +* Kills all images +*/ +function killAllImages() { + ajaxRequest("/kill/images"); +} diff --git a/templates/index.html b/templates/index.html index 3e31879..51cfbfe 100644 --- a/templates/index.html +++ b/templates/index.html @@ -33,6 +33,7 @@ Sounds Streams Voices + Images +