From 0c65a1e6c6ffa739731e3101dcac1dc5d728c9ad Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 2 Nov 2014 22:41:04 +0100 Subject: [XFileSharingPro] Fix hook plugin --- module/plugins/hooks/XFileSharingPro.py | 60 +++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 25 deletions(-) (limited to 'module/plugins') diff --git a/module/plugins/hooks/XFileSharingPro.py b/module/plugins/hooks/XFileSharingPro.py index 552730f5d..c4205b34f 100644 --- a/module/plugins/hooks/XFileSharingPro.py +++ b/module/plugins/hooks/XFileSharingPro.py @@ -8,14 +8,14 @@ from module.plugins.Hook import Hook class XFileSharingPro(Hook): __name__ = "XFileSharingPro" __type__ = "hook" - __version__ = "0.20" + __version__ = "0.21" __config__ = [("activated", "bool", "Activated", True), - ("every_hoster", "bool", "Try to hook any hoster", True), - ("every_crypter", "bool", "Try to hook any crypter", True), - ("load_default", "bool", "Load built-in plugins", True), - ("hoster_list", "str", "Load hosters (comma separated)", ""), - ("crypter_list", "str", "Load crypters (comma separated)", "")] + ("use_hoster_list", "bool", "Load listed hosters only", False), + ("use_crypter_list", "bool", "Load listed crypters only", False), + ("use_builtin_list", "bool", "Load built-in plugin list", True), + ("hoster_list", "str", "Hoster list (comma separated)", ""), + ("crypter_list", "str", "Crypter list (comma separated)", "")] __description__ = """Load XFileSharingPro based hosters and crypter which don't need a own plugin to run""" __license__ = "GPLv3" @@ -23,7 +23,7 @@ class XFileSharingPro(Hook): # event_list = ["pluginConfigChanged"] - regex = {'hoster' : (r'https?://(?:www\.)?([\w^_]+(?:\.[a-zA-Z]{2,})+(?:\:\d+)?)/(?:embed-)?\w{12}', + regexp = {'hoster' : (r'https?://(?:www\.)?([\w^_]+(?:\.[a-zA-Z]{2,})+(?:\:\d+)?)/(?:embed-)?\w{12}', r'https?://(?:[^/]+\.)?(%s)/(?:embed-)?\w{12}\W?'), 'crypter': (r'https?://(?:www\.)?([\w^_]+(?:\.[a-zA-Z]{2,})+(?:\:\d+)?)/(?:user|folder)s?/\w+', r'https?://(?:[^/]+\.)?(%s)/(?:user|folder)s?/\w+')} @@ -40,7 +40,7 @@ class XFileSharingPro(Hook): CRYPTER_LIST = [] - # def pluginConfigChanged(self, plugin, name, value): + # def pluginConfigChanged(self.__name__, plugin, name, value): # self.loadPattern() @@ -49,40 +49,50 @@ class XFileSharingPro(Hook): def loadPattern(self): - for type, plugin in (("hoster", "XFileSharingPro"), ("crypter", "XFileSharingProFolder")): - every_plugin = self.getConfig('every_%s' % type) + use_builtin_list = self.getConfig('use_builtin_list') + + for type, plugin in (("hoster", "XFileSharingPro"), + ("crypter", "XFileSharingProFolder")): + every_plugin = not self.getConfig("use_%s_list" % type) if every_plugin: - self.logInfo("Handling all %ss: %s" % (len(plugin_list), type, match_list.replace('|', ', '))) - regexp = self.regex[type][0] + self.logInfo(_("Handling any %s I can!") % type) + pattern = self.regexp[type][0] else: s = self.getConfig('%s_list' % type).replace('\\', '').replace('|', ',').replace(';', ',').lower() plugin_list = set([x.strip() for x in s.split(',')]) - if self.getConfig('load_default'): + if use_builtin_list: plugin_list |= set([x.lower() for x in getattr(self, "%s_LIST" % type.upper())]) - plugin_list -= set(('', u'')) + plugin_list -= set(('', u'') if not plugin_list: - self.unload() + self.logInfo(_("No %s to handle") % type) + self._unload(type, plugin) return match_list = '|'.join(sorted(plugin_list)) - self.logInfo("Handling %s %ss" % (u'\u221E', type)) - regexp = self.regex[type][1] % match_list.replace('.', '\.') + len_match_list = len(plugin_list) + self.logInfo(_("Handling %d %s%s: %s") % (len_match_list, type, "" if len_match_list is 1 else "s", match_list.replace('|', ', '))) + + pattern = self.regexp[type][1] % match_list.replace('.', '\.') dict = self.core.pluginManager.plugins[type][plugin] - dict['pattern'] = regexp - dict['re'] = re.compile(regexp) + dict['pattern'] = pattern + dict['re'] = re.compile(pattern) + + self.logDebug("Loaded %s pattern: %s" % (type, pattern)) - self.logDebug("Loaded %s regex: `%s`" % (type, regexp)) + + def _unload(self, type, plugin): + dict = self.core.pluginManager.plugins[type][plugin] + dict['pattern'] = r'^unmatchable$' + dict['re'] = re.compile(dict['pattern']) def unload(self): - regexp = r'^unmatchable$' - for type, plugin in (("hoster", "XFileSharingPro"), ("crypter", "XFileSharingProFolder")): - dict = self.core.pluginManager.plugins[type][plugin] - dict['pattern'] = regexp - dict['re'] = re.compile(regexp) + for type, plugin in (("hoster", "XFileSharingPro"), + ("crypter", "XFileSharingProFolder")): + self._unload(type, plugin) -- cgit v1.2.3