Skip to content

Instantly share code, notes, and snippets.

@Xorcerer
Last active August 29, 2015 14:05
Show Gist options
  • Save Xorcerer/387eadf1c9e1eb7d6321 to your computer and use it in GitHub Desktop.
Save Xorcerer/387eadf1c9e1eb7d6321 to your computer and use it in GitHub Desktop.
import os
from subprocess import Popen, PIPE
from bottle import route, run, template
dir = 'music'
files = os.listdir(dir)
music_player = None
list_template = '''
<ul>
% for item in files:
<li><a href='/play/{{item}}'>{{item}}</a></li>
% end
</ul>
'''
@route('/list')
def list():
return template(list_template, files=files)
@route('/')
def index():
return 'hello world!!'
@route('/play/<filename>')
def play(filename):
global music_player
if music_player:
music_player.kill()
music_player = Popen(['omxplayer', os.path.join(dir, filename)], stdin=PIPE, stdout=PIPE)
redirect('/list')
run(host='localhost', port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment