diff options
author | Pedro Algarvio <pedro@algarvio.me> | 2012-02-04 04:06:15 +0100 |
---|---|---|
committer | Pedro Algarvio <pedro@algarvio.me> | 2012-02-04 04:06:15 +0100 |
commit | a0ebf8d7a70fde61c754af2f146abc3d9b3511f9 (patch) | |
tree | 9201d95bd60cea72873eab62d6592400048ae0df /module/plugins | |
parent | Correct import. (diff) | |
download | pyload-a0ebf8d7a70fde61c754af2f146abc3d9b3511f9.tar.xz |
Add helper method `formatTrafficleft()` to `module.plugins.Account`.
Regarding Oron account and hoster plugins, make use of `formatSize`, `parseFileSize` and the `Account`'s `formatTrafficleft()` helper method.
Diffstat (limited to 'module/plugins')
-rw-r--r-- | module/plugins/Account.py | 5 | ||||
-rwxr-xr-x | module/plugins/accounts/OronCom.py | 3 | ||||
-rwxr-xr-x | module/plugins/hoster/OronCom.py | 15 |
3 files changed, 12 insertions, 11 deletions
diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 780a8ee69..d30f6920c 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -4,7 +4,7 @@ from time import time from traceback import print_exc from threading import RLock -from module.utils import compare_time, parseFileSize, lock, from_string +from module.utils import compare_time, formatSize, parseFileSize, lock, from_string from module.Api import AccountInfo from module.network.CookieJar import CookieJar @@ -241,6 +241,9 @@ class Account(Base, AccountInfo): def parseTraffic(self, string): #returns kbyte return parseFileSize(string) / 1024 + def formatTrafficleft(self): + return formatSize(self.trafficleft*1024) + def wrongPassword(self): raise WrongPassword diff --git a/module/plugins/accounts/OronCom.py b/module/plugins/accounts/OronCom.py index 1fe8a4449..2c1d33162 100755 --- a/module/plugins/accounts/OronCom.py +++ b/module/plugins/accounts/OronCom.py @@ -20,6 +20,7 @@ from module.plugins.Account import Account import re from time import strptime, mktime +from module.utils import formatSize, parseFileSize class OronCom(Account): __name__ = "OronCom" @@ -37,7 +38,7 @@ class OronCom(Account): validuntil = validuntil.group(1) validuntil = int(mktime(strptime(validuntil, "%d %B %Y"))) trafficleft = re.search(r'<td>Download Traffic verfügbar:</td>\s*<td>(.*?)</td>', src).group(1) - self.logDebug("Oron left: " + trafficleft) + self.logDebug("Oron left: " + formatSize(parseFileSize(trafficleft))) trafficleft = int(self.parseTraffic(trafficleft)) premium = True else: diff --git a/module/plugins/hoster/OronCom.py b/module/plugins/hoster/OronCom.py index 120aa8ff4..e0be91486 100755 --- a/module/plugins/hoster/OronCom.py +++ b/module/plugins/hoster/OronCom.py @@ -4,6 +4,7 @@ import re from module.plugins.Hoster import Hoster from module.network.RequestFactory import getURL from module.plugins.ReCaptcha import ReCaptcha +from module.utils import parseFileSize def getInfo(urls): result = [] @@ -18,9 +19,7 @@ def getInfo(urls): m = re.search(OronCom.FILE_INFO_PATTERN, html) if m: name = m.group(1) - hSize = float(m.group(2).replace(",", ".")) - pow = {'Kb': 1, 'Mb': 2, 'Gb': 3}[m.group(3)] - size = int(hSize * 1024 ** pow) + size = parseFileSize(m.group(2), m.group(3)) else: name = url size = 0 @@ -57,10 +56,8 @@ class OronCom(Hoster): m = re.search(self.FILE_INFO_PATTERN, self.html) if m: pyfile.name = m.group(1) - hSize = float(m.group(2)) - pow = {'Kb': 1, 'Mb': 2, 'Gb': 3}[m.group(3)] - pyfile.size = int(hSize * 1024 ** pow) - self.logDebug("File Size: %d" % pyfile.size) + pyfile.size = parseFileSize(m.group(2), m.group(3)) + self.logDebug("File Size: %s" % pyfile.formatSize()) else: self.logDebug("Name and/or size not found.") @@ -130,8 +127,8 @@ class OronCom(Hoster): def handlePremium(self): self.account.getAccountInfo(True) - self.logDebug("Traffic left: %s" % self.account.trafficleft) - self.logDebug("File Size: %d" % int(self.pyfile.size / 1024)) + self.logDebug("Traffic left: %s" % self.account.formatTrafficleft()) + self.logDebug("File Size: %s" % self.pyfile.formatSize()) if int(self.pyfile.size / 1024) > self.account.trafficleft: self.logInfo(_("Not enough traffic left")) |