diff options
| author | 2015-10-18 17:30:01 +0200 | |
|---|---|---|
| committer | 2015-10-18 17:30:01 +0200 | |
| commit | 6835a74b8c8db080b67c6d673bc15adb1afc246a (patch) | |
| tree | a7d6dd3ffab93c266afad42d4baccb5ede3e85ae /module/plugins | |
| parent | [ClickNLoad] Don't sleep, use scheduling (diff) | |
| download | pyload-6835a74b8c8db080b67c6d673bc15adb1afc246a.tar.xz | |
[MultiAccount] Still not working, but 90% complete
Diffstat (limited to 'module/plugins')
| -rw-r--r-- | module/plugins/internal/MultiAccount.py | 252 | 
1 files changed, 117 insertions, 135 deletions
| diff --git a/module/plugins/internal/MultiAccount.py b/module/plugins/internal/MultiAccount.py index b38670ce7..be509e9b3 100644 --- a/module/plugins/internal/MultiAccount.py +++ b/module/plugins/internal/MultiAccount.py @@ -4,27 +4,28 @@ import re  import time  from module.plugins.internal.Account import Account -from module.utils import decode, remove_chars +from module.plugins.internal.utils import decode, remove_chars, uniqify  class MultiAccount(Account):      __name__    = "MultiAccount"      __type__    = "account" -    __version__ = "0.02" -    __status__  = "testing" +    __version__ = "0.03" +    __status__  = "broken" -    __config__ = [("pluginmode"    , "all;listed;unlisted", "Use for plugins"              , "all"), -                  ("pluginlist"    , "str"                , "Plugin list (comma separated)", ""   ), -                  ("reload"        , "bool"               , "Reload plugin list"           , True ), -                  ("reloadinterval", "int"                , "Reload interval in hours"     , 12   )] +    __config__ = [("activated"     , "bool"               , "Activated"                    , True ), +                  ("multi"         , "bool"               , "Multi-hoster"                 , True ), +                  ("multi_mode"    , "all;listed;unlisted", "Hosters to use"               , "all"), +                  ("multi_list"    , "str"                , "Hoster list (comma separated)", ""   ), +                  ("multi_interval", "int"                , "Reload interval in hours"     , 12   )] -    __description__ = """Multi hoster account plugin""" +    __description__ = """Multi-hoster account plugin"""      __license__     = "GPLv3" -    __authors__     = [("pyLoad Team"   , "admin@pyload.org" ), -                       ("Walter Purcaro", "vuolter@gmail.com")] +    __authors__     = [("Walter Purcaro", "vuolter@gmail.com")] -    REFRESH_INTERVAL = 1 * 60 * 60  #: 1 hour +    # PERIODICAL_INTERVAL = 1 * 60 * 60  #: 1 hour +    PERIODICAL_LOGIN    = False      DOMAIN_REPLACEMENTS = [(r'180upload\.com'  , "hundredeightyupload.com"),                             (r'bayfiles\.net'   , "bayfiles.com"           ), @@ -54,153 +55,96 @@ class MultiAccount(Account):                             (r'^0'              , "zero"                   )] - - - - - - - - - - - - - - - - - - - - - - - - - - - -      def init(self): -        self.plugins       = [] -        self.supported     = [] -        self.new_supported = [] +        self.plugins      = [] +        self.supported    = [] +        self.newsupported = [] -        self.account      = None          self.pluginclass  = None          self.pluginmodule = None -        self.pluginname   = None          self.plugintype   = None          self.init_plugin()      def init_plugin(self): -        self.pluginname         = self.__name__.rsplit("Hook", 1)[0] -        plugin, self.plugintype = self.pyload.pluginManager.findPlugin(self.pluginname) +        plugin, self.plugintype = self.pyload.pluginManager.findPlugin(self.classname)          if plugin: -            self.pluginmodule = self.pyload.pluginManager.loadModule(self.plugintype, self.pluginname) -            self.pluginclass  = getattr(self.pluginmodule, self.pluginname) +            self.pluginmodule = self.pyload.pluginManager.loadModule(self.plugintype, self.classname) +            self.pluginclass  = self.pyload.pluginManager.loadClass(self.plugintype, self.classname)          else: -            self.log_warning(_("Hook plugin will be deactivated due missing plugin reference")) -            self.set_config('activated', False) +            self.log_warning(_("Multi-hoster feature will be deactivated due missing plugin reference")) +            self.set_config('multi', False) -    def load_account(self): -        self.account = self.pyload.accountManager.getAccountPlugin(self.pluginname) +    def activate(self): +        interval = self.get_config('multi_interval') * 60 * 60 +        self.start_periodical(interval, threaded=True) -        if self.account and not self.account.select()[0]: -            self.account = False -        if not self.account and hasattr(self.pluginclass, "LOGIN_ACCOUNT") and self.pluginclass.LOGIN_ACCOUNT: -            self.log_warning(_("Hook plugin will be deactivated due missing account reference")) -            self.set_config('activated', False) +    def replace_domains(self, list): +        for r in self.DOMAIN_REPLACEMENTS: +            pattern, repl = r +            regex = re.compile(pattern, re.I | re.U) +            domains = [regex.sub(repl, domain) if regex.match(domain) else domain for domain in list] +        return domains -    def activate(self): -        self.init_periodical(threaded=True) +    def parse_domains(self, list): +        regexp  = re.compile(r'^(?:https?://)?(?:www\.)?(?:\w+\.)*((?:[\d.]+|[\w\-^_]{3,63}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)', +                             re.I | re.U) -    def plugins_cached(self): -        if self.plugins: -            return self.plugins +        r'^(?:https?://)?(?:www\.)?(?:\w+\.)*((?:[\d.]+|[\w\-^_]{3,63}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)' -        for _i in xrange(5): -            try: -                pluginset = self._plugin_set(self.grab_hosters()) -                break +        domains = [decode(domain).strip().lower() for url in list for domain in regexp.findall(url)] +        return self.replace_domains(uniqify(domains)) -            except Exception, e: -                self.log_warning(e, _("Waiting 1 minute and retry")) -                time.sleep(60) -        else: -            self.log_error(_("No hoster list retrieved")) -            self.interval = self.REFRESH_INTERVAL -            return list() +    def _grab_hosters(self):          try: -            configmode = self.get_config('pluginmode', 'all') -            if configmode in ("listed", "unlisted"): -                pluginlist = self.get_config('pluginlist', '').replace('|', ',').replace(';', ',').split(',') -                configset  = self._plugin_set(pluginlist) +            hosterlist = self.grab_hosters(self.user, self.info['login']['password'], self.info['data']) -                if configmode == "listed": -                    pluginset &= configset -                else: -                    pluginset -= configset +            if hosterlist and isinstance(hosterlist, list): +                domains = self.parse_domains(hosterlist) +                self.info['data']['hosters'] = sorted(domains)          except Exception, e: -            self.log_error(e) +            self.log_warning(_("Error loading hoster list for user `%s`") % self.user, e, trace=True) -        self.plugins = list(pluginset) - -        return self.plugins - - -    def _plugin_set(self, plugins): -        regexp  = re.compile(r'^[\w\-.^_]{3,63}\.[a-zA-Z]{2,}$', re.U) -        plugins = [decode(p.strip()).lower() for p in plugins if regexp.match(p.strip())] - -        for r in self.DOMAIN_REPLACEMENTS: -            rf, rt  = r -            repr    = re.compile(rf, re.I|re.U) -            plugins = [re.sub(rf, rt, p) if repr.match(p) else p for p in plugins] - -        return set(plugins) +        finally: +            return self.info['data']['hosters']      def grab_hosters(self, user, password, data):          """          Load list of supported hoster -          :return: List of domain names          """          raise NotImplementedError      def periodical(self): -        """ -        Reload plugin list periodically -        """ -        self.load_account() - -        if self.get_config('reload', True): -            self.interval = max(self.get_config('reloadinterval', 12) * 60 * 60, self.REFRESH_INTERVAL) +        if not self.info['data'].get('hosters'): +            self.log_info(_("Loading hoster list for user `%s`...") % self.user)          else: -            self.pyload.scheduler.removeJob(self.cb) -            self.cb = None +            self.log_info(_("Reloading hoster list for user `%s`...") % self.user) + +        if self.PERIODICAL_LOGIN and not self.logged: +            self.relogin() -        self.log_info(_("Reloading supported %s list") % self.plugintype) +        hosters = self._grab_hosters() + +        self.log_debug("Hoster list for user `%s`: %s" % (self.user, hosters))          old_supported = self.supported -        self.supported     = [] -        self.new_supported = [] -        self.plugins       = [] +        self.supported    = [] +        self.newsupported = [] +        self.plugins      = [] -        self.override_plugins() +        self._override()          old_supported = [plugin for plugin in old_supported if plugin not in self.supported] @@ -209,8 +153,10 @@ class MultiAccount(Account):              for plugin in old_supported:                  self.unload_plugin(plugin) +        self.set_interval(self.get_config('multi_interval') * 60 * 60) + -    def override_plugins(self): +    def _override(self):          excludedList = []          if self.plugintype == "hoster": @@ -229,9 +175,9 @@ class MultiAccount(Account):                  if name in pluginMap:                      self.supported.append(pluginMap[name])                  else: -                    self.new_supported.append(plugin) +                    self.newsupported.append(plugin) -        if not self.supported and not self.new_supported: +        if not self.supported and not self.newsupported:              self.log_error(_("No %s loaded") % self.plugintype)              return @@ -241,13 +187,13 @@ class MultiAccount(Account):          for plugin in self.supported:              hdict = self.pyload.pluginManager.plugins[self.plugintype][plugin]              hdict['new_module'] = self.pluginmodule -            hdict['new_name']   = self.pluginname +            hdict['new_name']   = self.classname          if excludedList:              self.log_info(_("%ss not overwritten: %s") % (self.plugintype.capitalize(), ", ".join(sorted(excludedList)))) -        if self.new_supported: -            plugins = sorted(self.new_supported) +        if self.newsupported: +            plugins = sorted(self.newsupported)              self.log_debug("New %ss: %s" % (self.plugintype, ", ".join(plugins))) @@ -258,30 +204,66 @@ class MultiAccount(Account):              self.log_debug("Regexp: %s" % regexp) -            hdict = self.pyload.pluginManager.plugins[self.plugintype][self.pluginname] +            hdict = self.pyload.pluginManager.plugins[self.plugintype][self.classname]              hdict['pattern'] = regexp              hdict['re']      = re.compile(regexp) -    def unload_plugin(self, plugin): -        hdict = self.pyload.pluginManager.plugins[self.plugintype][plugin] -        if "module" in hdict: -            hdict.pop('module', None) +    def plugins_cached(self): +        if self.plugins: +            return self.plugins -        if "new_module" in hdict: -            hdict.pop('new_module', None) -            hdict.pop('new_name', None) +        for _i in xrange(5): +            try: +                pluginset = self._plugin_set(self.grab_hosters()) +                break +            except Exception, e: +                self.log_warning(e, _("Waiting 1 minute and retry"), trace=True) +                time.sleep(60) +        else: +            self.log_warning(_("No hoster list retrieved")) +            self.interval = self.PERIODICAL_INTERVAL +            return list() -    def deactivate(self): -        """ -        Remove override for all plugins. Scheduler job is removed by hookmanager -        """ -        for plugin in self.supported: -            self.unload_plugin(plugin) +        try: +            configmode = self.get_config('pluginmode', 'all') +            if configmode in ("listed", "unlisted"): +                pluginlist = self.get_config('pluginlist', '').replace('|', ',').replace(';', ',').split(',') +                configset  = self._plugin_set(pluginlist) + +                if configmode == "listed": +                    pluginset &= configset +                else: +                    pluginset -= configset + +        except Exception, e: +            self.log_error(e) + +        self.plugins = list(pluginset) + +        return self.plugins + + +    # def unload_plugin(self, plugin): +        # hdict = self.pyload.pluginManager.plugins[self.plugintype][plugin] +        # if "module" in hdict: +            # hdict.pop('module', None) + +        # if "new_module" in hdict: +            # hdict.pop('new_module', None) +            # hdict.pop('new_name', None) + + +    # def deactivate(self): +        # """ +        # Remove override for all plugins. Scheduler job is removed by hookmanager +        # """ +        # for plugin in self.supported: +            # self.unload_plugin(plugin)          #: Reset pattern -        hdict = self.pyload.pluginManager.plugins[self.plugintype][self.pluginname] +        # hdict = self.pyload.pluginManager.plugins[self.plugintype][self.classname] -        hdict['pattern'] = getattr(self.pluginclass, "__pattern__", r'^unmatchable$') -        hdict['re']      = re.compile(hdict['pattern']) +        # hdict['pattern'] = getattr(self.pluginclass, "__pattern__", r'^unmatchable$') +        # hdict['re']      = re.compile(hdict['pattern']) | 
