forked from server/soundboard
Merge branch 'random' into 'master'
Add endpoint /random See merge request mmueller/soundboard!5
This commit is contained in:
commit
7d79dab19b
@ -1,8 +1,10 @@
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import subprocess
|
||||
import sqlite3
|
||||
|
||||
|
||||
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, g
|
||||
|
||||
import config
|
||||
@ -147,3 +149,9 @@ ON tag.id = checked.id""", (sound,))
|
||||
@app.route("/sounds/<path:name>")
|
||||
def sounds(name):
|
||||
return send_from_directory(config.path, name)
|
||||
|
||||
@app.route("/random")
|
||||
def play_random():
|
||||
sounds = [os.fsencode(file).decode() for file in os.listdir(config.path)]
|
||||
random_sound = random.sample(sounds, 1)
|
||||
subprocess.Popen(["omxplayer", os.path.join(config.path, random_sound.encode("utf-8")], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
Loading…
x
Reference in New Issue
Block a user