Last active
August 29, 2015 14:05
-
-
Save Xorcerer/387eadf1c9e1eb7d6321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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