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 | |
parent | Update some hosters (diff) | |
download | pyload-a32ab94ad39f14febf6d0526e368478d829a17c5.tar.xz |
[internal] Spare code optimizations and fixes
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/internal/Base.py | 66 | ||||
-rw-r--r-- | module/plugins/internal/Crypter.py | 2 | ||||
-rw-r--r-- | module/plugins/internal/Plugin.py | 19 | ||||
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 29 |
4 files changed, 60 insertions, 56 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=""): diff --git a/module/plugins/internal/Crypter.py b/module/plugins/internal/Crypter.py index b78dadad5..596bbcfb4 100644 --- a/module/plugins/internal/Crypter.py +++ b/module/plugins/internal/Crypter.py @@ -7,7 +7,7 @@ from module.plugins.internal.misc import parse_name, safename class Crypter(Base): __name__ = "Crypter" __type__ = "crypter" - __version__ = "0.15" + __version__ = "0.16" __status__ = "stable" __pattern__ = r'^unmatchable$' diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index 779865147..43284f6a8 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -51,11 +51,18 @@ class Plugin(object): def _init(self, core): - self.pyload = core - self.db = DB(self) - self.config = Config(self) - self.info = {} #: Provide information in dict here - self.req = None #: Browser instance, see `network.Browser` + #: Internal modules + self.pyload = core + self.db = DB(self) + self.config = Config(self) + + #: Provide information in dict here + self.info = {} + + #: Browser instance, see `network.Browser` + self.req = self.pyload.requestFactory.getRequest(self.classname) + + #: Last loaded html self.last_html = "" self.last_header = {} @@ -175,7 +182,7 @@ class Plugin(object): url = fixurl(url, unquote=True) #: Recheck in 0.4.10 if req is None: - req = self.req or self.pyload.requestFactory.getRequest(self.classname) + req = self.req #@TODO: Move to network in 0.4.10 if isinstance(cookies, list): diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 86d72ba48..c6e915cc4 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -101,6 +101,7 @@ class SimpleHoster(Hoster): LOGIN_PREMIUM = False #: Set to True to require premium account login LEECH_HOSTER = False #: Set to True to leech other hoster link (as defined in handle_multi method) TEXT_ENCODING = True #: Set to encoding name if encoding value in http header is not correct + # TRANSLATE_ERROR = True LINK_PATTERN = None LINK_FREE_PATTERN = None @@ -246,13 +247,11 @@ class SimpleHoster(Hoster): def process(self, pyfile): self.prepare() + #@TODO: Remove `handle_multi`, use MultiHoster instead if self.leech_dl: self.log_info(_("Processing as debrid download...")) self.handle_multi(pyfile) - if not self.link and not was_downloaded(): - self.log_info(_("Failed to leech url")) - else: if not self.link and self.direct_dl: self.log_info(_("Looking for direct download link...")) @@ -265,24 +264,22 @@ class SimpleHoster(Hoster): if not self.link: self.preload() + self.check_errors() if self.info.get('status', 3) is not 2: self.grab_info() self.check_status() self.check_duplicates() - if self.premium and (not self.CHECK_TRAFFIC or self.check_traffic()): + if self.premium and (not self.CHECK_TRAFFIC or not self.out_of_traffic()): self.log_info(_("Processing as premium download...")) self.handle_premium(pyfile) - elif not self.LOGIN_ACCOUNT or (not self.CHECK_TRAFFIC or self.check_traffic()): + elif not self.LOGIN_ACCOUNT or (not self.CHECK_TRAFFIC or not self.out_of_traffic()): self.log_info(_("Processing as free download...")) self.handle_free(pyfile) - if not self.link and not self.last_download: - self.error(_("%s download link not found") % ("Premium" if self.premium else "Free")) - - if not self.last_download: + if self.link and not self.last_download: self.log_info(_("Downloading file...")) self.download(self.link, disposition=self.DISPOSITION) @@ -295,7 +292,7 @@ class SimpleHoster(Hoster): def check_download(self): super(SimpleHoster, self).check_download() - self.log_info(_("Checking downloaded file with built-in rules...")) + self.log_info(_("Checking file (with built-in rules)...")) for r, p in self.FILE_ERRORS: errmsg = self.scan_download({r: re.compile(p)}) if errmsg is not None: @@ -312,7 +309,7 @@ class SimpleHoster(Hoster): self.restart(errmsg) else: if self.CHECK_FILE: - self.log_info(_("Checking downloaded file with custom rules...")) + self.log_info(_("Checking file (with custom rules)...")) with open(encode(self.last_download), "rb") as f: self.data = f.read(1048576) #@TODO: Recheck in 0.4.10 @@ -448,10 +445,12 @@ class SimpleHoster(Hoster): def handle_free(self, pyfile): if not self.LINK_FREE_PATTERN: - self.error(_("Free download not implemented")) + self.fail(_("Free download not implemented")) m = re.search(self.LINK_FREE_PATTERN, self.data) - if m is not None: + if m is None: + self.error(_("Free download link not found")) + else: self.link = m.group(1) @@ -461,5 +460,7 @@ class SimpleHoster(Hoster): self.restart(premium=False) m = re.search(self.LINK_PREMIUM_PATTERN, self.data) - if m is not None: + if m is None: + self.error(_("Premium download link not found")) + else: self.link = m.group(1) |