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 # LastFMProxy API by atie 9 10 import os 11 import string 12 import gobject 13 import mpdclient2 14 import urllib2 15 from GenericPlayer import GenericAPI 1618 __name__ = 'LastFMProxy API' 19 __version__ = '0.0' 20 __author__ = 'atie' 21 __desc__ = 'LastFMProxy API to a Music Player' 22 23 playerAPI = None 24 25 __timeout = None 26 __interval = 3 27 28 callbackFn = False 29 __curplaying = None 3013832 # Ignore the session_bus. Initialize a mpdclient connection 33 GenericAPI.__init__(self, session_bus)34 35 # Check if the player is active : Returns Boolean 36 # A handle to the dbus interface is passed in : doesn't need to be used38 app = mpdclient2.connect() 39 if not app: return False 40 else: 41 proc = os.popen("""ps axo "%p,%a" | grep "last" | grep -v grep|cut -d',' -f1""").read() 42 procs = proc.split('\n') 43 if len(procs) > 1: 44 return True 45 else: 46 return False47 48 49 # Make a connection to the Player 52 53 # Get LastFMProxy dump55 try: 56 dump = urllib2.urlopen('http://localhost:1881/np').read() 57 except urllib2.HTTPError, e: 58 print "Cannot retrieve URL: HTTP Error Code", e.code 59 except urllib2.URLError, e: 60 print "Cannot retrieve URL: " + e.reason[1] 61 return dump6264 x = len(first) 65 begin = dump.find(first) +x 66 end = dump.find(last, begin) 67 return dump[begin:end]68 69 # The following return Strings 70 # FIXME, maybe.72 #return getattr(self.playerAPI.currentsong(), 'np_title = ', ';') 73 dump = self.getdump() 74 return self.getBetween(dump, 'np_title = \'', '\';')75 76 # FIXME if necessary 80 81 # FIXME if necessary 85 86 # FIXME, if necessary, currently by the amazoncoverartsearch88 #return os.environ['HOME']+"/.covers/"+self.get_artist()+\ 89 # " - "+self.get_album()+".jpg" 90 #return "" 91 # No need to search Amazon, one image file for now playing 92 #path = os.environ['HOME']+"/.covers/image_by_lfproxy.jpg" 93 path = os.environ['HOME']+"/.covers/"+self.get_artist()+\ 94 " - "+self.get_album()+".jpg" 95 dump = self.getdump() 96 f = open(path, 'wb') 97 image = urllib2.urlopen(self.getBetween(dump, 'np_image = \'', 98 '\'')).read() 99 f.write(image) 100 f.close() 101 return path102 103 104 # Returns Boolean 109 110 # The following do not return any values 113 116 119121 self.callback_fn = fn 122 # Could not find a callback signal for mpd, so just calling after some time interval 123 if self.__timeout: 124 gobject.source_remove(self.__timeout) 125 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)126 #self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed) 127129 # Only call the callback function if Data has changed 130 if self.__curplaying != getattr(self.playerAPI.currentsong(), 131 'title', ''): 132 self.__curplaying = getattr(self.playerAPI.currentsong(), 'title', '') 133 self.callback_fn() 134 135 if self.__timeout: 136 gobject.source_remove(self.__timeout) 137 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Feb 28 23:21:27 2011 | http://epydoc.sourceforge.net |