updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / sipie / sanitize.patch
blobf7707eab9f1be9e808f9ee29bd3569e798d4b753
1 diff --git a/Sipie/Factory.py b/Sipie/Factory.py
2 index 667feb2..9e7cb1c 100644
3 --- a/Sipie/Factory.py
4 +++ b/Sipie/Factory.py
5 @@ -203,6 +203,7 @@ class Factory:
6 #self.__dbfd("MediaPlayer.html",data) #DEBUG
7 if data.find('bg-now-playing-mac-large') > 0: #already authed
8 return True
9 + data = self.sanitize(data)
10 soup = BeautifulSoup(data)
11 try:
12 self.token = soup.find('input', {'name': 'token'})['value']
13 @@ -263,6 +264,9 @@ class Factory:
14 #self.__dbfd("debug-ERROR.html",data) #DEBUG
15 print "Unsuccessful Login. Please check username and password." #DEBUG 0
16 raise LoginError
17 + elif data.find('Too Many Login Attempts') <> -1: #IF FOUND
18 + print "Too Many Login Attempts, try again later."
19 + raise LoginError
20 return True
22 def tryGetStreams(self):
23 @@ -295,6 +299,7 @@ class Factory:
24 raise LoginError
25 #self.__dbfd("miniplayer.html",data) #DEBUG XXX
26 #data = open('small_playing_100.html').read() # DEBUG
27 + data = self.sanitize(data)
28 soup = BeautifulSoup(data)
29 for catstrm in soup.findAll('option'):
30 if catstrm['value'].find('|') <> -1: # IF FOUND
31 @@ -341,6 +346,7 @@ class Factory:
32 raise LoginError
33 #self.printcookies() #DEBUG
34 #self.__dbfd ("streamselect.html",data) #DEBUG
35 + data = self.sanitize(data)
36 soup = BeautifulSoup(data)
37 try:
38 asxURL = soup.find('param', {'name': 'FileName'})['value']
39 @@ -470,3 +476,17 @@ class Factory:
40 else:
41 nowplaying['new'] = False
42 return nowplaying
44 + def sanitize(self, data):
45 + """ Sanitizes Data against specific errors in the Sirus HTML that
46 + Beautiful soup can not handle."""
47 + import re
48 + data = re.sub(r'style=["\']?(\{.*\})["\']?', r'style="\1" ', data)
49 + data = re.sub(r'width=["\']?(\d+)["\']?', r'width="\1"', data)
50 + #data = re.sub(r'width=["\']?(\d+i)[^\d]*%["\']?', r'width="\1%"', data)
51 + data = re.sub(r'width="100"%"', r'width="100%"', data)
52 + data = re.sub(r'onclick=["\']?([^\s<>]*)["\']?', r'onclick=""', data)
54 + #print data #DEBUG
55 + return data
57 diff --git a/Sipie/cliPlayer.py b/Sipie/cliPlayer.py
58 index 2cb8ba6..49187a4 100644
59 --- a/Sipie/cliPlayer.py
60 +++ b/Sipie/cliPlayer.py
61 @@ -38,6 +38,8 @@ def cliPlayer():
62 def ask4Stream():
63 try:
64 stream = raw_input("Enter stream: ")
65 + stream = stream.strip()
66 + #print "|" + stream + "|" #Debug
67 except (EOFError, KeyboardInterrupt):
68 print "Thanks for playing"
69 sys.exit(0)