Package screenlets :: Package plugins :: Module Rhythmbox

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.Rhythmbox

      1  # Rythmbox API
      2
      3  import os
      4  import dbus
      5  from GenericPlayer import GenericAPI
      6  import urllib
      7  from urlparse import urlparse
      8
      9 -class RhythmboxAPI(GenericAPI):
     10          __name__ = 'Rhythmbox'
     11          __version__ = '0.0'
     12          __author__ = 'vrunner'
     13          __desc__ = 'API to the Rhythmbox Music Player'
     14
     15          ns = "org.gnome.Rhythmbox"
     16          playerAPI = None
     17          shellAPI = None
     18
     19          callback_fn = None
     20
     21          # Extended Functions from the GenericAPI
     22
     23 -        def __init__(self, session_bus):
     24                  GenericAPI.__init__(self, session_bus)
     25
     26 -        def is_active(self, dbus_iface):
     27                  if self.ns in dbus_iface.ListNames(): return True
     28                  else: return False
     29
     30 -        def connect(self):
     31                  proxy_obj1 = self.session_bus.get_object(self.ns, '/org/gnome/Rhythmbox/Player')
     32                  proxy_obj2 = self.session_bus.get_object(self.ns, '/org/gnome/Rhythmbox/Shell')
     33                  self.playerAPI = dbus.Interface(proxy_obj1, self.ns+".Player")
     34                  self.shellAPI = dbus.Interface(proxy_obj2, self.ns+".Shell")
     35
     36 -        def get_title(self):
     37                  tmp = self.getProperty('rb:stream-song-title')
     38                  if tmp: return tmp
     39                  else: return self.getProperty('title')
     40
     41 -        def get_album(self):
     42                  tmp = self.getProperty('rb:stream-song-album')
     43                  if tmp: return tmp
     44                  else: return self.getProperty('album')
     45
     46 -        def get_artist(self):
     47                  tmp = self.getProperty('rb:stream-song-artist')
     48                  if tmp: return tmp
     49                  else: return self.getProperty('artist')
     50
     51          # **MUST HAVE** the "COVER ART" Plugin enabled
     52          # (or the "Art Display-Awn" Plugin)
     53
     54 -        def get_cover_path(self):
     55                  # Return the Expected Path (will be ignored by NowPlaying if it doesn't
     56                  # exist
     57
     58                  coverFile = self.getProperty('rb:coverArt-uri')
     59                  if coverFile != None:
     60                          if os.path.isfile(coverFile):
     61                                  return coverFile
     62
     63                  coverFile = os.environ['HOME']+"/.gnome2/rhythmbox/covers/"+self.get_artist()+" - "+self.get_album()+".jpg"
     64                  if not os.path.isfile(coverFile):
     65                          baseURL = urlparse( urllib.url2pathname( self.playerAPI.getPlayingUri() ) )
     66                          basePath = os.path.dirname( baseURL.path )
     67                          names = ['Album', 'Cover', 'Folde']
     68                          for x in os.listdir(basePath):
     69                                  if os.path.splitext(x)[1] in [".jpg", ".png"] and (x.capitalize()[:5] in names):
     70                                          coverFile = basePath + '/' + x
     71                                          return coverFile
     72                  return coverFile
     73
     74
     75
     76 -        def is_playing(self):
     77                  if self.playerAPI.getPlaying() == 1: return True
     78                  else: return False
     79
     80 -        def play_pause(self):
     81                  if self.is_playing:
     82                          self.playerAPI.playPause(False)
     83                  else:
     84                          self.playerAPI.playPause(True)
     85
     86 -        def next(self):
     87                  self.playerAPI.next()
     88
     89 -        def previous(self):
     90                  self.playerAPI.previous()
     91
     92 -        def register_change_callback(self, fn):
     93                  if(self.callback_fn == None):
     94                          #print "Registering Callback"
     95                          self.callback_fn = fn
     96                          self.playerAPI.connect_to_signal("playingChanged", self.info_changed)
     97                          self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed)
     98                          self.playerAPI.connect_to_signal("playingSongPropertyChanged", self.info_changed)
     99
    100          # Internal Functions
    101 -        def getProperty(self, name):
    102                  try:
    103                          val = self.shellAPI.getSongProperties(self.playerAPI.getPlayingUri())[name]
    104                          return val
    105                  except:
    106                          return None
    107
    108 -        def info_changed(self, *args, **kwargs):
    109                  self.callback_fn()
    110