Package screenlets :: Package plugins :: Module Exaile

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.Exaile

      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
      9  # Exaile API by vrunner
     10
     11  import os
     12  import dbus
     13  import string
     14  import gobject
     15  from GenericPlayer import GenericAPI
     16
     17  #EXAILE = {'DBUS_NAME':'org.exaile.DBusInterface','DBUS_OBJECT':'/DBusInterfaceObject', \
     18  #                       'DBUS_TITLE':'get_title()','DBUS_ALBUM':'get_album()', \
     19  #                       'DBUS_ARTIST':'get_artist()','DBUS_ART':'get_cover_path()',\
     20  #                       'DBUS_PLAYING':'query()','PLAY_WORD':'playing'}
     21
     22 -class ExaileAPI(GenericAPI):
     23          __name__ = 'Exaile API'
     24          __version__ = '0.0'
     25          __author__ = 'vrunner'
     26          __desc__ = 'API to the Exaile Music Player'
     27
     28          ns = "org.exaile.DBusInterface"
     29          iroot = "/DBusInterfaceObject"
     30          iface = "org.exaile.DBusInterface"
     31
     32          playerAPI = None
     33
     34          __timeout = None
     35          __interval = 2
     36
     37          callbackFn = None
     38          __curplaying = None
     39
     40          # Extended Functions from the GenericAPI
     41
     42 -        def __init__(self, session_bus):
     43                  GenericAPI.__init__(self, session_bus)
     44
     45 -        def is_active(self, dbus_iface):
     46                  if self.ns in dbus_iface.ListNames(): return True
     47                  else: return False
     48
     49 -        def connect(self):
     50                  proxy_obj = self.session_bus.get_object(self.ns, self.iroot)
     51                  self.playerAPI = dbus.Interface(proxy_obj, self.iface)
     52
     53 -        def get_title(self):
     54                  return self.playerAPI.get_title()
     55
     56 -        def get_album(self):
     57                  return self.playerAPI.get_album()
     58
     59 -        def get_artist(self):
     60                  return self.playerAPI.get_artist()
     61
     62 -        def get_cover_path(self):
     63                  return self.playerAPI.get_cover_path()
     64
     65 -        def is_playing(self):
     66                  if self.now_playing() == "": return False
     67                  else: return True
     68
     69 -        def play_pause(self):
     70                  self.playerAPI.play()
     71
     72 -        def next(self):
     73                  self.playerAPI.next_track()
     74
     75 -        def previous(self):
     76                  self.playerAPI.prev_track()
     77
     78 -        def register_change_callback(self, fn):
     79                  self.callback_fn = fn
     80                  # Could not find a callback signal for Banshee, so just calling after some time interval
     81                  if self.__timeout:
     82                          gobject.source_remove(self.__timeout)
     83                  self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
     84
     85 -        def info_changed(self, signal=None):
     86                  if self.__timeout:
     87                          gobject.source_remove(self.__timeout)
     88
     89                  try:
     90                          # Only call the callback function if Data has changed
     91                          if self.__curplaying != None and not self.is_playing():
     92                                  self.__curplaying = None
     93                                  self.callback_fn()
     94
     95                          nowplaying = self.now_playing()
     96                          if self.is_playing() and self.__curplaying != nowplaying:
     97                                  self.__curplaying = nowplaying
     98                                  self.callback_fn()
     99                          self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
    100                  except:
    101                          # The player exited ? call callback function
    102                          self.callback_fn()
    103                          pass
    104
    105
    106 -        def now_playing(self):
    107                  return self.get_artist()+self.get_title()
    108