Package screenlets :: Package plugins :: Module Quodlibet
[hide private]
[frames] | no frames]

Source Code for Module screenlets.plugins.Quodlibet

  1  # This application is released under the GNU General Public License  
  2  # v3 (or, at your option, any later version). You can find the full  
  3  # text of the license under http://www.gnu.org/licenses/gpl.txt.  
  4  # By using, editing and/or distributing this software you agree to  
  5  # the terms and conditions of this license.  
  6  # Thank you for using free software! 
  7   
  8  #  Quodlibet API (c) Whise (Helder Fraga) 2008 <helder.fraga@hotmail.com> 
  9   
 10   
 11  import os 
 12  import dbus 
 13  from GenericPlayer import GenericAPI 
 14  import urllib 
 15  from urlparse import urlparse 
 16   
17 -class QuodlibetAPI(GenericAPI):
18 __name__ = 'Quodlibet' 19 __version__ = '0.1' 20 __author__ = 'Whise' 21 __desc__ = 'API to the Quodlibet Music Player' 22 23 ns = "net.sacredchao.QuodLibet" 24 playerAPI = None 25 shellAPI = None 26 27 callback_fn = None 28 29 # Extended Functions from the GenericAPI 30
31 - def __init__(self, session_bus):
33
34 - def is_active(self, dbus_iface):
35 if self.ns in dbus_iface.ListNames(): return True 36 else: return False
37
38 - def connect(self):
39 proxy_obj1 = self.session_bus.get_object(self.ns, '/net/sacredchao/QuodLibet') 40 # proxy_obj2 = self.session_bus.get_object(self.ns, '/org/gnome/Rhythmbox/Shell') 41 self.playerAPI = dbus.Interface(proxy_obj1, self.ns)
42 #self.shellAPI = dbus.Interface(proxy_obj2, self.ns+".Shell") 43
44 - def get_title(self):
45 try: 46 return self.playerAPI.CurrentSong()['title'] 47 except: 48 return ''
49 - def get_album(self):
50 try: 51 return self.playerAPI.CurrentSong()['album'] 52 except: 53 return ''
54
55 - def get_artist(self):
56 try: 57 return self.playerAPI.CurrentSong()['artist'] 58 except: 59 return ''
60 61 # **MUST HAVE** the "COVER ART" Plugin enabled 62 # (or the "Art Display-Awn" Plugin) 63
64 - def get_cover_path(self):
65 # Return the Expected Path (will be ignored by NowPlaying if it doesn't 66 # exist 67 coverFile = os.environ["HOME"] + "/.quodlibet/current.cover" 68 if os.path.isfile(coverFile): 69 return coverFile 70 else: 71 current = os.environ["HOME"] + "/.quodlibet/current" 72 f = open(current, "r") 73 tmp = f.readlines(200) 74 f.close() 75 for line in tmp: 76 if line.startswith('~filename'): 77 t = line.replace('~filename=','') 78 t = t.split('/') 79 basePath = '' 80 for l in t: 81 if l.find('.') == -1: 82 basePath = basePath + l +'/' 83 84 names = ['Album', 'Cover', 'Folde'] 85 for x in os.listdir(basePath): 86 if os.path.splitext(x)[1] in [".jpg", ".png"] and (x.capitalize()[:5] in names): 87 coverFile = basePath + x 88 return coverFile 89 90 return ''
91
92 - def is_playing(self):
93 if self.get_title() != '': return True 94 else: return False
95
96 - def play_pause(self):
97 self.playerAPI.PlayPause()
98
99 - def next(self):
100 self.playerAPI.Next()
101
102 - def previous(self):
103 self.playerAPI.Previous ()
104
105 - def register_change_callback(self, fn):
106 if(self.callback_fn == None): 107 #print "Registering Callback" 108 self.callback_fn = fn 109 self.playerAPI.connect_to_signal("SongStarted", self.info_changed) 110 self.playerAPI.connect_to_signal("SongEnded", self.info_changed)
111 #self.playerAPI.connect_to_signal("playingSongPropertyChanged", self.info_changed) 112 113 # Internal Functions 114 # def getProperty(self, name): 115 ## try: 116 # val = self.shellAPI.getSongProperties(self.playerAPI.getPlayingUri())[name] 117 # return val 118 # except: 119 # return None 120 #
121 - def info_changed(self, *args, **kwargs):
122 self.callback_fn()
123