generic 'play file' API route
This commit is contained in:
parent
f870c5107c
commit
6c0380666e
1 changed files with 11 additions and 4 deletions
15
app.py
15
app.py
|
@ -202,15 +202,15 @@ def api_nowplaying():
|
|||
return jsonify(response)
|
||||
|
||||
|
||||
@app.route("/api/isengard", methods=["POST"])
|
||||
def api_isengard():
|
||||
@app.route("/api/play/<filename>", methods=["POST"])
|
||||
def api_play_file(filename: str, error_str: str = "Could not play file '{filename}'"):
|
||||
if not is_playing():
|
||||
playback_start()
|
||||
|
||||
sock = mpv_socket_open()
|
||||
if sock is not None:
|
||||
mpv_socket_command(
|
||||
sock, {"command": ["loadfile", str(music_path.joinpath("isengard.mp3"))]}
|
||||
sock, {"command": ["loadfile", str(music_path.joinpath(filename))]}
|
||||
)
|
||||
sock.close()
|
||||
|
||||
|
@ -218,7 +218,14 @@ def api_isengard():
|
|||
if is_playing():
|
||||
return jsonify("ok")
|
||||
|
||||
return jsonify("Could not take the hobbits to Isengard"), 500
|
||||
return jsonify(error_str.format(filename=filename)), 500
|
||||
|
||||
|
||||
@app.route("/api/isengard", methods=["POST"])
|
||||
def api_isengard():
|
||||
return api_play_file(
|
||||
"isengard.mp3", error_str="Could not take the hobbits to Isengard"
|
||||
)
|
||||
|
||||
|
||||
signal.signal(signal.SIGTERM, sigh)
|
||||
|
|
Loading…
Add table
Reference in a new issue