summaryrefslogtreecommitdiffstats
path: root/module/plugins/accounts/ZeveraCom.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/accounts/ZeveraCom.py')
-rw-r--r--module/plugins/accounts/ZeveraCom.py84
1 files changed, 54 insertions, 30 deletions
diff --git a/module/plugins/accounts/ZeveraCom.py b/module/plugins/accounts/ZeveraCom.py
index 11a224039..15b6d9379 100644
--- a/module/plugins/accounts/ZeveraCom.py
+++ b/module/plugins/accounts/ZeveraCom.py
@@ -6,49 +6,73 @@ from module.plugins.Account import Account
class ZeveraCom(Account):
- __name__ = "ZeveraCom"
- __version__ = "0.21"
- __type__ = "account"
+ __name__ = "ZeveraCom"
+ __type__ = "account"
+ __version__ = "0.25"
__description__ = """Zevera.com account plugin"""
- __author_name__ = "zoidberg"
- __author_mail__ = "zoidberg@mujmail.cz"
+ __license__ = "GPLv3"
+ __authors__ = [("zoidberg", "zoidberg@mujmail.cz"),
+ ("Walter Purcaro", "vuolter@gmail.com")]
+
+
+ HOSTER_DOMAIN = "zevera.com"
+
+
+ def __init__(self, manager, accounts): #@TODO: remove in 0.4.10
+ self.init()
+ return super(ZeveraCom, self).__init__(manager, accounts)
+
+
+ def init(self):
+ if not self.HOSTER_DOMAIN:
+ self.logError(_("Missing HOSTER_DOMAIN"))
+
+ if not hasattr(self, "API_URL"):
+ self.API_URL = "http://api.%s/jDownloader.ashx" % (self.HOSTER_DOMAIN or "")
def loadAccountInfo(self, user, req):
- data = self.getAPIData(req)
- if data == "No traffic":
- account_info = {"trafficleft": 0, "validuntil": 0, "premium": False}
- else:
- account_info = {
- "trafficleft": int(data['availabletodaytraffic']) * 1024,
- "validuntil": mktime(strptime(data['endsubscriptiondate'], "%Y/%m/%d %H:%M:%S")),
- "premium": True
- }
- return account_info
+ validuntil = None
+ trafficleft = None
+ premium = False
+
+ api = self.api_response(req)
+
+ if "No trafic" not in api or "Expired" not in api:
+ validuntil = mktime(strptime(api['endsubscriptiondate'], "%Y/%m/%d %H:%M:%S"))
+ trafficleft = float(api['availabletodaytraffic']) * 1024 if api['orondaytrafficlimit'] != '0' else -1
+ premium = True
+
+ return {'validuntil': validuntil, 'trafficleft': trafficleft, 'premium': premium}
+
def login(self, user, data, req):
- self.loginname = user
+ self.user = user
self.password = data['password']
- if self.getAPIData(req) == "No traffic":
+
+ if self.api_response(req) == "No trafic":
self.wrongPassword()
- def getAPIData(self, req, just_header=False, **kwargs):
- get_data = {
- 'cmd': 'accountinfo',
- 'login': self.loginname,
- 'pass': self.password
- }
+
+ def api_response(self, req, just_header=False, **kwargs):
+ get_data = {'cmd' : "accountinfo",
+ 'login': self.user,
+ 'pass' : self.password}
+
get_data.update(kwargs)
- response = req.load("http://www.zevera.com/jDownloader.ashx", get=get_data,
- decode=True, just_header=just_header)
- self.logDebug(response)
+ res = req.load(self.API_URL,
+ get=get_data,
+ just_header=just_header,
+ decode=True)
+
+ self.logDebug(res)
- if ':' in response:
+ if ':' in res:
if not just_header:
- response = response.replace(',', '\n')
+ res = res.replace(',', '\n')
return dict((y.strip().lower(), z.strip()) for (y, z) in
- [x.split(':', 1) for x in response.splitlines() if ':' in x])
+ [x.split(':', 1) for x in res.splitlines() if ':' in x])
else:
- return response
+ return res