diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-27 21:14:40 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-27 21:14:40 +0100 |
commit | b72be64cc16660e3ba877d97dbc0e717bb030666 (patch) | |
tree | 2a6f08c55d778a022ab571bc9b1f65ff78030120 | |
parent | [ShareonlineBiz] Account fixup (diff) | |
download | pyload-b72be64cc16660e3ba877d97dbc0e717bb030666.tar.xz |
[MultiHook] Crypter support
-rw-r--r-- | module/plugins/internal/MultiHook.py | 150 |
1 files changed, 83 insertions, 67 deletions
diff --git a/module/plugins/internal/MultiHook.py b/module/plugins/internal/MultiHook.py index 78de1ed0a..cf251bacf 100644 --- a/module/plugins/internal/MultiHook.py +++ b/module/plugins/internal/MultiHook.py @@ -9,16 +9,22 @@ from module.utils import remove_chars class MultiHook(Hook): __name__ = "MultiHook" __type__ = "hook" - __version__ = "0.23" + __version__ = "0.25" - __description__ = """Hook plugin for MultiHoster""" + __config__ = [("mode" , "all;listed;unlisted", "Use for plugins (if supported)" , "all"), + ("pluginlist" , "str" , "Plugin list (comma separated)" , "" ), + ("revertfailed", "bool" , "Revert to standard download if download fails", False), + ("interval" , "int" , "Reload interval in hours (0 to disable)" , 12 )] + + __description__ = """Hook plugin for multi hoster/crypter""" __license__ = "GPLv3" - __authors__ = [("pyLoad Team", "admin@pyload.org")] + __authors__ = [("pyLoad Team", "admin@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] - interval = 12 * 60 * 60 #: reload hosters every 12h + MIN_INTERVAL = 12 * 60 * 60 #: reload plugins every 12h - HOSTER_REPLACEMENTS = [("1fichier.com" , "onefichier.com"), + PLUGIN_REPLACEMENTS = [("1fichier.com" , "onefichier.com"), ("2shared.com" , "twoshared.com" ), ("4shared.com" , "fourshared.com"), ("cloudnator.com" , "shragle.com" ), @@ -34,15 +40,26 @@ class MultiHook(Hook): ("sharerapid.cz" , "multishare.cz" ), ("ul.to" , "uploaded.to" ), ("uploaded.net" , "uploaded.to" )] - HOSTER_EXCLUDED = [] def setup(self): - self.hosters = [] + self.type = self.core.pluginManager.findPlugin(self.__name__)[1] or "hoster" + self.plugins = [] self.supported = [] self.new_supported = [] + def getURL(self, *args, **kwargs): #@TODO: Remove in 0.4.10 + """ see HTTPRequest for argument list """ + h = pyreq.getHTTPRequest(timeout=120) + try: + rep = h.load(*args, **kwargs) + finally: + h.close() + + return rep + + def getConfig(self, option, default=''): """getConfig with default value - sublass may not implements all config options""" try: @@ -52,36 +69,37 @@ class MultiHook(Hook): return default - def getHosterCached(self): - if not self.hosters: + def pluginCached(self): + if not self.plugins: try: - hosterSet = self.toHosterSet(self.getHoster()) - set(self.HOSTER_EXCLUDED) + pluginset = self.pluginSet(self.getHosters() if self.type is "hoster" else self.getCrypters()) except Exception, e: self.logError(e) return [] try: - configMode = self.getConfig('hosterListMode', 'all') - if configMode in ("listed", "unlisted"): - configSet = self.toHosterSet(self.getConfig('hosterList', '').replace('|', ',').replace(';', ',').split(',')) + configmode = self.getConfig("mode", 'all') + if configmode in ("listed", "unlisted"): + list = self.getConfig("pluginlist", '').replace('|', ',').replace(';', ',').split(',') + configset = self.pluginSet(list) - if configMode == "listed": - hosterSet &= configSet + if configmode == "listed": + pluginset &= configset else: - hosterSet -= configSet + pluginset -= configset except Exception, e: self.logError(e) - self.hosters = list(hosterSet) + self.plugins = list(pluginset) - return self.hosters + return self.plugins - def toHosterSet(self, hosters): + def pluginSet(self, hosters): hosters = set((str(x).strip().lower() for x in hosters)) - for rep in self.HOSTER_REPLACEMENTS: + for rep in self.PLUGIN_REPLACEMENTS: if rep[0] in hosters: hosters.remove(rep[0]) hosters.add(rep[1]) @@ -90,7 +108,7 @@ class MultiHook(Hook): return hosters - def getHoster(self): + def getHosters(self): """Load list of supported hoster :return: List of domain names @@ -98,96 +116,93 @@ class MultiHook(Hook): raise NotImplementedError - def coreReady(self): - if self.cb: - self.core.scheduler.removeJob(self.cb) - - self.setConfig("activated", True) #: config not in sync after plugin reload - - cfg_interval = self.getConfig("interval", None) #: reload interval in hours - if cfg_interval is not None: - self.interval = cfg_interval * 60 * 60 - - if self.interval: - self._periodical() - else: - self.periodical() - + def getCrypters(self): + """Load list of supported crypters - def initPeriodical(self): - pass + :return: List of domain names + """ + raise NotImplementedError def periodical(self): - """reload hoster list periodically""" - self.logInfo(_("Reloading supported hoster list")) + """reload plugin list periodically""" + self.interval = max(self.getConfig("interval", 0), self.MIN_INTERVAL) + + self.logInfo(_("Reloading supported %s list") % self.type) old_supported = self.supported self.supported = [] self.new_supported = [] - self.hosters = [] + self.plugins = [] self.overridePlugins() - old_supported = [hoster for hoster in old_supported if hoster not in self.supported] + old_supported = [plugin for plugin in old_supported if plugin not in self.supported] + if old_supported: self.logDebug("Unload: %s" % ", ".join(old_supported)) - for hoster in old_supported: - self.unloadHoster(hoster) + for plugin in old_supported: + self.unloadPlugin(plugin) def overridePlugins(self): - pluginMap = dict((name.lower(), name) for name in self.core.pluginManager.hosterPlugins.iterkeys()) - accountList = [account.type.lower() for account in self.core.api.getAccounts(False) if account.valid and account.premium] excludedList = [] - for hoster in self.getHosterCached(): - name = remove_chars(hoster, "-.") + if self.type is "hoster": + pluginMap = dict((name.lower(), name) for name in self.core.pluginManager.hosterPlugins.iterkeys()) + accountList = [account.type.lower() for account in self.core.api.getAccounts(False) if account.valid and account.premium] + else: + pluginMap = {} + accountList = [name[::-1].replace("Folder"[::-1], "", 1).lower()[::-1] for name in self.core.pluginManager.crypterPlugins.iterkeys()] + + for plugin in self.pluginCached(): + name = remove_chars(plugin, "-.") if name in accountList: - excludedList.append(hoster) + excludedList.append(plugin) else: if name in pluginMap: self.supported.append(pluginMap[name]) else: - self.new_supported.append(hoster) + self.new_supported.append(plugin) if not self.supported and not self.new_supported: - self.logError(_("No Hoster loaded")) + self.logError(_("No %s loaded") % self.type) return module = self.core.pluginManager.getPlugin(self.__name__) klass = getattr(module, self.__name__) # inject plugin plugin - self.logDebug("Overwritten Hosters: %s" % ", ".join(sorted(self.supported))) - for hoster in self.supported: - hdict = self.core.pluginManager.hosterPlugins[hoster] + self.logDebug("Overwritten %ss: %s" % (self.type, ", ".join(sorted(self.supported)))) + + for plugin in self.supported: + hdict = self.core.pluginManager.plugins[self.type][plugin] hdict['new_module'] = module hdict['new_name'] = self.__name__ if excludedList: - self.logInfo(_("Hosters not overwritten: %s" % ", ".join(sorted(excludedList)))) + self.logInfo(_("%ss not overwritten: %s") % (self.type.capitalize(), ", ".join(sorted(excludedList)))) if self.new_supported: - hosters = sorted(self.new_supported) + plugins = sorted(self.new_supported) - self.logDebug("New Hosters: %s" % ", ".join(hosters)) + self.logDebug("New %ss: %s" % (self.type, ", ".join(plugins))) # create new regexp - regexp = r'.*(%s).*' % "|".join([x.replace(".", "\.") for x in hosters]) + regexp = r'.*(%s).*' % "|".join([x.replace(".", "\.") for x in plugins]) if hasattr(klass, "__pattern__") and isinstance(klass.__pattern__, basestring) and '://' in klass.__pattern__: regexp = r'%s|%s' % (klass.__pattern__, regexp) self.logDebug("Regexp: %s" % regexp) - hdict = self.core.pluginManager.hosterPlugins[self.__name__] + hdict = self.core.pluginManager.plugins[self.type][self.__name__] hdict['pattern'] = regexp hdict['re'] = re.compile(regexp) - def unloadHoster(self, hoster): - hdict = self.core.pluginManager.hosterPlugins[hoster] + def unloadPlugin(self, plugin): + hdict = self.core.pluginManager.plugins[self.type][plugin] if "module" in hdict: del hdict['module'] @@ -198,21 +213,22 @@ class MultiHook(Hook): def unload(self): """Remove override for all hosters. Scheduler job is removed by hookmanager""" - for hoster in self.supported: - self.unloadHoster(hoster) + for plugin in self.supported: + self.unloadPlugin(plugin) # reset pattern klass = getattr(self.core.pluginManager.getPlugin(self.__name__), self.__name__) - hdict = self.core.pluginManager.hosterPlugins[self.__name__] + hdict = self.core.pluginManager.plugins[self.type][self.__name__] + hdict['pattern'] = getattr(klass, "__pattern__", r'^unmatchable$') hdict['re'] = re.compile(hdict['pattern']) def downloadFailed(self, pyfile): """remove plugin override if download fails but not if file is offline/temp.offline""" - if pyfile.hasStatus("failed") and self.getConfig("unloadFailing", True): - hdict = self.core.pluginManager.hosterPlugins[pyfile.pluginname] + if self.type is "hoster" and pyfile.hasStatus("failed") and self.getConfig("revertfailed", True): + hdict = self.core.pluginManager.plugins[self.type][pyfile.pluginname] if "new_name" in hdict and hdict['new_name'] == self.__name__: self.logDebug("Unload MultiHook", pyfile.pluginname, hdict) - self.unloadHoster(pyfile.pluginname) + self.unloadPlugin(pyfile.pluginname) pyfile.setStatus("queued") |