summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nils Hesse <nphesse@gmail.com> 2013-02-13 22:09:05 +0100
committerGravatar Nils Hesse <nphesse@gmail.com> 2013-02-13 22:09:05 +0100
commit883371e41d81cc45abd986a50610d04026ed71c6 (patch)
tree7afc5c942446e67e05a9305735c226412e7a4adf
parentclosed #760 (diff)
downloadpyload-883371e41d81cc45abd986a50610d04026ed71c6.tar.xz
Enable better error handling for the Reload.cc plugin
-rw-r--r--module/plugins/accounts/ReloadCc.py38
-rw-r--r--module/plugins/hoster/ReloadCc.py68
2 files changed, 74 insertions, 32 deletions
diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py
index e0eb5df6e..0916499e8 100644
--- a/module/plugins/accounts/ReloadCc.py
+++ b/module/plugins/accounts/ReloadCc.py
@@ -2,20 +2,22 @@ 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.2"
__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'],
@@ -24,15 +26,18 @@ class ReloadCc(Account):
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(
@@ -47,5 +52,22 @@ class ReloadCc(Account):
except Exception:
query_params.update(dict(pwd=self.accounts[user]['password']))
- answer = req.load("https://api.reload.cc/login", get=query_params)
- return json_loads(answer) \ No newline at end of file
+ try:
+ answer = req.load("http://api.reload.cc/login", get=query_params)
+ except BadHeader as 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)
diff --git a/module/plugins/hoster/ReloadCc.py b/module/plugins/hoster/ReloadCc.py
index 7c171befe..a038594dc 100644
--- a/module/plugins/hoster/ReloadCc.py
+++ b/module/plugins/hoster/ReloadCc.py
@@ -2,15 +2,17 @@ from module.plugins.Hoster import Hoster
from module.common.json_layer import json_loads
+from module.network.HTTPRequest import BadHeader
+
class ReloadCc(Hoster):
__name__ = "ReloadCc"
__version__ = "0.2"
__type__ = "hoster"
__description__ = """Reload.Cc hoster plugin"""
-
+
# Since we want to allow the user to specify the list of hoster to use we let MultiHoster.coreReady create the regex patterns for us using getHosters in our ReloadCc hook.
__pattern__ = None
-
+
__author_name__ = ("Reload Team")
__author_mail__ = ("hello@reload.cc")
@@ -19,10 +21,10 @@ class ReloadCc(Hoster):
if not self.account or not self.account.canUse():
self.logError("Please enter a valid reload.cc account or deactivate this plugin")
self.fail("No valid reload.cc account provided")
-
+
# In some cases hostsers do not supply us with a filename at download, so we are going to set a fall back filename (e.g. for freakshare or xfileshare)
self.pyfile.name = self.pyfile.name.split('/').pop() # Remove everthing before last slash
-
+
# Correction for automatic assigned filename: Removing html at end if needed
suffix_to_remove = ["html", "htm", "php", "php3", "asp", "shtm", "shtml", "cfml", "cfm"]
temp = self.pyfile.name.split('.')
@@ -44,29 +46,47 @@ class ReloadCc(Hoster):
except Exception:
query_params.update(dict(pwd=data['password']))
- # Get rewritten link using the reload.cc api v1
- answer = self.load("https://api.reload.cc/dl", get=query_params)
+ try:
+ answer = self.load("https://api.reload.cc/dl", get=query_params)
+ except BadHeader as e:
+ if e.code == 400:
+ self.fail("The URI is not supported by Reload.cc.")
+ elif e.code == 401:
+ self.fail("Wrong username or password")
+ elif e.code == 402:
+ self.fail("Your account is inactive. A payment is required for downloading!")
+ elif e.code == 403:
+ self.fail("Your account is disabled. Please contact the Reload.cc support!")
+ elif e.code == 409:
+ self.logWarning("The hoster seems to be a limited hoster and you've used your daily traffic for this hoster: %s" % self.pyfile.url)
+ # Wait for 6 hours and retry up to 4 times => one day
+ self.retry(max_retries=4, wait_time=(3600 * 6), reason="Limited hoster traffic limit exceeded")
+ elif e.code == 429:
+ self.retry(max_retries=5, wait_time=120, reason="Too many concurrent connections") # Too many connections, wait 2 minutes and try again
+ elif e.code == 503:
+ self.retry(wait_time=600, reason="Reload.cc is currently in maintenance mode! Please check again later.") # Retry in 10 minutes
+ else:
+ self.fail("Internal error within Reload.cc. Please contact the Reload.cc support for further information.")
+ return
+
data = json_loads(answer)
# Check status and decide what to do
status = data['status']
if status == "ok":
- self.download(data['link'], disposition=True)
- elif status == 400:
- self.fail("Unsupported URI")
- elif status == 401:
- self.fail("Invalid login")
- elif status == 402:
- self.fail("Payment required")
- elif status == 403:
- self.fail("User is disabled")
- elif status == 404:
- self.offline()
- elif status == 409:
- self.fail("Fairuse traffic exceeded")
- elif status == 428:
- self.fail("Hoster currently not possible")
- elif status >= 500:
- self.tempOffline()
+ try:
+ self.download(data['link'], disposition=True)
+ except BadHeader as e:
+ if e.code == 404:
+ self.fail("File Not Found")
+ elif e.code == 412:
+ self.fail("File access password is wrong")
+ elif e.code == 417:
+ self.fail("Password required for file access")
+ elif e.code == 429:
+ self.retry(max_retries=5, wait_time=120, reason="Too many concurrent connections") # Too many connections, wait 2 minutes and try again
+ else:
+ self.fail("Internal error within Reload.cc. Please contact the Reload.cc support for further information.")
+ return
else:
- self.fail(data['msg'])
+ self.fail("Internal error within Reload.cc. Please contact the Reload.cc support for further information.")