#!/usr/bin/python # -*- coding: utf-8 -*- ##################################################################### # Based on public domain code to see how the bonobo interface worked # Removed xchat dep and added minor usefulness # UTF-8 encoding and arguments for optional stars # # -- Xchat hints ------------------------------------------------- # Add something like this to your xchat user commands as 'song': # /exec -o python /home/mongoose/scripts/rhythmbox-song.py &2 # # Now in xchat /song 10 will show song with suns as stars # ----------------------------------------------------------------- # mongoose at icculus dot org ##################################################################### import bonobo import sys def rb_song(star_index): try: rb = bonobo.get_object("OAFIID:GNOME_Rhythmbox", "GNOME/Rhythmbox") except Exception, e: print "Rhythmbox is not running." return rb_bag = rb.getPlayerProperties() song = rb_bag.getValue("song").value() if song is None: print "Rhythmbox is not playing a song." return if star_index > 12 or star_index < 0: star_index = 0 # Stuff I don't use #mins = song.duration / 60 #secs = song.duration % 60 #song.genre #song.play_count #filename = song.path # The magical mongoose utf-8 star array stars_on_thars = [ "✩", "✪", "✫", "✬", "✭", "✮", "✯", "✰", "❀", "✿", "❂", "❁", "*" ] star = stars_on_thars[star_index] stars = song.rating * star + (5-song.rating) * " " s = "Playing: %B" + song.title + "%B " if song.album != "Unknown": s = s + "from %B" + song.album + "%B " if song.artist != "Unknown": s = s + "by %B" + song.artist + "%B " s = s + stars print s return if __name__ == "__main__": args = sys.argv[1:] if not args: rb_song(0) else: rb_song(eval(args[0]))