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 # Sonata API (c) Whise (Helder Fraga) 2008 <helder.fraga@hotmail.com> 15 16 17 import os 18 import dbus 19 import gobject 20 import mpdclient2 21 from GenericPlayer import GenericAPI 2224 __name__ = 'Sonata API' 25 __version__ = '0.0' 26 __author__ = '' 27 __desc__ = '' 28 29 30 playerAPI = None 31 32 __timeout = None 33 __interval = 2 34 35 callbackFn = None 36 __curplaying = None 37 38 39 ns = "org.MPD.Sonata" 40 iroot = "/org/MPD/Sonata" 41 iface = "org.MPD.SonataInterface" 42 43 host = 'localhost' 44 port = 6600 45 musicdir = '/media/MULTIMEDIA/music/' 46 49 50 # Check if the player is active : Returns Boolean 51 # A handle to the dbus interface is passed in : doesn't need to be used 52 # if there are other ways of checking this (like dcop in amarok) 56 57 # Make a connection to the Player14559 proxy_obj = self.session_bus.get_object(self.ns, self.iroot) 60 self.playerAPI = dbus.Interface(proxy_obj, self.iface)61 62 # The following return Strings 66 70 7476 artist = self.get_artist() 77 album = self.get_album() 78 filename = os.path.expanduser("~/.covers/" + artist + "-" + album + ".jpg") 79 if os.path.isfile(filename): 80 return filename 81 82 try: 83 t = mpdclient2.connect().currentsong().file 84 t = t.replace('file://','') 85 t = t.split('/') 86 basePath = '' 87 for l in t: 88 if l.find('.') == -1: 89 basePath = basePath + l +'/' 90 91 names = ['Album', 'Cover', 'Folde'] 92 for x in os.listdir(basePath): 93 if os.path.splitext(x)[1] in [".jpg", ".png"] and (x.capitalize()[:5] in names): 94 coverFile = basePath + x 95 return coverFile 96 except: return '' 97 return ''98 99 100 # Returns Boolean 104 105 # The following do not return any values107 status = mpdclient2.connect().status() 108 if status.state == 'play': 109 mpdclient2.connect().pause(1) 110 elif status.state == 'pause': 111 mpdclient2.connect().pause(0) 112 else: 113 mpdclient2.connect().play()114 117 120122 self.callback_fn = fn 123 # Could not find a callback signal for Banshee, so just calling after some time interval 124 if self.__timeout: 125 gobject.source_remove(self.__timeout) 126 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)127129 # Only call the callback function if Data has changed 130 if self.__timeout: 131 gobject.source_remove(self.__timeout) 132 try: 133 if self.__curplaying != None and not self.is_playing(): 134 self.__curplaying = None 135 self.callback_fn() 136 137 playinguri = self.get_title() 138 if self.is_playing() and self.__curplaying != playinguri: 139 self.__curplaying = playinguri 140 self.callback_fn() 141 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed) 142 except: 143 # The player exited ? call callback function 144 self.callback_fn()
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jan 4 16:58:27 2012 | http://epydoc.sourceforge.net |