def tryGetAsxURL(self, stream): """ give this the stream you want to play and this will give you the url for the asx, play that url if it failes with an AuthError try Sirius.auth() and try again or use getAsxUrl """ self.sirius.validateStream() postdict = { "channelKey": stream["channelKey"], "genreKey": stream["genreKey"], "categoryKey": stream["categoryKey"], "selectedStream": stream["selectedStream"], "stopped": "no", } data = self.sirius.getURL("http://www.sirius.com/player/listen/play.action", postdict).read() data = self.sirius.sanitize(data) soup = BeautifulSoup(data) try: firstURL = soup.find("param", {"name": "FileName"})["value"] except TypeError: logfile("getasuxurl-ERROR.html", data) # DEBUG log("\nAuth Error:, see getasuxurl-ERROR.html\n") # DEBUG raise AuthError if not firstURL.startswith("http://"): firstURL = "http://%s%s" % (self.host, firstURL) asxURL = self.sirius.getURL(firstURL).read() log("asxURL = %s" % asxURL) return asxURL
def tryGetAsxURL(self): """ give this the stream you want to play and this will give you the url for the asx, play that url if it failes with an AuthError try Sirius.auth() and try again or use getAsxUrl """ self.validateStream() postdict = { 'channelKey': self.__stream['channelKey'], 'genreKey': self.__stream['genreKey'], 'categoryKey': self.__stream['categoryKey'], 'selectedStream': self.__stream['selectedStream'], 'stopped': 'no', } data = self.__getURL( 'http://www.sirius.com/player/listen/play.action', postdict).read() data = self.sanitize(data) soup = BeautifulSoup(data) try: firstURL = soup.find('param', {'name': 'FileName'})['value'] except TypeError: logfile("getasuxurl-ERROR.html",data) #DEBUG log("\nAuth Error:, see getasuxurl-ERROR.html\n") #DEBUG raise AuthError if not firstURL.startswith('http://'): firstURL = 'http://%s%s' % (self.host, firstURL) asxURL = self.__getURL(firstURL).read() self.asxURL = asxURL log('asxURL = %s' % asxURL) return asxURL
def tryGetAsxURL(self, stream): """ give this the stream you want to play and this will give you the url for the asx, play that url if it failes with an AuthError try Sirius.auth() and try again or use getAsxUrl """ self.sirius.validateStream() postdict = { 'channelKey': stream['channelKey'], 'genreKey': stream['genreKey'], 'categoryKey': stream['categoryKey'], 'selectedStream': stream['selectedStream'], 'stopped': 'no', } data = self.sirius.getURL( 'http://www.sirius.com/player/listen/play.action', postdict).read() data = self.sirius.sanitize(data) soup = BeautifulSoup(data) try: firstURL = soup.find('param', {'name': 'FileName'})['value'] except TypeError: logfile("getasuxurl-ERROR.html", data) #DEBUG log("\nAuth Error:, see getasuxurl-ERROR.html\n") #DEBUG raise AuthError if not firstURL.startswith('http://'): firstURL = 'http://%s%s' % (self.host, firstURL) asxURL = self.sirius.getURL(firstURL).read() log('asxURL = %s' % asxURL) return asxURL
def sanitize(self, data): """ Sanitizes Data against specific errors in the Sirus HTML that Beautiful soup can not handle. """ for sub in htmlfixes.subs: data = re.sub(sub[0], sub[1], data) logfile('sanitize.html', data) #DEBUG return data
def tryGetStreams(self): """ Returns a list of streams avalible, if it failes with AuthError, try Sipie.auth() first, then try again Or use getStreams() """ allstreams = [] url = 'http://%s/sirius/ca/servlet/MediaPlayer' % self.host hd = self.sirius.getURL(url) data = hd.read() hd.close() if data.find('name="selectedStream"') == -1: #IF NOT FOUND post = {'activity': 'minimize', 'token': self.token} hd = self.sirius.getURL(url, post) data = hd.read() hd.close() if data.find('unable to log you in') <> -1: #IF FOUND logfile('login-error.html', data) #DEBUG 0 print 'LoginError, expired account??, see login-error.html' #DEBUG 0 raise LoginError if data.find('Sorry_Pg3.gif') <> -1: #IF FOUND #DEBUG 0 print '\nLoginError: to many logins today? see login-error.html' logfile('login-error.html', data) #DEBUG 0 raise LoginError #self.__dbfd("miniplayer.html",data) #DEBUG XXX #data = open('small_playing_100.html').read() # DEBUG data = self.sirius.sanitize(data) soup = BeautifulSoup(data) for catstrm in soup.findAll('option'): if catstrm['value'].find('|') <> -1: # IF FOUND chunks = catstrm['value'].split('|') stream = { 'channelKey': chunks[2], 'genreKey': chunks[1], 'categoryKey': chunks[0], 'selectedStream': catstrm['value'], 'longName': catstrm.contents[0].split(';')[-1].lower() } allstreams.append(stream) if len(allstreams) < 5: print "ERROR getting streams, see streams-DEBUG.html" # DEBUG #self.__dbfd('streams-DEBUG.html',data) # DEBUG #return defaultstreams #TESTING raise AuthError else: return allstreams
def tryGetAsxURL(self, stream): """ give this the stream you want to play and this will give you the url for the asx, play that url if it failes with an AuthError try Sipie.auth() and try again or use getAsxUrl """ self.sirius.validateStream() # Get hashkey , and the url for the asx post = { 'activity': 'selectStream', 'stream': stream['channelKey'], 'token': self.token } if self.settings.bitrate.lower() == 'high': post = { 'activity': 'selectBitrate', 'stream': stream['channelKey'], 'bitrate': 'high', 'token': self.token } url = 'http://%s/sirius/ca/servlet/MediaPlayer' % self.host hd = self.sirius.getURL(url, post) data = hd.read() data = self.sirius.sanitize(data) hd.close() if data.find('Sorry_Pg3.gif') > 0: #IF FOUND print "Login Error: to many logins today?" print " see getasxurl-DEBUG.html" logfile('getasxurl-DEBUG.html', data) #DEBUG 0 raise LoginError #self.printcookies() #DEBUG #self.__dbfd ("streamselect.html",data) #DEBUG soup = BeautifulSoup(data) try: asxURL = soup.find('param', {'name': 'FileName'})['value'] except: logfile("getasuxurl-ERROR.html", data) #DEBUG print "\nAuth Error:, see getasuxurl-ERROR.html\n" #DEBUG raise AuthError if not asxURL.startswith('http://'): asxURL = 'http://%s%s' % (self.host, asxURL) return asxURL
def tryGetAsxURL(self, stream): """ give this the stream you want to play and this will give you the url for the asx, play that url if it failes with an AuthError try Sipie.auth() and try again or use getAsxUrl """ self.sirius.validateStream() # Get hashkey , and the url for the asx post = {'activity': 'selectStream', 'stream': stream['channelKey'], 'token': self.token} if self.settings.bitrate.lower() == 'high': post = {'activity': 'selectBitrate', 'stream': stream['channelKey'], 'bitrate': 'high', 'token': self.token} url = 'http://%s/sirius/ca/servlet/MediaPlayer' % self.host hd = self.sirius.getURL(url, post) data = hd.read() data = self.sirius.sanitize(data) hd.close() if data.find('Sorry_Pg3.gif') > 0: #IF FOUND print "Login Error: to many logins today?" print " see getasxurl-DEBUG.html" logfile('getasxurl-DEBUG.html', data) #DEBUG 0 raise LoginError #self.printcookies() #DEBUG #self.__dbfd ("streamselect.html",data) #DEBUG soup = BeautifulSoup(data) try: asxURL = soup.find('param', {'name': 'FileName'})['value'] except: logfile("getasuxurl-ERROR.html",data) #DEBUG print "\nAuth Error:, see getasuxurl-ERROR.html\n" #DEBUG raise AuthError if not asxURL.startswith('http://'): asxURL = 'http://%s%s' % (self.host, asxURL) return asxURL
def tryGetStreams(self): """ Returns a list of streams avalible, if it failes with AuthError, try Sirius.auth() first, then try again Or use getStreams() """ log("Getting streams ...") allstreams = [] url = "http://www.sirius.com/player/listen/play.action?resizeActivity=minimize" hd = self.sirius.getURL(url) data = hd.read() hd.close() if data.find('name="selectedStream"') == -1: # IF NOT FOUND post = {"activity": "minimize", "token": self.token} hd = self.sirius.getURL(url, post) data = hd.read() hd.close() if data.find("unable to log you in") <> -1: # IF FOUND logfile("login-error.html", data) # DEBUG 0 print "LoginError, expired account?" # DEBUG 0 raise LoginError if data.find("Sorry_Pg3.gif") <> -1: # IF FOUND print "\nLoginError: to many logins today?" logfile("login-error.html", data) # DEBUG 0 raise LoginError data = self.sirius.sanitize(data) soup = BeautifulSoup(data) for catstrm in soup.findAll("option"): if catstrm["value"].find("|") <> -1: # IF FOUND chunks = catstrm["value"].split("|") stream = { "channelKey": chunks[2], "genreKey": chunks[1], "categoryKey": chunks[0], "selectedStream": catstrm["value"], "longName": catstrm.contents[0].split(";")[-1].lower(), } allstreams.append(stream) if len(allstreams) < 5: log("ERROR getting streams, see streams-DEBUG.html") # DEBUG logfile("streams-DEBUG.html", data) # DEBUG raise AuthError else: logfile("streams.log", repr(allstreams)) log("Streams retrieved, see streams.log") return allstreams
def tryGetStreams(self): """ Returns a list of streams avalible, if it failes with AuthError, try Sirius.auth() first, then try again Or use getStreams() """ log('Getting streams ...') allstreams = [] url = 'http://www.sirius.com/player/listen/play.action?resizeActivity=minimize' hd = self.sirius.getURL(url) data = hd.read() hd.close() if data.find('name="selectedStream"') == -1: #IF NOT FOUND post = {'activity': 'minimize', 'token': self.token} hd = self.sirius.getURL(url, post) data = hd.read() hd.close() if data.find('unable to log you in') <> -1: #IF FOUND logfile('login-error.html', data) #DEBUG 0 print 'LoginError, expired account?' #DEBUG 0 raise LoginError if data.find('Sorry_Pg3.gif') <> -1: #IF FOUND print '\nLoginError: to many logins today?' logfile('login-error.html', data) #DEBUG 0 raise LoginError data = self.sirius.sanitize(data) soup = BeautifulSoup(data) for catstrm in soup.findAll('option'): if catstrm['value'].find('|') <> -1: # IF FOUND chunks = catstrm['value'].split('|') stream = { 'channelKey': chunks[2], 'genreKey': chunks[1], 'categoryKey': chunks[0], 'selectedStream': catstrm['value'], 'longName': catstrm.contents[0].split(';')[-1].lower() } allstreams.append(stream) if len(allstreams) < 5: log("ERROR getting streams, see streams-DEBUG.html") # DEBUG logfile('streams-DEBUG.html', data) # DEBUG raise AuthError else: logfile('streams.log', repr(allstreams)) log('Streams retrieved, see streams.log') return allstreams
def tryGetStreams(self): """ Returns a list of streams avalible, if it failes with AuthError, try Sirius.auth() first, then try again Or use getStreams() """ allstreams = [] url = 'http://www.sirius.com/player/listen/play.action?resizeActivity=minimize' hd = self.__getURL(url) data = hd.read() hd.close() if data.find('name="selectedStream"') == -1: #IF NOT FOUND post = {'activity': 'minimize', 'token': self.token} hd = self.__getURL(url, post) data = hd.read() hd.close() if data.find('unable to log you in') <> -1: #IF FOUND logfile('login-error.html', data) #DEBUG 0 print 'LoginError, expired account?' #DEBUG 0 raise LoginError if data.find('Sorry_Pg3.gif') <> -1: #IF FOUND print '\nLoginError: to many logins today?' logfile('login-error.html', data) #DEBUG 0 raise LoginError data = self.sanitize(data) soup = BeautifulSoup(data) for catstrm in soup.findAll('option'): if catstrm['value'].find('|') <> -1: # IF FOUND chunks = catstrm['value'].split('|') stream = { 'channelKey': chunks[2], 'genreKey': chunks[1], 'categoryKey': chunks[0], 'selectedStream': catstrm['value'], 'longName': catstrm.contents[0].split(';')[-1].lower() } allstreams.append(stream) if len(allstreams) < 5: log("ERROR getting streams, see streams-DEBUG.html") # DEBUG logfile('streams-DEBUG.html',data) # DEBUG raise AuthError else: self.allstreams = allstreams return allstreams