def getFragment( self, stationId=None, format=None ): if stationId == None: stationId = self.curStation if format == None: format = self.curFormat reqUrl = BASE_URL_LID.replace('https', 'http') %( self.rid, self.lid, "getFragment" ) args = ( self._timestamp(), self.authToken, stationId, "0", "", "", \ format, "0", "0" ) req = xmlrpclib.dumps( args, "playlist.getFragment" ) req = req.replace( "\n", "" ) enc = crypt.encryptString( req, self.keys['out'] ) u = urllib2.urlopen( reqUrl, enc ) resp = u.read() u.close() parsed = xmlrpclib.loads( resp )[0][0] #last 48 chars of URL encrypted, padded w/ 8 * '\x08' for i in range( len( parsed ) ): url = parsed[i]["audioURL"] url = url[:-48] + crypt.decryptString( url[-48:],\ self.keys['in'] )[:-8] parsed[i]["audioURL"] = url self.curStation = stationId self.curFormat = format return parsed
def get_next_songs_for_station(self,station, format="mp3"): request_url = self.BASE_URL_LID_SECURE % (self.rid, self.lid, "getFragment") songs = self.doRequest(request_url, "playlist.getFragment", self.authToken, station.pandora_id,'0','','',format,'0','0') for i in range(len(songs)): url = songs[i]["audioURL"] url = url[:-48] + crypt.decryptString(url[-48:])[:-8] songs[i]["audioURL"] = url return songs
def getFragment(self, stationId=None, format="mp3"): reqUrl = self.BASE_URL_LID % (self.rid, self.lid, "getFragment") songlist = self.doRequest( reqUrl, "playlist.getFragment", self.authToken, stationId, "0", "", "", format, "0", "0" ) # last 48 chars of URL encrypted, padded w/ 8 * '\x08' for i in range(len(songlist)): url = songlist[i]["audioURL"] url = url[:-48] + crypt.decryptString(url[-48:])[:-8] songlist[i]["audioURL"] = url self.curStation = stationId self.curFormat = format return songlist
def sync(self): reqUrl = self.BASE_URL_RID_SECURE % (self.rid, "sync") req = xmlrpclib.dumps((), "misc.sync").replace("\n", "") enc = crypt.encryptString(req) u = urllib2.urlopen(reqUrl, enc) resp = u.read() u.close() try: parsed = xmlrpclib.loads(resp) cryptedTimestamp = parsed[0][0] decryptedTimestamp = crypt.decryptString(cryptedTimestamp) self.timedelta = int(time.time()) - int(decryptedTimestamp[4:-2]) except xmlrpclib.Fault, fault: raise ValueError(str(fault))
if format == None: format = self.curFormat reqUrl = self.base_url_lid %( self.rid, self.lid, "getFragment" ) args = ( self._timestamp(), self.authToken, stationId, "0", "", "", \ format, "0", "0" ) req = xmlrpclib.dumps( args, "playlist.getFragment" ) req = req.replace( "\n", "" ) enc = crypt.encryptString( req, self.keys['out'] ) u = urlopen( reqUrl, enc ) resp = u.read() u.close() try: parsed = xmlrpclib.loads( resp )[0][0] except xmlrpclib.Fault, fault: parsed = resp print "Error:", fault.faultString print "Code:", fault.faultCode #last 48 chars of URL encrypted, padded w/ 8 * '\x08' for i in range( len( parsed ) ): url = parsed[i]["audioURL"] url = url[:-48] + crypt.decryptString( url[-48:], self.keys['in'] )[:-8] parsed[i]["audioURL"] = url self.curStation = stationId self.curFormat = format return parsed