screenlets.plugins.Quodlibet

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

# Source Code for Module screenlets.plugins.Quodlibet

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