I rarely get to sit down at my home machine and make something for my own use these days. I’ve always been interested in working with xmms and now these days xmms2. I built a plugin years ago that would dump audio information via http. These days I’d do the same, but with a script instead of a compiled c module for xmms. So this brings me to experimenting with xmms2 and python. This could be the first in a series of me blogging about python integration and what is possible with linux libraries and apps that have native python libraries. Python lends itself to being a lightweight language with great performance and fast turnover. According to debian there is a package that contains xmms2 bindings for python.
python-xmmsclient – XMMS2 – Python bindings
apt-get install python-xmmsclient
I decided to port a display_track shell script found on a debian administration article
Instead of using osd-cat I went with aosd-cat since I like the options better and it uses the libaosd library. Whatever I build next is news to me =) See the code below if you are interested in forking it for yourself.
By the way, excuse the formatting, its a bug in my code highlighter!
#!/usr/bin/env pythonimport xmmsclientimport osimport sysimport timedef xmms_connect(name):xmms = xmmsclient.XMMS(name)try:xmms.connect(os.getenv("XMMS_PATH"))except IOError, detail:print "Connection failed:", detailsys.exit(1)return xmms# retrieve current playing iddef xmms_playback_id(xmms):result = xmms.playback_current_id()result.wait()if result.iserror():return 0id = result.value()return iddef get_current_track(xmms, playback_id):result = xmms.medialib_get_info(playback_id)result.wait()if result.iserror():print "medialib get info returns error, %s" % result.get_error()return Noneminfo = result.value()try:artist = minfo["artist"]except KeyError:artist = "No Artist"try:title = minfo["title"]except KeyError:title = "No Title"try:bitrate = minfo["bitrate"]except KeyError:bitrate = 0return "%s - %s [%s]" % (artist, title, bitrate)def main():last_playback_id = 0osd_options="\--font='-b&h-lucida-medium-normal-*-96-*-*-*-p-*-iso10646-1' \-B black \-R white \-b 100 \--x-offset=50 \--y-offset=-50 \--width=900"xmms = xmms_connect("aosd_display")while 1:playback_id = xmms_playback_id(xmms)if playback_id != 0 and playback_id != last_playback_id:last_playback_id = playback_idtrack = get_current_track(xmms, playback_id)os.system("echo '%s' | /usr/bin/aosd_cat %s" % (track, osd_options))time.sleep(2)main()- Download this code: display_track.py