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 # LastFMProxy API by atie 15 16 import os 17 import string 18 import gobject 19 import mpdclient2 20 import urllib2 21 from GenericPlayer import GenericAPI 2224 __name__ = 'LastFMProxy API' 25 __version__ = '0.0' 26 __author__ = 'atie' 27 __desc__ = 'LastFMProxy API to a Music Player' 28 29 playerAPI = None 30 31 __timeout = None 32 __interval = 3 33 34 callbackFn = False 35 __curplaying = None 3614438 # Ignore the session_bus. Initialize a mpdclient connection 39 GenericAPI.__init__(self, session_bus)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 used44 app = mpdclient2.connect() 45 if not app: return False 46 else: 47 proc = os.popen("""ps axo "%p,%a" | grep "last" | grep -v grep|cut -d',' -f1""").read() 48 procs = proc.split('\n') 49 if len(procs) > 1: 50 return True 51 else: 52 return False53 54 55 # Make a connection to the Player 58 59 # Get LastFMProxy dump61 try: 62 dump = urllib2.urlopen('http://localhost:1881/np').read() 63 except urllib2.HTTPError, e: 64 print "Cannot retrieve URL: HTTP Error Code", e.code 65 except urllib2.URLError, e: 66 print "Cannot retrieve URL: " + e.reason[1] 67 return dump6870 x = len(first) 71 begin = dump.find(first) +x 72 end = dump.find(last, begin) 73 return dump[begin:end]74 75 # The following return Strings 76 # FIXME, maybe.78 #return getattr(self.playerAPI.currentsong(), 'np_title = ', ';') 79 dump = self.getdump() 80 return self.getBetween(dump, 'np_title = \'', '\';')81 82 # FIXME if necessary 86 87 # FIXME if necessary 91 92 # FIXME, if necessary, currently by the amazoncoverartsearch94 #return os.environ['HOME']+"/.covers/"+self.get_artist()+\ 95 # " - "+self.get_album()+".jpg" 96 #return "" 97 # No need to search Amazon, one image file for now playing 98 #path = os.environ['HOME']+"/.covers/image_by_lfproxy.jpg" 99 path = os.environ['HOME']+"/.covers/"+self.get_artist()+\ 100 " - "+self.get_album()+".jpg" 101 dump = self.getdump() 102 f = open(path, 'wb') 103 image = urllib2.urlopen(self.getBetween(dump, 'np_image = \'', 104 '\'')).read() 105 f.write(image) 106 f.close() 107 return path108 109 110 # Returns Boolean 115 116 # The following do not return any values 119 122 125127 self.callback_fn = fn 128 # Could not find a callback signal for mpd, so just calling after some time interval 129 if self.__timeout: 130 gobject.source_remove(self.__timeout) 131 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)132 #self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed) 133135 # Only call the callback function if Data has changed 136 if self.__curplaying != getattr(self.playerAPI.currentsong(), 137 'title', ''): 138 self.__curplaying = getattr(self.playerAPI.currentsong(), 'title', '') 139 self.callback_fn() 140 141 if self.__timeout: 142 gobject.source_remove(self.__timeout) 143 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:25 2012 | http://epydoc.sourceforge.net |