screenlets.plugins.Amarok

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

# Source Code for Module screenlets.plugins.Amarok

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