Package screenlets :: Package plugins :: Module Juk

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.Juk

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