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

Source Code for Module screenlets.plugins.Songbird

  1  # This program is free software: you can redistribute it and/or modify 
  2  # it under the terms of the GNU General Public License as published by 
  3  # the Free Software Foundation, either version 3 of the License, or 
  4  # (at your option) any later version. 
  5  #  
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU General Public License for more details. 
 10  #  
 11  # You should have received a copy of the GNU General Public License 
 12  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 13   
 14  # Songbird API (c) Whise (Helder Fraga) 2008 <helder.fraga@hotmail.com> 
 15   
 16  #Not working yet , and you need songbird 0.6 
 17   
 18  import os 
 19  import dbus 
 20  from GenericPlayer import GenericAPI 
 21  import urllib 
 22  from urlparse import urlparse 
 23   
24 -class SongbirdAPI(GenericAPI):
25 __name__ = 'Songbird' 26 __version__ = '0.1' 27 __author__ = 'Whise' 28 __desc__ = 'API to the Songbird Music Player' 29 30 ns = "org.mozilla.songbird" 31 playerAPI = None 32 shellAPI = None 33 34 callback_fn = None 35 36 # Extended Functions from the GenericAPI 37
38 - def __init__(self, session_bus):
40
41 - def is_active(self, dbus_iface):
42 if self.ns in dbus_iface.ListNames(): return True 43 else: return False
44
45 - def connect(self):
46 proxy_obj1 = self.session_bus.get_object(self.ns, '/org/mozilla/songbird') 47 # proxy_obj2 = self.session_bus.get_object(self.ns, '/org/gnome/Rhythmbox/Shell') 48 self.playerAPI = dbus.Interface(proxy_obj1, self.ns) 49 #self.shellAPI = dbus.Interface(proxy_obj2, self.ns+".Shell") 50 print self.playerAPI.getStatus()
51 - def get_title(self):
52 try: 53 return self.playerAPI.getTitle() 54 except: 55 return ''
56 - def get_album(self):
57 try: 58 return self.playerAPI.getAlbum() 59 except: 60 return ''
61
62 - def get_artist(self):
63 try: 64 return self.playerAPI.getArtist() 65 except: 66 return ''
67 68 # **MUST HAVE** the "COVER ART" Plugin enabled 69 # (or the "Art Display-Awn" Plugin) 70
71 - def get_cover_path(self):
72 # Return the Expected Path (will be ignored by NowPlaying if it doesn't 73 # exist 74 coverFile = os.environ["HOME"] + "/.quodlibet/current.cover" 75 if os.path.isfile(coverFile): 76 return coverFile 77 else: 78 current = os.environ["HOME"] + "/.quodlibet/current" 79 f = open(current, "r") 80 tmp = f.readlines(200) 81 f.close() 82 for line in tmp: 83 if line.startswith('~filename'): 84 t = line.replace('~filename=','') 85 t = t.split('/') 86 coverFile = '' 87 for l in t: 88 if l.find('.') == -1: 89 coverFile = coverFile + l +'/' 90 coverFilefinal = coverFile + 'Folder.jpg' 91 if os.path.isfile(coverFilefinal): 92 return coverFilefinal 93 else: 94 coverFilefinal = coverFile + 'folder.jpg' 95 if os.path.isfile(coverFilefinal): 96 return coverFilefinal 97 98 else: 99 return ''
100
101 - def is_playing(self):
102 if self.get_title() != '': return True 103 else: return False
104
105 - def play_pause(self):
106 self.playerAPI.PlayPause()
107
108 - def next(self):
109 self.playerAPI.Next()
110
111 - def previous(self):
112 self.playerAPI.Previous ()
113
114 - def register_change_callback(self, fn):
115 if(self.callback_fn == None): 116 #print "Registering Callback" 117 self.callback_fn = fn 118 self.playerAPI.connect_to_signal("trackChange", self.info_changed) 119 self.playerAPI.connect_to_signal("stop", self.info_changed)
120 #self.playerAPI.connect_to_signal("playingSongPropertyChanged", self.info_changed) 121 122 # Internal Functions 123 # def getProperty(self, name): 124 ## try: 125 # val = self.shellAPI.getSongProperties(self.playerAPI.getPlayingUri())[name] 126 # return val 127 # except: 128 # return None 129 #
130 - def info_changed(self, *args, **kwargs):
131 self.callback_fn()
132