9130: Extend API to support streaming dummy audio sources #1

Merged
jono merged 7 commits from 9130_dummy_audio into main 2023-06-15 12:49:14 +09:30
3 changed files with 16 additions and 3 deletions
Showing only changes of commit bed92bf0af - Show all commits

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)