diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-10-11 03:44:46 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-10-11 03:44:46 +0200 |
commit | 0624be22886c7543e95cee53a7d4b1bdc01bc3b1 (patch) | |
tree | 18cbc2af8a46f0b753a0c3b999bc297a25596e26 /module/plugins/internal | |
parent | [Plugin] Improve error tracing (diff) | |
download | pyload-0624be22886c7543e95cee53a7d4b1bdc01bc3b1.tar.xz |
[XFSAccount] Error handling support
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/Plugin.py | 13 | ||||
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 20 | ||||
-rw-r--r-- | module/plugins/internal/XFSAccount.py | 64 |
3 files changed, 68 insertions, 29 deletions
diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index ab5dcc447..3ad878c1b 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -136,15 +136,14 @@ def str2int(string): def parse_time(string): if re.search("da(il)?y|today", string): - time = seconds_to_midnight() + seconds = seconds_to_midnight() else: - regex = re.compile(r'(\d+| (?:this|an?) )\s*(hr|hour|min|sec|)', re.I) - time = sum((int(v) if v.strip() not in ("this", "a", "an") else 1) * - {'hr': 3600, 'hour': 3600, 'min': 60, 'sec': 1, '': 1}[u.lower()] - for v, u in regex.findall(string)) - - return time + regex = re.compile(r'(\d+| (?:this|an?) )\s*(hr|hour|min|sec|)', re.I) + seconds = sum((int(v) if v.strip() not in ("this", "a", "an") else 1) * + {'hr': 3600, 'hour': 3600, 'min': 60, 'sec': 1, '': 1}[u.lower()] + for v, u in regex.findall(string)) + return seconds #@TODO: Move to utils in 0.4.10 diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 98afe8b4c..744a1f686 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -16,7 +16,7 @@ from module.utils import fixup, fs_encode class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.97" + __version__ = "1.98" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -334,13 +334,16 @@ class SimpleHoster(Hoster): elif self.DL_LIMIT_PATTERN and re.search(self.DL_LIMIT_PATTERN, self.html): m = re.search(self.DL_LIMIT_PATTERN, self.html) try: - errmsg = m.group(1).strip() + errmsg = m.group(1) except (AttributeError, IndexError): - errmsg = m.group(0).strip() + errmsg = m.group(0) - self.info['error'] = re.sub(r'<.*?>', " ", errmsg) - self.log_warning(self.info['error']) + finally: + errmsg = re.sub(r'<.*?>', " ", errmsg.strip()) + + self.info['error'] = errmsg + self.log_warning(errmsg) wait_time = parse_time(errmsg) self.wait(wait_time, reconnect=wait_time > 300) @@ -358,8 +361,11 @@ class SimpleHoster(Hoster): except (AttributeError, IndexError): errmsg = m.group(0).strip() - self.info['error'] = re.sub(r'<.*?>', " ", errmsg) - self.log_warning(self.info['error']) + finally: + errmsg = re.sub(r'<.*?>', " ", errmsg) + + self.info['error'] = errmsg + self.log_warning(errmsg) if re.search('limit|wait|slot', errmsg, re.I): wait_time = parse_time(errmsg) diff --git a/module/plugins/internal/XFSAccount.py b/module/plugins/internal/XFSAccount.py index 75ff4a362..5a6f0ee9c 100644 --- a/module/plugins/internal/XFSAccount.py +++ b/module/plugins/internal/XFSAccount.py @@ -6,13 +6,13 @@ import urlparse from module.plugins.internal.Account import Account # from module.plugins.internal.MultiAccount import MultiAccount -from module.plugins.internal.Plugin import parse_html_form, set_cookie +from module.plugins.internal.Plugin import parse_html_form, parse_time, set_cookie class XFSAccount(Account): __name__ = "XFSAccount" __type__ = "account" - __version__ = "0.51" + __version__ = "0.52" __status__ = "testing" __description__ = """XFileSharing account plugin""" @@ -38,6 +38,7 @@ class XFSAccount(Account): LEECH_TRAFFIC_UNIT = "MB" #: Used only if no group <U> was found LOGIN_FAIL_PATTERN = r'Incorrect Login or Password|account was banned|Error<' + LOGIN_BAN_PATTERN = r'>(Your IP.+?)<a' LOGIN_SKIP_PATTERN = r'op=logout' @@ -63,13 +64,13 @@ class XFSAccount(Account): if not self.PLUGIN_URL: #@TODO: Remove in 0.4.10 return - html = self.load(self.PLUGIN_URL, - get={'op': "my_account"}, - cookies=self.COOKIES) + self.html = self.load(self.PLUGIN_URL, + get={'op': "my_account"}, + cookies=self.COOKIES) - premium = True if re.search(self.PREMIUM_PATTERN, html) else False + premium = True if re.search(self.PREMIUM_PATTERN, self.html) else False - m = re.search(self.VALID_UNTIL_PATTERN, html) + m = re.search(self.VALID_UNTIL_PATTERN, self.html) if m is not None: expiredate = m.group(1).strip() self.log_debug("Expire date: " + expiredate) @@ -92,7 +93,7 @@ class XFSAccount(Account): else: self.log_debug("VALID_UNTIL_PATTERN not found") - m = re.search(self.TRAFFIC_LEFT_PATTERN, html) + m = re.search(self.TRAFFIC_LEFT_PATTERN, self.html) if m is not None: try: traffic = m.groupdict() @@ -120,7 +121,7 @@ class XFSAccount(Account): else: self.log_debug("TRAFFIC_LEFT_PATTERN not found") - leech = [m.groupdict() for m in re.finditer(self.LEECH_TRAFFIC_PATTERN, html)] + leech = [m.groupdict() for m in re.finditer(self.LEECH_TRAFFIC_PATTERN, self.html)] if leech: leechtraffic = 0 try: @@ -167,12 +168,12 @@ class XFSAccount(Account): if not self.LOGIN_URL: self.LOGIN_URL = urlparse.urljoin(self.PLUGIN_URL, "login.html") - html = self.load(self.LOGIN_URL, cookies=self.COOKIES) + self.html = self.load(self.LOGIN_URL, cookies=self.COOKIES) - if re.search(self.LOGIN_SKIP_PATTERN, html): + if re.search(self.LOGIN_SKIP_PATTERN, self.html): self.skip_login() - action, inputs = parse_html_form('name="FL"', html) + action, inputs = parse_html_form('name="FL"', self.html) if not inputs: inputs = {'op' : "login", 'redirect': self.PLUGIN_URL} @@ -185,7 +186,40 @@ class XFSAccount(Account): else: url = self.LOGIN_URL - html = self.load(url, post=inputs, cookies=self.COOKIES) + self.html = self.load(url, post=inputs, cookies=self.COOKIES) - if re.search(self.LOGIN_FAIL_PATTERN, html): - self.fail_login() + self.check_errors() + + + def check_errors(self): + if not self.html: + self.log_warning(_("No html code to check")) + return + + m = re.search(self.LOGIN_BAN_PATTERN, self.html) + if m is not None: + try: + errmsg = m.group(1) + + except (AttributeError, IndexError): + errmsg = m.group(0) + + finally: + errmsg = re.sub(r'<.*?>', " ", errmsg.strip()) + + self.timeout = parse_time(errmsg) + self.fail_login(errmsg) + + m = re.search(self.LOGIN_FAIL_PATTERN, self.html) + if m is not None: + try: + errmsg = m.group(1) + + except (AttributeError, IndexError): + errmsg = m.group(0) + + finally: + errmsg = re.sub(r'<.*?>', " ", errmsg.strip()) + + self.timeout = self.LOGIN_TIMEOUT + self.fail_login(errmsg) |