Package screenlets :: Package plugins :: Module Kaffeine

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.Kaffeine

      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  # Kaffeine API (c) Whise (Helder Fraga) 2008 <helder.fraga@hotmail.com>
      9
     10
     11  import os
     12  import string
     13  import gobject
     14  from GenericPlayer import GenericAPI
     15  import commands
     16
     17 -class KaffeineAPI(GenericAPI):
     18          __name__ = 'Kaffeine API'
     19          __version__ = '0.0'
     20          __author__ = 'Whise (Helder Fraga)'
     21          __desc__ = 'Kaffeine API to a Music Player'
     22
     23          playerAPI = None
     24
     25          __timeout = None
     26          __interval = 2
     27
     28          callbackFn = None
     29          __curplaying = None
     30
     31
     32 -        def __init__(self, session_bus):
     33                  # Ignore the session_bus. Initialize a dcop connection
     34                  GenericAPI.__init__(self, session_bus)
     35
     36          # Check if the player is active : Returns Boolean
     37          # A handle to the dbus interface is passed in : doesn't need to be used
     38          # if there are other ways of checking this (like dcop in amarok)
     39 -        def is_active(self, dbus_iface):
     40                  proc = os.popen("""ps axo "%p,%a" | grep "kaffeine" | grep -v grep|cut -d',' -f1""").read()
     41                  procs = proc.split('\n')
     42                  if len(procs) > 1:
     43                          return True
     44                  else:
     45                          return False
     46 -        def connect(self):
     47                  pass
     48
     49          # The following return Strings
     50 -        def get_title(self):
     51                  return commands.getoutput('dcop kaffeine KaffeineIface title')
     52
     53 -        def get_album(self):
     54                  return commands.getoutput('dcop kaffeine KaffeineIface album')
     55
     56 -        def get_artist(self):
     57                  return commands.getoutput('dcop kaffeine KaffeineIface artist')
     58
     59
     60 -        def get_cover_path(self):
     61                  t = commands.getoutput('dcop kaffeine KaffeineIface getFileName')
     62                  t = t.split('/')
     63                  basePath = ''
     64                  for l in t:
     65                          if l.find('.') == -1:
     66                                  basePath = basePath + l +'/'
     67
     68                  names = ['Album', 'Cover', 'Folde']
     69                  for x in os.listdir(basePath):
     70                          if os.path.splitext(x)[1] in [".jpg", ".png"] and (x.capitalize()[:5] in names):
     71                                  coverFile = basePath + x
     72                                  return coverFile
     73
     74                  return ''
     75  #path
     76
     77          # Returns Boolean
     78 -        def is_playing(self):
     79                  return commands.getoutput('dcop kaffeine KaffeineIface isPlaying')
     80
     81          # The following do not return any values
     82 -        def play_pause(self):
     83                  if self.is_playing():
     84                          os.system('dcop kaffeine KaffeineIface pause &')
     85                  else:
     86                          os.system('dcop kaffeine KaffeineIface play &')
     87 -        def next(self):
     88                  os.system('dcop kaffeine KaffeineIface next &')
     89
     90 -        def previous(self):
     91                  os.system('dcop kaffeine KaffeineIface previous &')
     92
     93 -        def register_change_callback(self, fn):
     94                  self.callback_fn = fn
     95                  # Could not find a callback signal for Listen, so just calling after some time interval
     96                  if self.__timeout:
     97                          gobject.source_remove(self.__timeout)
     98                  self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
     99                  #self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed)
    100
    101 -        def info_changed(self, signal=None):
    102                  # Only call the callback function if Data has changed
    103                  if self.__curplaying != commands.getoutput('dcop kaffeine KaffeineIface title'):
    104                          self.__curplaying = commands.getoutput('dcop kaffeine KaffeineIface title')
    105                          self.callback_fn()
    106
    107                  if self.__timeout:
    108                          gobject.source_remove(self.__timeout)
    109                  self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
    110