Home | Trees | Indices | Help |
|
---|
|
1 #!/usr/bin/env python 2 # This application is released under the GNU General Public License 3 # v3 (or, at your option, any later version). You can find the full 4 # text of the license under http://www.gnu.org/licenses/gpl.txt. 5 # By using, editing and/or distributing this software you agree to 6 # the terms and conditions of this license. 7 # Thank you for using free software! 8 9 # LastFMProxy API by atie 10 11 import os 12 import string 13 import gobject 14 import mpdclient2 15 import urllib2 16 from GenericPlayer import GenericAPI 1719 __name__ = 'LastFMProxy API' 20 __version__ = '0.0' 21 __author__ = 'atie' 22 __desc__ = 'LastFMProxy API to a Music Player' 23 24 playerAPI = None 25 26 __timeout = None 27 __interval = 3 28 29 callbackFn = False 30 __curplaying = None 3113933 # Ignore the session_bus. Initialize a mpdclient connection 34 GenericAPI.__init__(self, session_bus)35 36 # Check if the player is active : Returns Boolean 37 # A handle to the dbus interface is passed in : doesn't need to be used39 app = mpdclient2.connect() 40 if not app: return False 41 else: 42 proc = os.popen("""ps axo "%p,%a" | grep "last" | grep -v grep|cut -d',' -f1""").read() 43 procs = proc.split('\n') 44 if len(procs) > 1: 45 return True 46 else: 47 return False48 49 50 # Make a connection to the Player 53 54 # Get LastFMProxy dump56 try: 57 dump = urllib2.urlopen('http://localhost:1881/np').read() 58 except urllib2.HTTPError, e: 59 print "Cannot retrieve URL: HTTP Error Code", e.code 60 except urllib2.URLError, e: 61 print "Cannot retrieve URL: " + e.reason[1] 62 return dump6365 x = len(first) 66 begin = dump.find(first) +x 67 end = dump.find(last, begin) 68 return dump[begin:end]69 70 # The following return Strings 71 # FIXME, maybe.73 #return getattr(self.playerAPI.currentsong(), 'np_title = ', ';') 74 dump = self.getdump() 75 return self.getBetween(dump, 'np_title = \'', '\';')76 77 # FIXME if necessary 81 82 # FIXME if necessary 86 87 # FIXME, if necessary, currently by the amazoncoverartsearch89 #return os.environ['HOME']+"/.covers/"+self.get_artist()+\ 90 # " - "+self.get_album()+".jpg" 91 #return "" 92 # No need to search Amazon, one image file for now playing 93 #path = os.environ['HOME']+"/.covers/image_by_lfproxy.jpg" 94 path = os.environ['HOME']+"/.covers/"+self.get_artist()+\ 95 " - "+self.get_album()+".jpg" 96 dump = self.getdump() 97 f = open(path, 'wb') 98 image = urllib2.urlopen(self.getBetween(dump, 'np_image = \'', 99 '\'')).read() 100 f.write(image) 101 f.close() 102 return path103 104 105 # Returns Boolean 110 111 # The following do not return any values 114 117 120122 self.callback_fn = fn 123 # Could not find a callback signal for mpd, 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)127 #self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed) 128130 # Only call the callback function if Data has changed 131 if self.__curplaying != getattr(self.playerAPI.currentsong(), 132 'title', ''): 133 self.__curplaying = getattr(self.playerAPI.currentsong(), 'title', '') 134 self.callback_fn() 135 136 if self.__timeout: 137 gobject.source_remove(self.__timeout) 138 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Wed Jun 4 18:52:59 2008 | http://epydoc.sourceforge.net |