Skip to content

Instantly share code, notes, and snippets.

@seanh
Created January 30, 2009 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanh/55083 to your computer and use it in GitHub Desktop.
Save seanh/55083 to your computer and use it in GitHub Desktop.
Now Playing in Rhythmbox web app
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.
$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>
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