From 45feced4c09605dc5e80c4d96e2a4c5e9ee416d4 Mon Sep 17 00:00:00 2001 From: GammaC0de Date: Wed, 26 Aug 2015 15:32:53 +0300 Subject: Update Plugin.py --- module/plugins/internal/Plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 7b45c40a8..8bc5d4a65 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -7,6 +7,7 @@ import inspect import os import re import urllib +import sys if os.name != "nt": import grp @@ -146,7 +147,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "hoster" - __version__ = "0.30" + __version__ = "0.32" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -345,7 +346,7 @@ class Plugin(object): #@TODO: Move to network in 0.4.10 if isinstance(decode, basestring): - res = decode(res, decode) + res = sys.modules[__name__].decode(res, decode) #@TODO: See #1787, use utils.decode() in 0.4.10 if self.pyload.debug: frame = inspect.currentframe() -- cgit v1.2.3 From f44acc14fc6492f9fefbc707618c774d34ac1aeb Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 30 Aug 2015 03:38:54 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1793 --- module/plugins/internal/Plugin.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 7b45c40a8..1e04d388e 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -54,6 +54,26 @@ def fixurl(url): #@TODO: Move to utils in 0.4.10 def timestamp(): return int(time.time() * 1000) + + +#@TODO: Move to utils in 0.4.10 +def which(program): + """ + Works exactly like the unix command which + Courtesy of http://stackoverflow.com/a/377028/675646 + """ + isExe = lambda x: os.path.isfile(x) and os.access(x, os.X_OK) + + fpath, fname = os.path.split(program) + + if fpath: + if isExe(program): + return program + else: + for path in os.environ['PATH'].split(os.pathsep): + exe_file = os.path.join(path.strip('"'), program) + if isExe(exe_file): + return exe_file def seconds_to_midnight(gmt=0): @@ -146,7 +166,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "hoster" - __version__ = "0.30" + __version__ = "0.31" __status__ = "testing" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 4cd2b7390dd97dc2016ab71f954f191de12f2f46 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 3 Sep 2015 20:37:17 +0200 Subject: Spare fixes (2) --- module/plugins/internal/Plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 1e04d388e..b0c0bb66e 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -54,9 +54,9 @@ def fixurl(url): #@TODO: Move to utils in 0.4.10 def timestamp(): return int(time.time() * 1000) - - -#@TODO: Move to utils in 0.4.10 + + +#@TODO: Move to utils in 0.4.10 def which(program): """ Works exactly like the unix command which -- cgit v1.2.3 From 6e6d464f35609828a14dcc09e4045b56686eb90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Broz=CC=8C?= Date: Sun, 13 Sep 2015 08:53:26 +0200 Subject: Remove accents from file name #1817 issue: #1817 --- module/plugins/internal/Plugin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index b0c0bb66e..fd8712b44 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -7,6 +7,7 @@ import inspect import os import re import urllib +import unicodedata if os.name != "nt": import grp @@ -51,6 +52,15 @@ def fixurl(url): return html_unescape(urllib.unquote(url.decode('unicode-escape'))).strip().rstrip('/') +def fixname(m): + m = unicodedata.normalize('NFKD', m) + output = '' + for c in m: + if not unicodedata.combining(c): + output += c + return output + + #@TODO: Move to utils in 0.4.10 def timestamp(): return int(time.time() * 1000) -- cgit v1.2.3 From f23c2ed39b842c115751937ebc3d1b1138a9ad88 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 19 Sep 2015 06:48:27 +0200 Subject: [XFSAccount] Update --- module/plugins/internal/Plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index fd8712b44..fc05e2a5b 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -354,7 +354,7 @@ class Plugin(object): url = fixurl(url) if not url or not isinstance(url, basestring): - self.fail(_("No url given")) + self.fail(_("No given url")) if self.pyload.debug: self.log_debug("LOAD URL " + url, -- cgit v1.2.3 From 59d2ad3541bf133ddd69fd3b7c633e7e226e4829 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 21 Sep 2015 01:08:35 +0200 Subject: Spare improvements and fixes --- module/plugins/internal/Plugin.py | 41 +++++++++++++++------------------------ 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index feabe9f1d..e4c16846c 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -6,8 +6,9 @@ import datetime import inspect import os import re -import urllib import sys +import urllib +import unicodedata if os.name != "nt": import grp @@ -23,7 +24,7 @@ def decode(string, encoding='utf8'): if type(string) is str: return string.decode(encoding, "replace") else: - return string + return unicode(string) #@TODO: Move to utils in 0.4.10 @@ -32,7 +33,7 @@ def encode(string, encoding='utf8'): if type(string) is unicode: return string.encode(encoding, "replace") else: - return string + return str(string) #@TODO: Move to utils in 0.4.10 @@ -175,8 +176,8 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" - __type__ = "hoster" - __version__ = "0.32" + __type__ = "plugin" + __version__ = "0.33" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -195,6 +196,11 @@ class Plugin(object): self.init() + def __repr__(self): + return "<%(type)s %(name)s>" % {'type': self.__type__.capitalize() + 'name': self.__name__} + + def _init(self, core): self.pyload = core self.info = {} #: Provide information in dict here @@ -210,11 +216,10 @@ class Plugin(object): def _log(self, level, plugintype, pluginname, messages): log = getattr(self.pyload.log, level) - msg = encode(" | ".join((a if isinstance(a, basestring) else str(a)).strip() for a in messages if a)) - log("%(plugintype)s %(pluginname)s%(id)s: %(msg)s" + msg = " | ".join(encode(a).strip() for a in messages if a) + log("%(plugintype)s %(pluginname)s%: %(msg)s" % {'plugintype': plugintype.upper(), 'pluginname': pluginname, - 'id' : ("[%s]" % self.pyfile.id) if hasattr(self, 'pyfile') else "", 'msg' : msg}) @@ -317,21 +322,10 @@ class Plugin(object): self.pyload.db.delStorage(self.__name__, key) - def fail(self, reason): + def fail(self, msg): """ - Fail and give reason + Fail and give msg """ - raise Fail(encode(reason)) #@TODO: Remove `encode` in 0.4.10 - - - def error(self, reason="", type=_("Parse")): - if not reason: - type = _("Unknown") - - msg = _("%s error") % type.strip().capitalize() if type else _("Error") - msg += (": %s" % reason.strip()) if reason else "" - msg += _(" | Plugin may be out of date") - raise Fail(encode(msg)) #@TODO: Remove `encode` in 0.4.10 @@ -348,9 +342,6 @@ class Plugin(object): :param decode: Wether to decode the output according to http header, should be True in most cases :return: Loaded content """ - if hasattr(self, 'pyfile') and self.pyfile.abort: - self.abort() - url = fixurl(url) if not url or not isinstance(url, basestring): @@ -375,7 +366,7 @@ class Plugin(object): #@TODO: Move to network in 0.4.10 if isinstance(decode, basestring): - res = sys.modules[__name__].decode(res, decode) #@TODO: See #1787, use utils.decode() in 0.4.10 + res = sys.modules[self.__name__].decode(res, decode) #@TODO: See #1787, use utils.decode() in 0.4.10 if self.pyload.debug: frame = inspect.currentframe() -- cgit v1.2.3 From af896302d7701e2bc63b1523b9ea73f38f5201c8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 21 Sep 2015 14:01:21 +0200 Subject: Fix pyfile.name processing --- module/plugins/internal/Plugin.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index e4c16846c..9494d34a6 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -7,8 +7,9 @@ import inspect import os import re import sys -import urllib import unicodedata +import urllib +import urlparse if os.name != "nt": import grp @@ -49,17 +50,19 @@ def exists(path): #@TODO: Move to utils in 0.4.10 -def fixurl(url): - return html_unescape(urllib.unquote(url.decode('unicode-escape'))).strip().rstrip('/') +def parse_name(url): + url = urllib.unquote(url) + url = url.decode('unicode-escape') + url = html_unescape(url) + url = urllib.quote(url) + + url_p = urlparse.urlparse(url.strip().rstrip('/')) + name = (url_p.path.split('/')[-1] or + url_p.query.split('=', 1)[::-1][0].split('&', 1)[0] or + url_p.netloc.split('.', 1)[0]) -def fixname(m): - m = unicodedata.normalize('NFKD', m) - output = '' - for c in m: - if not unicodedata.combining(c): - output += c - return output + return urllib.unquote(name) #@TODO: Move to utils in 0.4.10 @@ -177,7 +180,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.33" + __version__ = "0.34" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -342,11 +345,6 @@ class Plugin(object): :param decode: Wether to decode the output according to http header, should be True in most cases :return: Loaded content """ - url = fixurl(url) - - if not url or not isinstance(url, basestring): - self.fail(_("No given url")) - if self.pyload.debug: self.log_debug("LOAD URL " + url, *["%s=%s" % (key, val) for key, val in locals().items() if key not in ("self", "url")]) -- cgit v1.2.3 From f9fc367427e30b7a3ca2ccad6144cb76b21f0257 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 21 Sep 2015 14:36:22 +0200 Subject: Spare code cosmetics --- module/plugins/internal/Plugin.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 9494d34a6..bbccaa48d 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -410,6 +410,7 @@ class Plugin(object): """ try: self.req.close() + except Exception: pass -- cgit v1.2.3 From fb45ec44220201268f99b747831df717fa7a83f8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 21 Sep 2015 16:31:48 +0200 Subject: [Account] Fix __version__ --- module/plugins/internal/Plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index bbccaa48d..118b68812 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -200,7 +200,7 @@ class Plugin(object): def __repr__(self): - return "<%(type)s %(name)s>" % {'type': self.__type__.capitalize() + return "<%(type)s %(name)s>" % {'type': self.__type__.capitalize(), 'name': self.__name__} @@ -220,7 +220,7 @@ class Plugin(object): def _log(self, level, plugintype, pluginname, messages): log = getattr(self.pyload.log, level) msg = " | ".join(encode(a).strip() for a in messages if a) - log("%(plugintype)s %(pluginname)s%: %(msg)s" + log("%(plugintype)s %(pluginname)s: %(msg)s" % {'plugintype': plugintype.upper(), 'pluginname': pluginname, 'msg' : msg}) -- cgit v1.2.3 From 34244c7a49b099d30456e0bd80cf26a2be3a3208 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 21 Sep 2015 23:35:58 +0200 Subject: Spare improvements and fixes (2) --- module/plugins/internal/Plugin.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 118b68812..e9964b11d 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -7,9 +7,8 @@ import inspect import os import re import sys -import unicodedata +import traceback import urllib -import urlparse if os.name != "nt": import grp @@ -180,7 +179,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.34" + __version__ = "0.35" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -227,24 +226,31 @@ class Plugin(object): def log_debug(self, *args): - if self.pyload.debug: - return self._log("debug", self.__type__, self.__name__, args) + if not self.pyload.debug: + return + self._log("debug", self.__type__, self.__name__, args) def log_info(self, *args): - return self._log("info", self.__type__, self.__name__, args) + self._log("info", self.__type__, self.__name__, args) def log_warning(self, *args): - return self._log("warning", self.__type__, self.__name__, args) + self._log("warning", self.__type__, self.__name__, args) + if self.pyload.debug: + traceback.print_exc() def log_error(self, *args): - return self._log("error", self.__type__, self.__name__, args) + self._log("error", self.__type__, self.__name__, args) + if self.pyload.debug: + traceback.print_exc() def log_critical(self, *args): return self._log("critical", self.__type__, self.__name__, args) + if self.pyload.debug: + traceback.print_exc() def set_permissions(self, path): -- cgit v1.2.3 From 5748b8ed8222dac07e9d40ce582ca7f8ae591cb8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 22 Sep 2015 00:33:01 +0200 Subject: Auto-detect seconds_to_midnight --- module/plugins/internal/Plugin.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index e9964b11d..b651079c2 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -89,22 +89,15 @@ def which(program): return exe_file -def seconds_to_midnight(gmt=0): - now = datetime.datetime.utcnow() + datetime.timedelta(hours=gmt) - - if now.hour == 0 and now.minute < 10: - midnight = now +def seconds_to_midnight(gmt=None): + if gmt is None: + now = datetime.datetime.today() else: - midnight = now + datetime.timedelta(days=1) - - td = midnight.replace(hour=0, minute=10, second=0, microsecond=0) - now + now = datetime.datetime.utcnow() + datetime.timedelta(hours=gmt) - if hasattr(td, 'total_seconds'): - res = td.total_seconds() - else: #@NOTE: work-around for python 2.5 and 2.6 missing datetime.timedelta.total_seconds - res = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + midnight = now.replace(hour=0, minute=10, second=0, microsecond=0) + datetime.timedelta(days=1) - return int(res) + return (midnight - now).seconds def replace_patterns(string, ruleslist): -- cgit v1.2.3 From 553538287293b8a52eee41f28d57d0b4ae1003aa Mon Sep 17 00:00:00 2001 From: GammaC0de Date: Tue, 22 Sep 2015 01:57:37 +0300 Subject: [Plugin] fix missing import --- module/plugins/internal/Plugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index b651079c2..47648e2fb 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -9,6 +9,7 @@ import re import sys import traceback import urllib +import urlparse if os.name != "nt": import grp @@ -172,7 +173,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.35" + __version__ = "0.36" __status__ = "testing" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From fa5e570bfa4439812b4329f43d6a49e0b5239641 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 22 Sep 2015 03:20:25 +0200 Subject: [Plugin] Fix _log + code cosmetics --- module/plugins/internal/Plugin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 47648e2fb..f6f7258fa 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -90,11 +90,11 @@ def which(program): return exe_file -def seconds_to_midnight(gmt=None): - if gmt is None: +def seconds_to_midnight(utc=None): + if utc is None: now = datetime.datetime.today() else: - now = datetime.datetime.utcnow() + datetime.timedelta(hours=gmt) + now = datetime.datetime.utcnow() + datetime.timedelta(hours=utc) midnight = now.replace(hour=0, minute=10, second=0, microsecond=0) + datetime.timedelta(days=1) @@ -212,7 +212,7 @@ class Plugin(object): def _log(self, level, plugintype, pluginname, messages): log = getattr(self.pyload.log, level) - msg = " | ".join(encode(a).strip() for a in messages if a) + msg = u" | ".join(decode(a).strip() for a in messages if a) log("%(plugintype)s %(pluginname)s: %(msg)s" % {'plugintype': plugintype.upper(), 'pluginname': pluginname, -- cgit v1.2.3 From 96ce21ce760a6d4601d904446a639b1bef20bc6e Mon Sep 17 00:00:00 2001 From: GammaC0de Date: Tue, 22 Sep 2015 15:47:34 +0300 Subject: version up --- module/plugins/internal/Plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index f6f7258fa..51192d8c9 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -173,7 +173,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.36" + __version__ = "0.37" __status__ = "testing" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 8af39bfa2c409d4fd07d430485117bf60fdcc935 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 29 Sep 2015 21:43:22 +0200 Subject: Update internal plugins --- module/plugins/internal/Plugin.py | 60 +++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 51192d8c9..f1cd74fcb 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -6,7 +6,6 @@ import datetime import inspect import os import re -import sys import traceback import urllib import urlparse @@ -28,6 +27,11 @@ def decode(string, encoding='utf8'): return unicode(string) +#@TODO: Remove in 0.4.10 +def _decode(*args, **kwargs): + return decode(*args, **kwargs) + + #@TODO: Move to utils in 0.4.10 def encode(string, encoding='utf8'): """ Decode string to utf8 """ @@ -49,18 +53,25 @@ def exists(path): return False -#@TODO: Move to utils in 0.4.10 -def parse_name(url): - url = urllib.unquote(url) - url = url.decode('unicode-escape') - url = html_unescape(url) - url = urllib.quote(url) +#@TODO: Recheck in 0.4.10 +def fixurl(url, unquote=None): + newurl = urllib.unquote(url) + + if unquote is None: + unquote = newurl == url + + newurl = html_unescape(newurl.decode('unicode-escape')).strip() - url_p = urlparse.urlparse(url.strip().rstrip('/')) + return newurl if unquote else urllib.quote(newurl) - name = (url_p.path.split('/')[-1] or - url_p.query.split('=', 1)[::-1][0].split('&', 1)[0] or - url_p.netloc.split('.', 1)[0]) + +#@TODO: Recheck in 0.4.10 +def parse_name(string): + path = fixurl(decode(string), unquote=False) + url_p = urlparse.urlparse(path.rstrip('/')) + name = (url_p.path.split('/')[-1] or + url_p.query.split('=', 1)[::-1][0].split('&', 1)[0] or + url_p.netloc.split('.', 1)[0]) return urllib.unquote(name) @@ -96,7 +107,7 @@ def seconds_to_midnight(utc=None): else: now = datetime.datetime.utcnow() + datetime.timedelta(hours=utc) - midnight = now.replace(hour=0, minute=10, second=0, microsecond=0) + datetime.timedelta(days=1) + midnight = now.replace(hour=0, minute=1, second=0, microsecond=0) + datetime.timedelta(days=1) return (midnight - now).seconds @@ -173,7 +184,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.37" + __version__ = "0.38" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -199,8 +210,8 @@ class Plugin(object): def _init(self, core): self.pyload = core - self.info = {} #: Provide information in dict here - self.req = None + self.info = {} #: Provide information in dict here + self.req = None #: Browser instance, see `network.Browser` def init(self): @@ -231,8 +242,6 @@ class Plugin(object): def log_warning(self, *args): self._log("warning", self.__type__, self.__name__, args) - if self.pyload.debug: - traceback.print_exc() def log_error(self, *args): @@ -278,7 +287,7 @@ class Plugin(object): return min(self.pyload.config.get("download", "chunks"), self.chunk_limit) - def set_config(self, option, value): + def set_config(self, option, value, plugin=None): """ Set config value for current plugin @@ -286,7 +295,7 @@ class Plugin(object): :param value: :return: """ - self.pyload.config.setPlugin(self.__name__, option, value) + self.pyload.config.setPlugin(plugin or self.__name__, option, value) def get_config(self, option, default="", plugin=None): @@ -347,7 +356,9 @@ class Plugin(object): """ if self.pyload.debug: self.log_debug("LOAD URL " + url, - *["%s=%s" % (key, val) for key, val in locals().items() if key not in ("self", "url")]) + *["%s=%s" % (key, val) for key, val in locals().items() if key not in ("self", "url", "_[1]")]) + + url = fixurl(url, unquote=True) #: Recheck in 0.4.10 if req is None: req = self.req or self.pyload.requestFactory.getRequest(self.__name__) @@ -364,7 +375,7 @@ class Plugin(object): #@TODO: Move to network in 0.4.10 if isinstance(decode, basestring): - res = sys.modules[self.__name__].decode(res, decode) #@TODO: See #1787, use utils.decode() in 0.4.10 + res = _decode(res, decode) #@NOTE: Use `utils.decode()` in 0.4.10 if self.pyload.debug: frame = inspect.currentframe() @@ -409,11 +420,12 @@ class Plugin(object): Clean everything and remove references """ try: + self.req.clearCookies() self.req.close() except Exception: pass - for a in ("pyfile", "thread", "html", "req"): - if hasattr(self, a): - setattr(self, a, None) + for attr in ("account", "html", "pyfile", "req", "thread"): + if hasattr(self, attr): + setattr(self, attr, None) -- cgit v1.2.3 From 9fdf1ed882fa981efd96179aaee23fb87e597c9b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 29 Sep 2015 21:48:26 +0200 Subject: Update crypter plugins --- module/plugins/internal/Plugin.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index f1cd74fcb..6f3e52962 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -192,10 +192,7 @@ class Plugin(object): __description__ = """Base plugin""" __license__ = "GPLv3" - __authors__ = [("RaNaN" , "RaNaN@pyload.org" ), - ("spoob" , "spoob@pyload.org" ), - ("mkaay" , "mkaay@mkaay.de" ), - ("Walter Purcaro", "vuolter@gmail.com")] + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] def __init__(self, core): -- cgit v1.2.3 From 71c075a25b43220f793269c122b4fb17aa63f160 Mon Sep 17 00:00:00 2001 From: Manuel Mausz Date: Wed, 30 Sep 2015 21:53:04 +0200 Subject: Strip trailing slashes before case sensitive checking Strip trailing slashes. Otherwise the last pathname component might be empty --- module/plugins/internal/Plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 6f3e52962..771966389 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -45,7 +45,7 @@ def encode(string, encoding='utf8'): def exists(path): if os.path.exists(path): if os.name == "nt": - dir, name = os.path.split(path) + dir, name = os.path.split(path.rstrip(os.sep)) return name in os.listdir(dir) else: return True -- cgit v1.2.3 From 8d85a655d8cc408574f471306613bc05115c8c64 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 1 Oct 2015 18:59:55 +0200 Subject: Improve Hoster and Crypter + general fixup --- module/plugins/internal/Plugin.py | 45 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 6f3e52962..55574aae0 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -76,11 +76,6 @@ def parse_name(string): return urllib.unquote(name) -#@TODO: Move to utils in 0.4.10 -def timestamp(): - return int(time.time() * 1000) - - #@TODO: Move to utils in 0.4.10 def which(program): """ @@ -184,7 +179,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.38" + __version__ = "0.40" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -206,9 +201,10 @@ class Plugin(object): def _init(self, core): - self.pyload = core - self.info = {} #: Provide information in dict here - self.req = None #: Browser instance, see `network.Browser` + self.pyload = core + self.info = {} #: Provide information in dict here + self.req = None #: Browser instance, see `network.Browser` + self.last_html = None def init(self): @@ -355,7 +351,7 @@ class Plugin(object): self.log_debug("LOAD URL " + url, *["%s=%s" % (key, val) for key, val in locals().items() if key not in ("self", "url", "_[1]")]) - url = fixurl(url, unquote=True) #: Recheck in 0.4.10 + url = fixurl(url) #: Recheck in 0.4.10 if req is None: req = self.req or self.pyload.requestFactory.getRequest(self.__name__) @@ -364,15 +360,17 @@ class Plugin(object): if isinstance(cookies, list): set_cookies(req.cj, cookies) - res = req.load(url, get, post, ref, bool(cookies), just_header, multipart, decode is True) #@TODO: Fix network multipart in 0.4.10 + html = req.load(url, get, post, ref, bool(cookies), just_header, multipart, decode is True) #@TODO: Fix network multipart in 0.4.10 #@TODO: Move to network in 0.4.10 if decode: - res = html_unescape(res) + html = html_unescape(html) #@TODO: Move to network in 0.4.10 if isinstance(decode, basestring): - res = _decode(res, decode) #@NOTE: Use `utils.decode()` in 0.4.10 + html = _decode(html, decode) #@NOTE: Use `utils.decode()` in 0.4.10 + + self.last_html = html if self.pyload.debug: frame = inspect.currentframe() @@ -383,15 +381,18 @@ class Plugin(object): with open(framefile, "wb") as f: del frame #: Delete the frame or it wont be cleaned - f.write(encode(res)) + f.write(encode(html)) except IOError, e: self.log_error(e) - if just_header: - #: Parse header + if not just_header: + return html + + else: + #@TODO: Move to network in 0.4.10 header = {'code': req.code} - for line in res.splitlines(): + for line in html.splitlines(): line = line.strip() if not line or ":" not in line: continue @@ -407,14 +408,13 @@ class Plugin(object): header[key] = [header[key], value] else: header[key] = value - res = header - return res + return header def clean(self): """ - Clean everything and remove references + Remove references """ try: self.req.clearCookies() @@ -423,6 +423,5 @@ class Plugin(object): except Exception: pass - for attr in ("account", "html", "pyfile", "req", "thread"): - if hasattr(self, attr): - setattr(self, attr, None) + else: + self.req = None -- cgit v1.2.3 From ab3c90a7b0d18f47d3efc8259906895c1f50765d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 1 Oct 2015 23:21:14 +0200 Subject: Fixpack (1) --- module/plugins/internal/Plugin.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index dbf6775cb..5725bfa58 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -6,6 +6,7 @@ import datetime import inspect import os import re +import time import traceback import urllib import urlparse @@ -76,6 +77,11 @@ def parse_name(string): return urllib.unquote(name) +#@TODO: Move to utils in 0.4.10 +def timestamp(): + return int(time.time() * 1000) + + #@TODO: Move to utils in 0.4.10 def which(program): """ @@ -145,7 +151,10 @@ def parse_html_form(attr_str, html, input_names={}): else: inputs[name] = value - if input_names: + if not input_names: + #: No attribute check + return action, inputs + else: #: Check input attributes for key, val in input_names.items(): if key in inputs: @@ -155,14 +164,12 @@ def parse_html_form(attr_str, html, input_names={}): continue elif hasattr(val, "search") and re.match(val, inputs[key]): continue - break #: Attibute value does not match + else: + break #: Attibute value does not match else: break #: Attibute name does not match else: return action, inputs #: Passed attribute check - else: - #: No attribute check - return action, inputs return {}, None #: No matching form found @@ -179,7 +186,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.40" + __version__ = "0.41" __status__ = "testing" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 4e6234d8530c513ae37307f57d65c8c2b56efb1f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 2 Oct 2015 00:26:01 +0200 Subject: [Plugin] Improve fixurl function https://github.com/pyload/pyload/issues/1873 --- module/plugins/internal/Plugin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 5725bfa58..4546186d4 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -61,9 +61,13 @@ def fixurl(url, unquote=None): if unquote is None: unquote = newurl == url - newurl = html_unescape(newurl.decode('unicode-escape')).strip() + newurl = html_unescape(newurl.decode('unicode-escape')) + newurl = re.sub(r'/{2,}', '/', newurl).strip().lstrip('.') - return newurl if unquote else urllib.quote(newurl) + if not unquote: + newurl = urllib.quote(newurl) + + return newurl #@TODO: Recheck in 0.4.10 @@ -186,7 +190,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.41" + __version__ = "0.42" __status__ = "testing" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 67a21410eeb8a2bd7bc4d71f7fe5cd68312b702b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 2 Oct 2015 02:34:47 +0200 Subject: Fix https://github.com/pyload/pyload/issues/1917 + new function: parse_time --- module/plugins/internal/Plugin.py | 46 +++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'module/plugins/internal/Plugin.py') 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('/')) @@ -81,6 +79,46 @@ def parse_name(string): return urllib.unquote(name) +#@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$' -- cgit v1.2.3 From ab695d17397e101447102877cdd282d825051035 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 2 Oct 2015 04:22:19 +0200 Subject: [Account] Improve parse_traffic method + code cosmetics --- module/plugins/internal/Plugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/internal/Plugin.py') diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 24cff70c3..6d94ca1e4 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -11,12 +11,12 @@ import traceback import urllib import urlparse -if os.name != "nt": +if os.name is not "nt": import grp import pwd from module.plugins.Plugin import Abort, Fail, Reconnect, Retry, SkipDownload as Skip #@TODO: Remove in 0.4.10 -from module.utils import fs_encode, fs_decode, html_unescape, save_join as fs_join +from module.utils import fs_encode, fs_decode, html_unescape, parseFileSize as parse_size, save_join as fs_join #@TODO: Move to utils in 0.4.10 @@ -45,7 +45,7 @@ def encode(string, encoding='utf8'): #@TODO: Move to utils in 0.4.10 def exists(path): if os.path.exists(path): - if os.name == "nt": + if os.name is "nt": dir, name = os.path.split(path.rstrip(os.sep)) return name in os.listdir(dir) else: @@ -228,7 +228,7 @@ def chunks(iterable, size): class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.43" + __version__ = "0.44" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -314,7 +314,7 @@ class Plugin(object): self.log_warning(_("Setting path mode failed"), e) try: - if os.name != "nt" and self.pyload.config.get("permission", "change_dl"): + if os.name is not "nt" and self.pyload.config.get("permission", "change_dl"): uid = pwd.getpwnam(self.pyload.config.get("permission", "user"))[2] gid = grp.getgrnam(self.pyload.config.get("permission", "group"))[2] os.chown(path, uid, gid) -- cgit v1.2.3