Skip to content

Commit 9264524

Browse files
committed
closed pyload#440
1 parent 5eeac17 commit 9264524

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

Diff for: module/Utils.py

+27-17
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def decode(string):
2525
return string
2626

2727

28-
def removeChars(string, repl):
28+
def remove_chars(string, repl):
2929
""" removes all chars in repl from string"""
3030
if type(string) == str:
3131
return string.translate(maketrans("", ""), repl)
@@ -35,9 +35,9 @@ def removeChars(string, repl):
3535
def save_path(name):
3636
#remove some chars
3737
if os.name == 'nt':
38-
return removeChars(name, '/\\?%*:|"<>')
38+
return remove_chars(name, '/\\?%*:|"<>')
3939
else:
40-
return removeChars(name, '/\\"')
40+
return remove_chars(name, '/\\"')
4141

4242
def save_join(*args):
4343
""" joins a path, encoding aware """
@@ -134,21 +134,31 @@ def idfun(x): return x
134134
return result
135135

136136

137-
def parseFileSize(string): #returns bytes
138-
m = re.match(r"(\d*[\.,]?\d+)(.*)", string.strip().lower())
139-
if m:
140-
traffic = float(m.group(1).replace(",", "."))
141-
unit = m.group(2).strip()
142-
if unit in ("gb", "gig", "gbyte", "gigabyte", "gib"):
143-
traffic *= 1 << 30
144-
elif unit in ("mb", "mbyte", "megabyte", "mib"):
145-
traffic *= 1 << 20
146-
elif unit in ("kb", "kib", "kilobyte", "kbyte"):
147-
traffic *= 1 << 10
148-
return traffic
137+
def parseFileSize(string, unit=None): #returns bytes
138+
if not unit:
139+
m = re.match(r"(\d*[\.,]?\d+)(.*)", string.strip().lower())
140+
if m:
141+
traffic = float(m.group(1).replace(",", "."))
142+
unit = m.group(2)
143+
else:
144+
return 0
145+
else:
146+
if isinstance(string, basestring):
147+
traffic = float(string.replace(",", "."))
148+
else:
149+
traffic = string
150+
151+
#ignore case
152+
unit = unit.lower().strip()
149153

150-
return 0
154+
if unit in ("gb", "gig", "gbyte", "gigabyte", "gib", "g"):
155+
traffic *= 1 << 30
156+
elif unit in ("mb", "mbyte", "megabyte", "mib", "m"):
157+
traffic *= 1 << 20
158+
elif unit in ("kb", "kib", "kilobyte", "kbyte", "k"):
159+
traffic *= 1 << 10
151160

161+
return traffic
152162

153163
def lock(func):
154164
def new(*args):
@@ -190,4 +200,4 @@ def html_unescape(text):
190200
if __name__ == "__main__":
191201
print freeSpace(".")
192202

193-
print removeChars("ab'cdgdsf''ds'", "'ghd")
203+
print remove_chars("ab'cdgdsf''ds'", "'ghd")

Diff for: module/plugins/hoster/BasePlugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from module.network.HTTPRequest import BadHeader
88
from module.plugins.Hoster import Hoster
9-
from module.utils import html_unescape, removeChars
9+
from module.utils import html_unescape, remove_chars
1010

1111
class BasePlugin(Hoster):
1212
__name__ = "BasePlugin"
@@ -80,7 +80,7 @@ def downloadFile(self, pyfile):
8080
disp = m.groupdict()
8181
self.logDebug(disp)
8282
if not disp['enc']: disp['enc'] = 'utf-8'
83-
name = removeChars(disp['name'], "\"';").strip()
83+
name = remove_chars(disp['name'], "\"';").strip()
8484
name = unicode(unquote(name), disp['enc'])
8585

8686
if not name: name = url

Diff for: module/plugins/hoster/UploadedTo.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import re
44

5-
from module.utils import decode, html_unescape
5+
from module.utils import html_unescape, parseFileSize
66

77
from module.plugins.Hoster import Hoster
88
from module.network.RequestFactory import getURL
99
from module.plugins.Plugin import chunks
1010
from module.plugins.ReCaptcha import ReCaptcha
1111

12-
#key = reduce(lambda x,y: x+chr(y), [(i+2)^ord(x) for i,x in enumerate("jS1\\50}eSm~5i\\cB+$XVB s^/\\mm&JUF")], "")
1312
key = "bGhGMkllZXByd2VEZnU5Y2NXbHhYVlZ5cEE1bkEzRUw=".decode('base64')
1413

1514
def correctDownloadLink(url):
@@ -41,7 +40,7 @@ def getAPIData(urls):
4140

4241
result = {}
4342

44-
if len(api):
43+
if api:
4544
for line in api.splitlines():
4645
data = line.split(",")
4746
if data[1] in idMap:
@@ -60,7 +59,7 @@ def parseFileInfo(self, url = '', html = ''):
6059
found = re.search(self.FILE_INFO_PATTERN, html)
6160
if found:
6261
name, fileid = html_unescape(found.group('N')), found.group('ID')
63-
size = float(found.group('S').replace(',','.')) * 1024 ** {'K':1,'M':2,'G':3}[found.group('U')]
62+
size = parseFileSize(found.group('S'), found.group('U'))
6463
status = 2
6564

6665
return name, size, status, fileid
@@ -114,18 +113,23 @@ def process(self, pyfile):
114113

115114
api = getAPIData([pyfile.url])
116115

117-
if not len(api):
116+
# TODO: fallback to parse from site, because api sometimes delivers wrong status codes
117+
118+
if not api:
118119
self.logWarning("No response for API call")
119120

120121
self.html = unicode(self.load(pyfile.url, decode = False), 'iso-8859-1')
121122
name, size, status, self.fileID = parseFileInfo(self)
122123
self.logDebug(name, size, status, self.fileID)
123124
if status == 1:
124-
self.offline
125+
self.offline()
125126
elif status == 2:
126127
pyfile.name, pyfile.size = name, size
127128
else:
128129
self.fail('Parse error - file info')
130+
elif api == 'Access denied':
131+
self.fail(_("API key invalid"))
132+
129133
else:
130134
if self.fileID not in api:
131135
self.offline()
@@ -138,7 +142,7 @@ def process(self, pyfile):
138142

139143
# self.pyfile.name = self.get_file_name()
140144

141-
if self.account and self.premium:
145+
if self.premium:
142146
self.handlePremium()
143147
else:
144148
self.handleFree()

Diff for: module/plugins/internal/MultiHoster.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import re
55

6-
from module.utils import removeChars
6+
from module.utils import remove_chars
77
from module.plugins.Hook import Hook
88

99
class MultiHoster(Hook):
@@ -49,7 +49,7 @@ def coreReady(self):
4949
new_supported = []
5050

5151
for hoster in self.getHosterCached():
52-
name = removeChars(hoster.lower(), "-.")
52+
name = remove_chars(hoster.lower(), "-.")
5353

5454
if name in pluginMap:
5555
self.supported.append(pluginMap[name])

0 commit comments

Comments
 (0)