summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/Utils.py44
-rw-r--r--module/plugins/hoster/BasePlugin.py4
-rw-r--r--module/plugins/hoster/UploadedTo.py18
-rw-r--r--module/plugins/internal/MultiHoster.py4
4 files changed, 42 insertions, 28 deletions
diff --git a/module/Utils.py b/module/Utils.py
index 3919b5ff0..955d14b27 100644
--- a/module/Utils.py
+++ b/module/Utils.py
@@ -25,7 +25,7 @@ def decode(string):
return string
-def removeChars(string, repl):
+def remove_chars(string, repl):
""" removes all chars in repl from string"""
if type(string) == str:
return string.translate(maketrans("", ""), repl)
@@ -35,9 +35,9 @@ def removeChars(string, repl):
def save_path(name):
#remove some chars
if os.name == 'nt':
- return removeChars(name, '/\\?%*:|"<>')
+ return remove_chars(name, '/\\?%*:|"<>')
else:
- return removeChars(name, '/\\"')
+ return remove_chars(name, '/\\"')
def save_join(*args):
""" joins a path, encoding aware """
@@ -134,21 +134,31 @@ def uniqify(seq, idfun=None):
return result
-def parseFileSize(string): #returns bytes
- m = re.match(r"(\d*[\.,]?\d+)(.*)", string.strip().lower())
- if m:
- traffic = float(m.group(1).replace(",", "."))
- unit = m.group(2).strip()
- if unit in ("gb", "gig", "gbyte", "gigabyte", "gib"):
- traffic *= 1 << 30
- elif unit in ("mb", "mbyte", "megabyte", "mib"):
- traffic *= 1 << 20
- elif unit in ("kb", "kib", "kilobyte", "kbyte"):
- traffic *= 1 << 10
- return traffic
+def parseFileSize(string, unit=None): #returns bytes
+ if not unit:
+ m = re.match(r"(\d*[\.,]?\d+)(.*)", string.strip().lower())
+ if m:
+ traffic = float(m.group(1).replace(",", "."))
+ unit = m.group(2)
+ else:
+ return 0
+ else:
+ if isinstance(string, basestring):
+ traffic = float(string.replace(",", "."))
+ else:
+ traffic = string
+
+ #ignore case
+ unit = unit.lower().strip()
- return 0
+ if unit in ("gb", "gig", "gbyte", "gigabyte", "gib", "g"):
+ traffic *= 1 << 30
+ elif unit in ("mb", "mbyte", "megabyte", "mib", "m"):
+ traffic *= 1 << 20
+ elif unit in ("kb", "kib", "kilobyte", "kbyte", "k"):
+ traffic *= 1 << 10
+ return traffic
def lock(func):
def new(*args):
@@ -190,4 +200,4 @@ def html_unescape(text):
if __name__ == "__main__":
print freeSpace(".")
- print removeChars("ab'cdgdsf''ds'", "'ghd")
+ print remove_chars("ab'cdgdsf''ds'", "'ghd")
diff --git a/module/plugins/hoster/BasePlugin.py b/module/plugins/hoster/BasePlugin.py
index 15e35ce24..2de47940d 100644
--- a/module/plugins/hoster/BasePlugin.py
+++ b/module/plugins/hoster/BasePlugin.py
@@ -6,7 +6,7 @@ from urllib import unquote
from module.network.HTTPRequest import BadHeader
from module.plugins.Hoster import Hoster
-from module.utils import html_unescape, removeChars
+from module.utils import html_unescape, remove_chars
class BasePlugin(Hoster):
__name__ = "BasePlugin"
@@ -80,7 +80,7 @@ class BasePlugin(Hoster):
disp = m.groupdict()
self.logDebug(disp)
if not disp['enc']: disp['enc'] = 'utf-8'
- name = removeChars(disp['name'], "\"';").strip()
+ name = remove_chars(disp['name'], "\"';").strip()
name = unicode(unquote(name), disp['enc'])
if not name: name = url
diff --git a/module/plugins/hoster/UploadedTo.py b/module/plugins/hoster/UploadedTo.py
index 7ef39bf57..174c386a8 100644
--- a/module/plugins/hoster/UploadedTo.py
+++ b/module/plugins/hoster/UploadedTo.py
@@ -2,14 +2,13 @@
import re
-from module.utils import decode, html_unescape
+from module.utils import html_unescape, parseFileSize
from module.plugins.Hoster import Hoster
from module.network.RequestFactory import getURL
from module.plugins.Plugin import chunks
from module.plugins.ReCaptcha import ReCaptcha
-#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")], "")
key = "bGhGMkllZXByd2VEZnU5Y2NXbHhYVlZ5cEE1bkEzRUw=".decode('base64')
def correctDownloadLink(url):
@@ -41,7 +40,7 @@ def getAPIData(urls):
result = {}
- if len(api):
+ if api:
for line in api.splitlines():
data = line.split(",")
if data[1] in idMap:
@@ -60,7 +59,7 @@ def parseFileInfo(self, url = '', html = ''):
found = re.search(self.FILE_INFO_PATTERN, html)
if found:
name, fileid = html_unescape(found.group('N')), found.group('ID')
- size = float(found.group('S').replace(',','.')) * 1024 ** {'K':1,'M':2,'G':3}[found.group('U')]
+ size = parseFileSize(found.group('S'), found.group('U'))
status = 2
return name, size, status, fileid
@@ -114,18 +113,23 @@ class UploadedTo(Hoster):
api = getAPIData([pyfile.url])
- if not len(api):
+ # TODO: fallback to parse from site, because api sometimes delivers wrong status codes
+
+ if not api:
self.logWarning("No response for API call")
self.html = unicode(self.load(pyfile.url, decode = False), 'iso-8859-1')
name, size, status, self.fileID = parseFileInfo(self)
self.logDebug(name, size, status, self.fileID)
if status == 1:
- self.offline
+ self.offline()
elif status == 2:
pyfile.name, pyfile.size = name, size
else:
self.fail('Parse error - file info')
+ elif api == 'Access denied':
+ self.fail(_("API key invalid"))
+
else:
if self.fileID not in api:
self.offline()
@@ -138,7 +142,7 @@ class UploadedTo(Hoster):
# self.pyfile.name = self.get_file_name()
- if self.account and self.premium:
+ if self.premium:
self.handlePremium()
else:
self.handleFree()
diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py
index 6f0b4b636..d50df3943 100644
--- a/module/plugins/internal/MultiHoster.py
+++ b/module/plugins/internal/MultiHoster.py
@@ -3,7 +3,7 @@
import re
-from module.utils import removeChars
+from module.utils import remove_chars
from module.plugins.Hook import Hook
class MultiHoster(Hook):
@@ -49,7 +49,7 @@ class MultiHoster(Hook):
new_supported = []
for hoster in self.getHosterCached():
- name = removeChars(hoster.lower(), "-.")
+ name = remove_chars(hoster.lower(), "-.")
if name in pluginMap:
self.supported.append(pluginMap[name])