Home | Trees | Indices | Help |
|
---|
|
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 # Audacious 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 2325 __name__ = 'Audacious API' 26 __version__ = '0.0' 27 __author__ = 'Whise (Helder Fraga)' 28 __desc__ = 'Audacious 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 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)12947 proc = os.popen("""ps axo "%p,%a" | grep "audacious" | grep -v grep|cut -d',' -f1""").read() 48 procs = proc.split('\n') 49 if len(procs) > 1: 50 return True 51 else: 52 return False55 56 # The following return Strings58 try: 59 a = commands.getoutput('audtool --current-song').split(' - ')[2] 60 return a 61 except: 62 return ''6365 try: 66 a = commands.getoutput('audtool --current-song').split(' - ')[1] 67 return a 68 except: 69 return ''7072 try: 73 a = commands.getoutput('audtool --current-song').split(' - ')[0] 74 return a 75 except: 76 return ''77 7880 try: 81 t = urllib.unquote(commands.getoutput('audtool --current-song-filename')) 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 101 102 # The following do not return any values 105 108 111113 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) 119121 # Only call the callback function if Data has changed 122 if self.__curplaying != commands.getoutput('audtool --current-song'): 123 self.__curplaying = commands.getoutput('audtool --current-song') 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)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jan 4 16:58:27 2012 | http://epydoc.sourceforge.net |