diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/internal/Hoster.py | 2 | ||||
-rw-r--r-- | module/plugins/internal/Plugin.py | 46 | ||||
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 21 |
3 files changed, 48 insertions, 21 deletions
diff --git a/module/plugins/internal/Hoster.py b/module/plugins/internal/Hoster.py index ea5a3cb29..26da436a5 100644 --- a/module/plugins/internal/Hoster.py +++ b/module/plugins/internal/Hoster.py @@ -2,8 +2,8 @@ from __future__ import with_statement -import re import os +import re from module.plugins.internal.Base import Base, check_abort, create_getInfo, getInfo, parse_fileInfo from module.plugins.internal.Plugin import Fail, Retry, encode, exists, fixurl, parse_name diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 4546186d4..24cff70c3 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -54,7 +54,6 @@ def exists(path): return False -#@TODO: Recheck in 0.4.10 def fixurl(url, unquote=None): newurl = urllib.unquote(url) @@ -62,7 +61,7 @@ def fixurl(url, unquote=None): unquote = newurl == url newurl = html_unescape(newurl.decode('unicode-escape')) - newurl = re.sub(r'/{2,}', '/', newurl).strip().lstrip('.') + newurl = re.sub(r'[^:]/{2,}', '/', newurl).strip().lstrip('.') if not unquote: newurl = urllib.quote(newurl) @@ -70,7 +69,6 @@ def fixurl(url, unquote=None): return newurl -#@TODO: Recheck in 0.4.10 def parse_name(string): path = fixurl(decode(string), unquote=False) url_p = urlparse.urlparse(path.rstrip('/')) @@ -82,6 +80,46 @@ def parse_name(string): #@TODO: Move to utils in 0.4.10 +def str2int(string): + try: + return int(string) + except: + pass + + ones = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", + "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", + "sixteen", "seventeen", "eighteen", "nineteen"] + tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", + "eighty", "ninety"] + + o_tuple = [(w, i) for i, w in enumerate(ones)] + t_tuple = [(w, i * 10) for i, w in enumerate(tens)] + + numwords = dict(o_tuple + t_tuple) + tokens = re.split(r"[\s-]+", string.lower()) + + try: + return sum(numwords[word] for word in tokens) + except: + return 0 + + +def parse_time(string): + if re.search("da(il)?y|today", string): + time = seconds_to_midnight() + + else: + this = re.compile("this", re.I) + regex = re.compile(r'(\d+|\w+)\s*(hr|hour|min|sec|)', re.I) + + time = sum(1 if this.match(v) else str2int(v) * + {'hr': 3600, 'hour': 3600, 'min': 60, 'sec': 1, '': 1}[u.lower()] + for v, u in regex.findall(string)) + + return time + + +#@TODO: Move to utils in 0.4.10 def timestamp(): return int(time.time() * 1000) @@ -190,7 +228,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.42" + __version__ = "0.43" __status__ = "testing" __pattern__ = r'^unmatchable$' diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 5d2307d51..3a3e44619 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -9,14 +9,14 @@ import time from module.network.HTTPRequest import BadHeader from module.network.RequestFactory import getURL as get_url from module.plugins.internal.Hoster import Hoster, create_getInfo, parse_fileInfo -from module.plugins.internal.Plugin import Fail, encode, parse_name, replace_patterns, seconds_to_midnight, set_cookie, set_cookies +from module.plugins.internal.Plugin import Fail, encode, parse_name, parse_time, replace_patterns, seconds_to_midnight, set_cookie, set_cookies from module.utils import fixup, fs_encode, parseFileSize as parse_size class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.90" + __version__ = "1.91" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -352,12 +352,7 @@ class SimpleHoster(Hoster): self.info['error'] = re.sub(r'<.*?>', " ", errmsg) self.log_warning(self.info['error']) - if re.search('da(il)?y|today', errmsg, re.I): - wait_time = seconds_to_midnight() - else: - wait_time = sum(int(v) * {'hr': 3600, 'hour': 3600, 'min': 60, 'sec': 1, "": 1}[u.lower()] for v, u in - re.findall(r'(\d+)\s*(hr|hour|min|sec|)', errmsg, re.I)) - + wait_time = parse_time(errmsg) self.wantReconnect = wait_time > 300 self.retry(1, wait_time, _("Download limit exceeded")) @@ -377,12 +372,7 @@ class SimpleHoster(Hoster): self.log_warning(self.info['error']) if re.search('limit|wait|slot', errmsg, re.I): - if re.search("da(il)?y|today", errmsg): - wait_time = seconds_to_midnight() - else: - wait_time = sum(int(v) * {'hr': 3600, 'hour': 3600, 'min': 60, 'sec': 1, "": 1}[u.lower()] for v, u in - re.findall(r'(\d+)\s*(hr|hour|min|sec|)', errmsg, re.I)) - + wait_time = parse_time(errmsg) self.wantReconnect = wait_time > 300 self.retry(1, wait_time, _("Download limit exceeded")) @@ -423,8 +413,7 @@ class SimpleHoster(Hoster): except (AttributeError, IndexError): waitmsg = m.group(0).strip() - wait_time = sum(int(v) * {'hr': 3600, 'hour': 3600, 'min': 60, 'sec': 1, "": 1}[u.lower()] for v, u in - re.findall(r'(\d+)\s*(hr|hour|min|sec|)', waitmsg, re.I)) + wait_time = parse_time(waitmsg) self.wait(wait_time, wait_time > 300) self.info.pop('error', None) |