summaryrefslogtreecommitdiffstats
path: root/pyload/plugins/accounts/ReloadCc.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-06-09 18:10:22 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-06-09 18:10:23 +0200
commit16af85004c84d0d6c626b4f8424ce9647669a0c1 (patch)
tree025d479862d376dbc17e934f4ed20031c8cd97d1 /pyload/plugins/accounts/ReloadCc.py
parentadapted to jshint config (diff)
downloadpyload-16af85004c84d0d6c626b4f8424ce9647669a0c1.tar.xz
moved everything from module to pyload
Diffstat (limited to 'pyload/plugins/accounts/ReloadCc.py')
-rw-r--r--pyload/plugins/accounts/ReloadCc.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/pyload/plugins/accounts/ReloadCc.py b/pyload/plugins/accounts/ReloadCc.py
new file mode 100644
index 000000000..e4cb32c42
--- /dev/null
+++ b/pyload/plugins/accounts/ReloadCc.py
@@ -0,0 +1,73 @@
+from module.plugins.Account import Account
+
+from module.common.json_layer import json_loads
+
+from module.network.HTTPRequest import BadHeader
+
+class ReloadCc(Account):
+ __name__ = "ReloadCc"
+ __version__ = "0.3"
+ __type__ = "account"
+ __description__ = """Reload.Cc account plugin"""
+
+ __author_name__ = ("Reload Team")
+ __author_mail__ = ("hello@reload.cc")
+
+ def loadAccountInfo(self, user, req):
+
+ # Get user data from reload.cc
+ status = self.getAccountStatus(user, req)
+
+ # Parse account info
+ account_info = {"validuntil": float(status['msg']['expires']),
+ "pwdhash": status['msg']['hash'],
+ "trafficleft": -1}
+
+ return account_info
+
+ def login(self, user, data, req):
+
+ # Get user data from reload.cc
+ status = self.getAccountStatus(user, req)
+
+ if not status:
+ raise Exception("There was an error upon logging in to Reload.cc!")
+
+ # Check if user and password are valid
+ if status['status'] != "ok":
+ self.wrongPassword()
+
+
+ def getAccountStatus(self, user, req):
+ # Use reload.cc API v1 to retrieve account info and return the parsed json answer
+ query_params = dict(
+ via='pyload',
+ v=1,
+ get_traffic='true',
+ user=user
+ )
+
+ try:
+ query_params.update(dict(hash=self.infos[user]['pwdhash']))
+ except Exception:
+ query_params.update(dict(pwd=self.accounts[user]['password']))
+
+ try:
+ answer = req.load("http://api.reload.cc/login", get=query_params)
+ except BadHeader, e:
+ if e.code == 400:
+ raise Exception("There was an unknown error within the Reload.cc plugin.")
+ elif e.code == 401:
+ self.wrongPassword()
+ elif e.code == 402:
+ self.expired(user)
+ elif e.code == 403:
+ raise Exception("Your account is disabled. Please contact the Reload.cc support!")
+ elif e.code == 409:
+ self.empty(user)
+ elif e.code == 503:
+ self.logInfo("Reload.cc is currently in maintenance mode! Please check again later.")
+ self.wrongPassword()
+ return None
+
+ return json_loads(answer)