From 44c29d0120070f19c967799b846383f85651aed2 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 6 Dec 2025 17:24:38 +0100 Subject: [PATCH] flask tst --- modules/progress.py | 2 ++ modules/web.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 modules/web.py diff --git a/modules/progress.py b/modules/progress.py index 854a8c4..0fb6160 100644 --- a/modules/progress.py +++ b/modules/progress.py @@ -11,5 +11,7 @@ class Module(PlayerModule): if track.official: data = f"{track.path.name}: {format_time(elapsed)} / {format_time(total)}\n" Path("/tmp/radioPlayer_progress").write_text(data) + def shutdown(self): + Path("/tmp/radioPlayer_progress").write_text("") module = Module() \ No newline at end of file diff --git a/modules/web.py b/modules/web.py new file mode 100644 index 0000000..bde2eca --- /dev/null +++ b/modules/web.py @@ -0,0 +1,32 @@ +import multiprocessing + +from . import PlayerModule, Track +from flask import Flask + +manager = multiprocessing.Manager() +data = manager.dict() +data_lock = manager.Lock() + +app = Flask(__name__) +app.logger.disabled = True + +@app.route("/") +def home(): + global data, data_lock + with data_lock: return repr(data) + +def web(): + app.run("0.0.0.0", 3001) +p = multiprocessing.Process(target=web) + +class Module(PlayerModule): + def on_new_playlist(self, playlist: list[Track]) -> None: + global data, data_lock + with data_lock: data["playlist"] = playlist + def shutdown(self): + global p + p.terminate() + p.join() + +module = Module() +p.start() \ No newline at end of file