9130: Extend API to support streaming dummy audio sources #1
@ -173,6 +173,16 @@ def radio_info(radio):
|
|||||||
# Youtube shit
|
# Youtube shit
|
||||||
tubes = {}
|
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')
|
@app.route('/tuuube/<id>/start')
|
||||||
def start_tuuube_stream(id):
|
def start_tuuube_stream(id):
|
||||||
"""Start streaming from a youtube source.
|
"""Start streaming from a youtube source.
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
def is_alive(subprocess):
|
def is_alive(subprocess):
|
||||||
return (subprocess.poll() is None)
|
return True if (subprocess and subprocess.poll() is None) else False
|
||||||
|
|
||||||
class Streamer:
|
class Streamer:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@ -25,9 +25,12 @@ class Tuuube(Streamer):
|
|||||||
|
|
||||||
def __init__(self, id):
|
def __init__(self, id):
|
||||||
self.id = id
|
self.id = id
|
||||||
|
self.playback = None
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
def is_playing(self):
|
||||||
|
return is_alive(self.playback)
|
||||||
|
|
||||||
def _stream_path(self):
|
def _stream_path(self):
|
||||||
return f":{Tuuube.PORT}/tuuube/{self.id}"
|
return f":{Tuuube.PORT}/tuuube/{self.id}"
|
||||||
|
|
||||||
@ -62,7 +65,7 @@ class Tuuube(Streamer):
|
|||||||
)
|
)
|
||||||
|
|
||||||
while self.run:
|
while self.run:
|
||||||
if not is_alive(self.playback):
|
if not self.is_playing():
|
||||||
print('Playback failed, aborting stream.', file=sys.stderr)
|
print('Playback failed, aborting stream.', file=sys.stderr)
|
||||||
break
|
break
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user