put music path in env-able variable

This commit is contained in:
deneb 2025-02-25 19:55:59 +01:00
parent 0bdb5e3f4e
commit 86a866b2bf

12
app.py
View file

@ -2,11 +2,10 @@ from flask import Flask, render_template, request, send_file, Response
import os
import subprocess
import signal
from pathlib import Path
music_path = Path(os.environ.get("MUSIC_PATH", "./music"))
mpv_process: subprocess.Popen | None = None
if not os.path.exists("music"):
os.mkdir("music")
app = Flask(__name__)
@ -27,7 +26,7 @@ def playback_start():
"mpv",
"--input-ipc-server=/tmp/mpvsocket",
"--shuffle",
"music",
str(music_path),
"--no-video",
]
)
@ -80,7 +79,7 @@ def route_toggle():
@app.route("/files/<path:path>", methods=["GET"])
@app.route("/files")
def filemgr(path=""):
full_path = os.path.join("music", path)
full_path = music_path.joinpath(path)
print(full_path)
if os.path.isfile(full_path):
return send_file(full_path)
@ -124,6 +123,9 @@ def api_status():
signal.signal(signal.SIGTERM, sigh)
signal.signal(signal.SIGINT, sigh)
if not music_path.exists():
music_path.mkdir()
if __name__ == "__main__":
try:
app.run(host="0.0.0.0", port=1337)