From bed92bf0afd17ff5cdf1823beae65e89ef1b46e8 Mon Sep 17 00:00:00 2001 From: Jono Targett Date: Tue, 13 Jun 2023 17:07:59 +0930 Subject: [PATCH] Added a report of all current tuuube streams --- microservice.py | 10 ++++++++++ streamer.py | 2 +- tuuube.py | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/microservice.py b/microservice.py index d9256ad..9387f68 100755 --- a/microservice.py +++ b/microservice.py @@ -173,6 +173,16 @@ def radio_info(radio): # Youtube shit tubes = {} +@app.route('/tuuube/report') +def tuuube_report(): + """List the tuuube streams opened and their streaming status. + --- + responses: + 200: + description: JSON + """ + return jsonify({id:{'active':tube.is_streaming(),'playing':tube.is_playing()} for id,tube in tubes.items()}) + @app.route('/tuuube//start') def start_tuuube_stream(id): """Start streaming from a youtube source. diff --git a/streamer.py b/streamer.py index 907f554..b815ba4 100644 --- a/streamer.py +++ b/streamer.py @@ -1,7 +1,7 @@ from threading import Thread def is_alive(subprocess): - return (subprocess.poll() is None) + return True if (subprocess and subprocess.poll() is None) else False class Streamer: def __init__(self): diff --git a/tuuube.py b/tuuube.py index 3f0c9c7..b25bb7d 100755 --- a/tuuube.py +++ b/tuuube.py @@ -25,9 +25,12 @@ class Tuuube(Streamer): def __init__(self, id): self.id = id - + self.playback = None super().__init__() + def is_playing(self): + return is_alive(self.playback) + def _stream_path(self): return f":{Tuuube.PORT}/tuuube/{self.id}" @@ -62,7 +65,7 @@ class Tuuube(Streamer): ) while self.run: - if not is_alive(self.playback): + if not self.is_playing(): print('Playback failed, aborting stream.', file=sys.stderr) break time.sleep(0.1)