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

Source Code for Module screenlets.plugins.Kaffeine

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