44 lines
824 B
Python
Executable File
44 lines
824 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Music streaming.
|
|
"""
|
|
import subprocess
|
|
|
|
from flask import Flask, Response, render_template
|
|
|
|
FFMPEG_CMD = [
|
|
'ffmpeg', '-y',
|
|
'-loglevel', 'panic',
|
|
'-i', '',
|
|
'-codec:a', 'libopus',
|
|
'-b:a', '64k',
|
|
'-f', 'opus',
|
|
'-'
|
|
]
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/')
|
|
def index():
|
|
"""Main index page."""
|
|
track = "01 - Balls to the Wall.flac"
|
|
return render_template('index.html', track=track)
|
|
|
|
|
|
@app.route('/stream/<track>')
|
|
def stream(track):
|
|
"""View for the raw audio file."""
|
|
FFMPEG_CMD[5] = track
|
|
|
|
def generate():
|
|
with subprocess.Popen(FFMPEG_CMD, stdout=subprocess.PIPE) as proc:
|
|
data = proc.stdout.read(1024)
|
|
while data:
|
|
yield data
|
|
data = proc.stdout.read(1024)
|
|
return Response(generate(), mimetype="audio/ogg")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host='0.0.0.0', port=5150)
|