Added a report of all current tuuube streams

This commit is contained in:
Jono Targett 2023-06-13 17:07:59 +09:30
parent 9151ddce42
commit bed92bf0af
3 changed files with 16 additions and 3 deletions

View File

@ -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/<id>/start')
def start_tuuube_stream(id):
"""Start streaming from a youtube source.

View File

@ -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):

View File

@ -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)