Home | Trees | Indices | Help |
|
---|
|
1 # This application is released under the GNU General Public License 2 # v3 (or, at your option, any later version). You can find the full 3 # text of the license under http://www.gnu.org/licenses/gpl.txt. 4 # By using, editing and/or distributing this software you agree to 5 # the terms and conditions of this license. 6 # Thank you for using free software! 7 8 # Sonata API (c) Whise (Helder Fraga) 2008 <helder.fraga@hotmail.com> 9 10 11 import os 12 import dbus 13 import gobject 14 import mpdclient2 15 from GenericPlayer import GenericAPI 1618 __name__ = 'Sonata API' 19 __version__ = '0.0' 20 __author__ = '' 21 __desc__ = '' 22 23 24 playerAPI = None 25 26 __timeout = None 27 __interval = 2 28 29 callbackFn = None 30 __curplaying = None 31 32 33 ns = "org.MPD.Sonata" 34 iroot = "/org/MPD/Sonata" 35 iface = "org.MPD.SonataInterface" 36 37 host = 'localhost' 38 port = 6600 39 musicdir = '/media/MULTIMEDIA/music/' 40 43 44 # Check if the player is active : Returns Boolean 45 # A handle to the dbus interface is passed in : doesn't need to be used 46 # if there are other ways of checking this (like dcop in amarok) 50 51 # Make a connection to the Player13953 proxy_obj = self.session_bus.get_object(self.ns, self.iroot) 54 self.playerAPI = dbus.Interface(proxy_obj, self.iface)55 56 # The following return Strings 60 64 6870 artist = self.get_artist() 71 album = self.get_album() 72 filename = os.path.expanduser("~/.covers/" + artist + "-" + album + ".jpg") 73 if os.path.isfile(filename): 74 return filename 75 76 try: 77 t = mpdclient2.connect().currentsong().file 78 t = t.replace('file://','') 79 t = t.split('/') 80 basePath = '' 81 for l in t: 82 if l.find('.') == -1: 83 basePath = basePath + l +'/' 84 85 names = ['Album', 'Cover', 'Folde'] 86 for x in os.listdir(basePath): 87 if os.path.splitext(x)[1] in [".jpg", ".png"] and (x.capitalize()[:5] in names): 88 coverFile = basePath + x 89 return coverFile 90 except: return '' 91 return ''92 93 94 # Returns Boolean 98 99 # The following do not return any values101 status = mpdclient2.connect().status() 102 if status.state == 'play': 103 mpdclient2.connect().pause(1) 104 elif status.state == 'pause': 105 mpdclient2.connect().pause(0) 106 else: 107 mpdclient2.connect().play()108 111 114116 self.callback_fn = fn 117 # Could not find a callback signal for Banshee, so just calling after some time interval 118 if self.__timeout: 119 gobject.source_remove(self.__timeout) 120 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)121123 # Only call the callback function if Data has changed 124 if self.__timeout: 125 gobject.source_remove(self.__timeout) 126 try: 127 if self.__curplaying != None and not self.is_playing(): 128 self.__curplaying = None 129 self.callback_fn() 130 131 playinguri = self.get_title() 132 if self.is_playing() and self.__curplaying != playinguri: 133 self.__curplaying = playinguri 134 self.callback_fn() 135 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed) 136 except: 137 # The player exited ? call callback function 138 self.callback_fn()
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Feb 28 23:21:26 2011 | http://epydoc.sourceforge.net |