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

Source Code for Module screenlets.plugins.Songbird

  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  # Songbird API (c) Whise (Helder Fraga) 2008 <helder.fraga@hotmail.com> 
  9   
 10  #Not working yet , and you need songbird 0.6 
 11   
 12  import os 
 13  import dbus 
 14  from GenericPlayer import GenericAPI 
 15  import urllib 
 16  from urlparse import urlparse 
 17   
18 -class SongbirdAPI(GenericAPI):
19 __name__ = 'Songbird' 20 __version__ = '0.1' 21 __author__ = 'Whise' 22 __desc__ = 'API to the Songbird Music Player' 23 24 ns = "org.mozilla.songbird" 25 playerAPI = None 26 shellAPI = None 27 28 callback_fn = None 29 30 # Extended Functions from the GenericAPI 31
32 - def __init__(self, session_bus):
34
35 - def is_active(self, dbus_iface):
36 if self.ns in dbus_iface.ListNames(): return True 37 else: return False
38
39 - def connect(self):
40 proxy_obj1 = self.session_bus.get_object(self.ns, '/org/mozilla/songbird') 41 # proxy_obj2 = self.session_bus.get_object(self.ns, '/org/gnome/Rhythmbox/Shell') 42 self.playerAPI = dbus.Interface(proxy_obj1, self.ns) 43 #self.shellAPI = dbus.Interface(proxy_obj2, self.ns+".Shell") 44 print self.playerAPI.getStatus()
45 - def get_title(self):
46 try: 47 return self.playerAPI.getTitle() 48 except: 49 return ''
50 - def get_album(self):
51 try: 52 return self.playerAPI.getAlbum() 53 except: 54 return ''
55
56 - def get_artist(self):
57 try: 58 return self.playerAPI.getArtist() 59 except: 60 return ''
61 62 # **MUST HAVE** the "COVER ART" Plugin enabled 63 # (or the "Art Display-Awn" Plugin) 64
65 - def get_cover_path(self):
66 # Return the Expected Path (will be ignored by NowPlaying if it doesn't 67 # exist 68 coverFile = os.environ["HOME"] + "/.quodlibet/current.cover" 69 if os.path.isfile(coverFile): 70 return coverFile 71 else: 72 current = os.environ["HOME"] + "/.quodlibet/current" 73 f = open(current, "r") 74 tmp = f.readlines(200) 75 f.close() 76 for line in tmp: 77 if line.startswith('~filename'): 78 t = line.replace('~filename=','') 79 t = t.split('/') 80 coverFile = '' 81 for l in t: 82 if l.find('.') == -1: 83 coverFile = coverFile + l +'/' 84 coverFilefinal = coverFile + 'Folder.jpg' 85 if os.path.isfile(coverFilefinal): 86 return coverFilefinal 87 else: 88 coverFilefinal = coverFile + 'folder.jpg' 89 if os.path.isfile(coverFilefinal): 90 return coverFilefinal 91 92 else: 93 return ''
94
95 - def is_playing(self):
96 if self.get_title() != '': return True 97 else: return False
98
99 - def play_pause(self):
100 self.playerAPI.PlayPause()
101
102 - def next(self):
103 self.playerAPI.Next()
104
105 - def previous(self):
106 self.playerAPI.Previous ()
107
108 - def register_change_callback(self, fn):
109 if(self.callback_fn == None): 110 #print "Registering Callback" 111 self.callback_fn = fn 112 self.playerAPI.connect_to_signal("trackChange", self.info_changed) 113 self.playerAPI.connect_to_signal("stop", self.info_changed)
114 #self.playerAPI.connect_to_signal("playingSongPropertyChanged", self.info_changed) 115 116 # Internal Functions 117 # def getProperty(self, name): 118 ## try: 119 # val = self.shellAPI.getSongProperties(self.playerAPI.getPlayingUri())[name] 120 # return val 121 # except: 122 # return None 123 #
124 - def info_changed(self, *args, **kwargs):
125 self.callback_fn()
126