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 # Amarok API by Whise and vrunner 15 16 import os 17 import string 18 import gobject 19 from GenericPlayer import GenericAPI 20 import commands 2123 __name__ = 'Amarok API' 24 __version__ = '0.0' 25 __author__ = 'Whise and vrunner' 26 __desc__ = 'Amarok API to a Music Player' 27 28 playerAPI = None 29 30 __timeout = None 31 __interval = 2 32 33 callbackFn = None 34 __curplaying = None 35 36 40 41 # Check if the player is active : Returns Boolean 42 # A handle to the dbus interface is passed in : doesn't need to be used 43 # if there are other ways of checking this (like dcop in amarok)11445 proc = os.popen("""ps axo "%p,%a" | grep "amarokapp" | grep -v grep|cut -d',' -f1""").read() 46 procs = proc.split('\n') 47 if len(procs) > 1: 48 return True 49 else: 50 return False53 54 # The following return Strings56 return commands.getoutput('dcop amarok player title')5759 return commands.getoutput('dcop amarok player album')6062 return commands.getoutput('dcop amarok player artist')63 6466 path = commands.getoutput('dcop amarok player coverImage') 67 if path.find('130@nocover.png') != -1: 68 t = commands.getoutput('dcop amarok player path') 69 t = t.split('/') 70 basePath = '' 71 for l in t: 72 if l.find('.') == -1: 73 basePath = basePath + l +'/' 74 75 names = ['Album', 'Cover', 'Folde'] 76 for x in os.listdir(basePath): 77 if os.path.splitext(x)[1] in [".jpg", ".png"] and (x.capitalize()[:5] in names): 78 coverFile = basePath + x 79 return coverFile 80 81 return ''82 83 # Returns Boolean85 return commands.getoutput('dcop amarok player isPlaying')86 87 # The following do not return any values 90 93 9698 self.callback_fn = fn 99 # Could not find a callback signal for Listen, so just calling after some time interval 100 if self.__timeout: 101 gobject.source_remove(self.__timeout) 102 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)103 #self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed) 104106 # Only call the callback function if Data has changed 107 if self.__curplaying != commands.getoutput('dcop amarok player nowPlaying'): 108 self.__curplaying = commands.getoutput('dcop amarok player nowPlaying') 109 self.callback_fn() 110 111 if self.__timeout: 112 gobject.source_remove(self.__timeout) 113 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 |