Skip to content

Instantly share code, notes, and snippets.

@mds2
Created May 14, 2018 16:20
Show Gist options
  • Save mds2/48d36404e9867ae9f5efa955f1f521a3 to your computer and use it in GitHub Desktop.
Save mds2/48d36404e9867ae9f5efa955f1f521a3 to your computer and use it in GitHub Desktop.
simple web interface to systemd music player
[Unit]
Description=Dronezone (somafm) music player
Conflicts=sonic-universe.service groove-salad.service silence.service
[Service]
Type=simple
WorkingDirectory=/home/pi
ExecStart=/usr/bin/mplayer http://ice3.somafm.com/dronezone-128-mp3
KillMode=process
Restart=on-failure
[Install]
Alias=dronezone.service
from bottle import route, run, template
from subprocess import call
default_str = """<html>
<head><title>Music player</title></head>
<body>
<style>
li {
font-size:100px
}
</style>
<ul>
<li><a href="jazz">jazz</a></li>
<li><a href="drone">drone</a></li>
<li><a href="groove">groove</a></li>
<li><a href="silence">silence</a></li>
</ul>
</body>
</html>"""
@route('/play/<name>')
def play(name):
if name == "jazz":
call(["systemctl", "--user", "start", "sonic-universe.service"])
elif name == "drone":
call(["systemctl", "--user", "start", "dronezone.service"])
elif name == "groove":
call(["systemctl", "--user", "start", "groove-salad.service"])
elif name == "silence":
call(["systemctl", "--user", "start", "silence.service"])
else:
call(["systemctl", "--user", "start", "do-nothing.service"])
return default_str
run(host='192.168.1.141', port=8080, debug=True)
@mds2
Copy link
Author

mds2 commented May 14, 2018

screenshot_pi_music_player_ui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment