initial commit

This commit is contained in:
iou1name 2018-09-12 13:04:00 -04:00
commit 0c3ccba783
6 changed files with 83 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
__pycache__/
*.swp
*.swo

14
README.md Normal file
View File

@ -0,0 +1,14 @@
# Musik
Stream some music.
## Requirements
Python 3.6+
FFmpeg compiled with `--enable-libopus`
Python packages: `flask gunicorn`
## Install
1. Get on the floor
2. Walk the dinosaur
## Usage
`gunicorn -b localhost:5150 -e SCRIPT_NAME=/musik musik:app`

43
musik.py Executable file
View File

@ -0,0 +1,43 @@
#!/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)

2
static/musik.css Normal file
View File

@ -0,0 +1,2 @@
body {
}

2
static/musik.js Normal file
View File

@ -0,0 +1,2 @@
function ajax() {
}

19
templates/index.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Musik</title>
<link rel="stylesheet" type="text/css" href="/static/musik.css">
<script type="text/javascript" src="/static/musik.js"></script>
</head>
<body>
<h1>Musik</h1>
<div id="navigation">
</div>
<div id="playerContainer">
<hr>
<audio id="player" controls>
<source id="stream" src="{{ url_for('stream', track=track) }}" type="audio/ogg">
</audio>
</div>
</body>
</html>