Package screenlets :: Package plugins :: Module Amarok

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.Amarok

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