Thursday, 5 July 2012

Conky Exaile

Just a quick one but I'm a big fan of conky and exaile. Disappointingly it seems Exaile changed its DBUS API so my 'now playing' script (shamefully pulled from google) no longer worked.

I've been dabbling with python a bit so had a go at writing my own replacement script. Its the first time I've really used DBUS - quite impressed so far, especially after finding dbus-cli

Anyway - here's the code. Quick, dirty and just what I needed:


 #!/usr/bin/env python  
   
 import sys  
 import dbus  
 reload(sys)  
   
 sys.setdefaultencoding('utf8')  
   
 bus = dbus.SessionBus()  
 try:  
  remote_object = bus.get_object("org.exaile.Exaile","/org/exaile/Exaile")  
 except dbus.exceptions.DBusException:  
  print("Exaile not running")  
  sys.exit()  
   
 iface = dbus.Interface(remote_object, "org.exaile.Exaile")  
 status = iface.Query()  
 #print "Status: "+status  
   
   
   
 if status == "Not playing.":  
  print("Exaile not playing")  
  sys.exit()  
 elif "paused" in status:  
  print("Exaile is paused")  
  sys.exit()  
   
 title = iface.GetTrackAttr("title")  
 album = iface.GetTrackAttr("album")  
 artist = iface.GetTrackAttr("artist")  
   
 if iface.IsPlaying():  
  print("%s - %s (%s)"%(title, artist, album))  
 else:  
  print "Exaile is not playing"  
   

No comments:

Post a Comment