diff options
author | lazlev <lazlev@yopmail.com> | 2015-08-09 00:50:54 +0200 |
---|---|---|
committer | lazlev <lazlev@yopmail.com> | 2015-08-09 00:50:54 +0200 |
commit | b0ef3f1673e1930916604bb1264ca3a38414bc8d (patch) | |
tree | c97936e4d2a4cd6eb1072c65c8a08a7d18816b18 /module/plugins/internal/MultiHoster.py | |
parent | [XFileSharingPro][XFileSharingProFolder] Added default __pattern__ (diff) | |
parent | Fix https://github.com/pyload/pyload/issues/1707 (diff) | |
download | pyload-b0ef3f1673e1930916604bb1264ca3a38414bc8d.tar.xz |
Merge pull request #1 from pyload/stable
sync with stable
Diffstat (limited to 'module/plugins/internal/MultiHoster.py')
-rw-r--r-- | module/plugins/internal/MultiHoster.py | 113 |
1 files changed, 64 insertions, 49 deletions
diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py index ff4414034..c0c928a45 100644 --- a/module/plugins/internal/MultiHoster.py +++ b/module/plugins/internal/MultiHoster.py @@ -2,14 +2,15 @@ import re -from module.plugins.Plugin import Fail, Retry -from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo, replace_patterns, set_cookies +from module.plugins.internal.Plugin import Fail, encode +from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo, replace_patterns, set_cookie, set_cookies class MultiHoster(SimpleHoster): __name__ = "MultiHoster" __type__ = "hoster" - __version__ = "0.40" + __version__ = "0.50" + __status__ = "testing" __pattern__ = r'^unmatchable$' __config__ = [("use_premium" , "bool", "Use premium account if available" , True), @@ -20,76 +21,90 @@ class MultiHoster(SimpleHoster): __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + HOSTER_NAME = None + + LEECH_HOSTER = False LOGIN_ACCOUNT = True - def setup(self): - self.chunkLimit = 1 - self.multiDL = bool(self.account) - self.resumeDownload = self.premium + def init(self): + self.HOSTER_NAME = self.pyload.pluginManager.hosterPlugins[self.__name__]['name'] - def prepare(self): - self.info = {} - self.html = "" - self.link = "" #@TODO: Move to hoster class in 0.4.10 - self.directDL = False #@TODO: Move to hoster class in 0.4.10 + def _log(self, level, plugintype, pluginname, messages): + return super(MultiHoster, self)._log(level, + plugintype, + pluginname, + (self.HOSTER_NAME,) + messages) - if not self.getConfig('use_premium', True): - self.retryFree() - if self.LOGIN_ACCOUNT and not self.account: - self.fail(_("Required account not found")) + def setup(self): + self.chunk_limit = 1 + self.multiDL = bool(self.account) + self.resume_download = self.premium + - self.req.setOption("timeout", 120) + def prepare(self): + #@TODO: Recheck in 0.4.10 + plugin = self.pyload.pluginManager.hosterPlugins[self.__name__] + name = plugin['name'] + module = plugin['module'] + klass = getattr(module, name) - if isinstance(self.COOKIES, list): - set_cookies(self.req.cj, self.COOKIES) + self.get_info = klass.get_info if self.DIRECT_LINK is None: - self.directDL = self.__pattern__ != r'^unmatchable$' and re.match(self.__pattern__, self.pyfile.url) + direct_dl = self.__pattern__ != r'^unmatchable$' and re.match(self.__pattern__, self.pyfile.url) else: - self.directDL = self.DIRECT_LINK + direct_dl = self.DIRECT_LINK + + super(MultiHoster, self).prepare() - self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS) + self.direct_dl = direct_dl def process(self, pyfile): try: self.prepare() + self.check_info() #@TODO: Remove in 0.4.10 + + if self.direct_dl: + self.log_info(_("Looking for direct download link...")) + self.handle_direct(pyfile) - if self.directDL: - self.checkInfo() - self.logDebug("Looking for direct download link...") - self.handleDirect(pyfile) + if self.link or was_downloaded(): + self.log_info(_("Direct download link detected")) + else: + self.log_info(_("Direct download link not found")) - if not self.link and not self.lastDownload: + if not self.link and not self.last_download: self.preload() - self.checkErrors() - self.checkStatus(getinfo=False) + self.check_errors() + self.check_status(getinfo=False) - if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): - self.logDebug("Handled as premium download") - self.handlePremium(pyfile) + if self.premium and (not self.CHECK_TRAFFIC or self.check_traffic_left()): + self.log_info(_("Processing as premium download...")) + self.handle_premium(pyfile) - elif not self.LOGIN_ACCOUNT or (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): - self.logDebug("Handled as free download") - self.handleFree(pyfile) + elif not self.LOGIN_ACCOUNT or (not self.CHECK_TRAFFIC or self.check_traffic_left()): + self.log_info(_("Processing as free download...")) + self.handle_free(pyfile) - self.downloadLink(self.link, True) - self.checkFile() + if not self.last_download: + self.log_info(_("Downloading file...")) + self.download(self.link, disposition=self.DISPOSITION) - except Fail, e: #@TODO: Move to PluginThread in 0.4.10 - err = str(e) #@TODO: Recheck in 0.4.10 + self.check_file() + except Fail, e: #@TODO: Move to PluginThread in 0.4.10 if self.premium: - self.logWarning(_("Premium download failed")) - self.retryFree() + self.log_warning(_("Premium download failed")) + self.restart(nopremium=True) - elif self.getConfig("revertfailed", True) \ - and "new_module" in self.core.pluginManager.hosterPlugins[self.__name__]: - hdict = self.core.pluginManager.hosterPlugins[self.__name__] + elif self.get_config("revertfailed", True) \ + and "new_module" in self.pyload.pluginManager.hosterPlugins[self.__name__]: + hdict = self.pyload.pluginManager.hosterPlugins[self.__name__] tmp_module = hdict['new_module'] tmp_name = hdict['new_name'] @@ -101,17 +116,17 @@ class MultiHoster(SimpleHoster): hdict['new_module'] = tmp_module hdict['new_name'] = tmp_name - raise Retry(_("Revert to original hoster plugin")) + self.restart(_("Revert to original hoster plugin")) else: - raise Fail(err) + raise Fail(encode(e)) #@TODO: Remove `encode` in 0.4.10 - def handlePremium(self, pyfile): - return self.handleFree(pyfile) + def handle_premium(self, pyfile): + return self.handle_free(pyfile) - def handleFree(self, pyfile): + def handle_free(self, pyfile): if self.premium: raise NotImplementedError else: |