screenlets.plugins.Juk

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

# Source Code for Module screenlets.plugins.Juk

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