Created
January 30, 2009 14:20
-
-
Save seanh/55083 to your computer and use it in GitHub Desktop.
Now Playing in Rhythmbox web app
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
A little web app that I wrote to tell the world what song is currently | |
playing in rhtyhmbox on the jukebox at the forest cafe. Requires rhythmbox- | |
client and web.py 0.31. templates.html should go in a folder called | |
templates. |
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
$def with (nowplaying) | |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<title>Now playing at The Forest</title> | |
<!-- External stylesheet --> | |
<!--<link rel="stylesheet" type="text/css" href="mystyle.css" />--> | |
<!-- Internal stylesheet --> | |
<style type="text/css"> | |
body { | |
color: #ccc; | |
background: #444; | |
font-family: Georgia; | |
font-size:1.25em; | |
} | |
a { | |
color: #fff; | |
font-weight:bold; | |
} | |
b { | |
color:#99a; | |
} | |
div.nowplaying { | |
width:20em; | |
margin-left:auto; | |
margin-right:auto; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="nowplaying"> | |
<h1>Playing right now at <a href="http://theforest.org.uk/">the forest</a></h1> | |
<p>$:nowplaying</p> | |
</div> | |
</body> | |
</html> |
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 web | |
import commands | |
urls = ("/.*", "NowPlaying") | |
app = web.application(urls, globals()) | |
# Tell web.py to look for templates in the templates folder | |
render = web.template.render('templates') | |
class NowPlaying: | |
def GET(self): | |
# Run rhythmbox-client and capture its output. | |
cmd = 'rhythmbox-client --no-start --no-present --print-playing-format "<b>%tt</b><br/>by <b>%aa</b><br/>from <b>%at</b>."' | |
status,output = commands.getstatusoutput(cmd); | |
# rhythmbox-client always returns status 0, but the output is an empty | |
# string if rhythmbox is open but not playing anything, or an error if | |
# rhythmbox is not open. | |
if (output == '') or ('Rhythmbox-WARNING **:' in output): | |
return render.nowplaying(':( Rhythmbox is not playing.') | |
else: | |
return render.nowplaying(output) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment