diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 20:11:56 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 22:53:01 +0100 |
commit | a32ab94ad39f14febf6d0526e368478d829a17c5 (patch) | |
tree | d3b619f210203db1bf6fc08bf5e7d7307fd05dd6 /module/plugins/internal/Base.py | |
parent | Update some hosters (diff) | |
download | pyload-a32ab94ad39f14febf6d0526e368478d829a17c5.tar.xz |
[internal] Spare code optimizations and fixes
Diffstat (limited to 'module/plugins/internal/Base.py')
-rw-r--r-- | module/plugins/internal/Base.py | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/module/plugins/internal/Base.py b/module/plugins/internal/Base.py index e28121ce2..063950db6 100644 --- a/module/plugins/internal/Base.py +++ b/module/plugins/internal/Base.py @@ -8,11 +8,11 @@ import urlparse from module.plugins.internal.Captcha import Captcha from module.plugins.internal.Plugin import Plugin, Abort, Fail, Reconnect, Retry, Skip -from module.plugins.internal.utils import (decode, encode, fixurl, format_size, format_time, +from module.plugins.internal.misc import (decode, encode, fixurl, format_size, format_time, parse_html_form, parse_name, replace_patterns) -#@TODO: Remove in 0.4.10 +#@TODO: Recheck in 0.4.10 def getInfo(urls): #: result = [ .. (name, size, status, url) .. ] pass @@ -24,19 +24,10 @@ def parse_fileInfo(klass, url="", html=""): return encode(info['name']), info['size'], info['status'], info['url'] -#@TODO: Remove in 0.4.10 -def create_getInfo(klass): - def get_info(urls): - for url in urls: - yield parse_fileInfo(klass, url) - - return get_info - - class Base(Plugin): __name__ = "Base" __type__ = "base" - __version__ = "0.19" + __version__ = "0.20" __status__ = "stable" __pattern__ = r'^unmatchable$' @@ -55,6 +46,7 @@ class Base(Plugin): def get_info(cls, url="", html=""): url = fixurl(url, unquote=True) info = {'name' : parse_name(url), + 'hash' : {}, 'pattern': {}, 'size' : 0, 'status' : 3 if url else 8, @@ -72,9 +64,6 @@ class Base(Plugin): def __init__(self, pyfile): self._init(pyfile.m.core) - #: - self.premium = None - #: Engage wan reconnection self.wantReconnect = False #@TODO: Change to `want_reconnect` in 0.4.10 @@ -82,22 +71,25 @@ class Base(Plugin): self.multiDL = True #@TODO: Change to `multi_dl` in 0.4.10 #: time.time() + wait in seconds - self.waiting = False + self.waiting = False #: Account handler instance, see :py:class:`Account` self.account = None self.user = None #@TODO: Remove in 0.4.10 + self.premium = None #: Associated pyfile instance, see `PyFile` self.pyfile = pyfile - self.thread = None #: Holds thread in future + #: Holds thread in future + self.thread = None #: Js engine, see `JsEngine` self.js = self.pyload.js #: Captcha stuff - self.captcha = Captcha(self) + _Captcha = self.pyload.pluginManager.loadClass("captcha", self.classname) or Captcha + self.captcha = _Captcha(pyfile) #: Some plugins store html code here self.data = "" @@ -136,11 +128,12 @@ class Base(Plugin): def _setup(self): #@TODO: Remove in 0.4.10 - self.data = "" self.pyfile.error = "" - self.last_html = None + self.data = "" + self.last_html = "" + self.last_header = {} - if self.get_config('use_premium', True): + if self.config.get('use_premium', True): self.load_account() #@TODO: Move to PluginThread in 0.4.10 else: self.account = False @@ -193,7 +186,7 @@ class Base(Plugin): size = self.info.get('size') if size > 0: - self.pyfile.size = int(self.info['size']) #@TODO: Fix int conversion in 0.4.10 + self.pyfile.size = int(self.info.get('size')) #@TODO: Fix int conversion in 0.4.10 else: size = self.pyfile.size @@ -249,10 +242,7 @@ class Base(Plugin): self.abort() - def _process(self, thread): - """ - Handles important things to do before starting - """ + def _initialize(self): self.log_debug("Plugin version: " + self.__version__) self.log_debug("Plugin status: " + self.__status__) @@ -262,11 +252,18 @@ class Base(Plugin): elif self.__status__ is "testing": self.log_warning(_("Plugin may be unstable")) + + def _process(self, thread): + """ + Handles important things to do before starting + """ self.thread = thread + + self._initialize() self._setup() # self.pyload.hookManager.downloadPreparing(self.pyfile) #@TODO: Recheck in 0.4.10 - self.check_status() + # self.check_status() self.pyfile.setStatus("starting") @@ -277,6 +274,7 @@ class Base(Plugin): #: Deprecated method, use `_process` instead (Remove in 0.4.10) def preprocessing(self, *args, **kwargs): + time.sleep(1) #@NOTE: Recheck info thread synchronization in 0.4.10 return self._process(*args, **kwargs) @@ -320,15 +318,13 @@ class Base(Plugin): """ Waits the time previously set """ - pyfile = self.pyfile - if seconds is not None: self.set_wait(seconds) if reconnect is not None: self.set_reconnect(reconnect) - wait_time = pyfile.waitUntil - time.time() + wait_time = self.pyfile.waitUntil - time.time() if wait_time < 1: self.log_warning(_("Invalid wait time interval")) @@ -336,8 +332,8 @@ class Base(Plugin): self.waiting = True - status = pyfile.status #@NOTE: Recheck in 0.4.10 - pyfile.setStatus("waiting") + status = self.pyfile.status #@NOTE: Recheck in 0.4.10 + self.pyfile.setStatus("waiting") self.log_info(_("Waiting %s...") % format_time(wait_time)) @@ -347,12 +343,12 @@ class Base(Plugin): self.log_warning(_("Reconnection ignored due logged account")) if not self.wantReconnect or self.account: - while pyfile.waitUntil > time.time(): + while self.pyfile.waitUntil > time.time(): self.check_status() time.sleep(2) else: - while pyfile.waitUntil > time.time(): + while self.pyfile.waitUntil > time.time(): self.check_status() self.thread.m.reconnecting.wait(1) @@ -366,7 +362,7 @@ class Base(Plugin): time.sleep(2) self.waiting = False - pyfile.status = status #@NOTE: Recheck in 0.4.10 + self.pyfile.status = status #@NOTE: Recheck in 0.4.10 def skip(self, msg=""): |