diff options
| author | 2015-01-31 21:18:17 +0100 | |
|---|---|---|
| committer | 2015-01-31 21:18:17 +0100 | |
| commit | a206e9103c6d791caf780be3de6ce6ceda13b793 (patch) | |
| tree | 8deaa062ce15b014779cf0518ba278f5b1ef19ad | |
| parent | [RapidgatorNet] Tiny code cosmetics (diff) | |
| download | pyload-a206e9103c6d791caf780be3de6ce6ceda13b793.tar.xz | |
[JustPremium] Rewritten
| -rw-r--r-- | module/plugins/hooks/JustPremium.py | 44 | 
1 files changed, 14 insertions, 30 deletions
| diff --git a/module/plugins/hooks/JustPremium.py b/module/plugins/hooks/JustPremium.py index 7e1e738e4..1b0ed4196 100644 --- a/module/plugins/hooks/JustPremium.py +++ b/module/plugins/hooks/JustPremium.py @@ -1,55 +1,39 @@  # -*- coding: utf-8 -*- +import re +  from module.plugins.Hook import Hook  class JustPremium(Hook):      __name__    = "JustPremium"      __type__    = "hook" -    __version__ = "0.18" +    __version__ = "0.19" -    __config__ = [("freehosters", "bool", "Allow all freehosters and other unknown sites", False), -                  ("nicehoster" , "str" , "unblock this hosters (comma seperated)"       , "Zippyshare.com")] +    __config__ = [("excluded", "str", "Exclude hosters (comma separated)", "")]      __description__ = """Remove all not premium links from urls added"""      __license__     = "GPLv3" -    __authors__     = [("mazleu", "mazleica@gmail.com")] +    __authors__     = [("mazleu", "mazleica@gmail.com"), +                       ("Walter Purcaro", "vuolter@gmail.com")]      event_list = ["linksAdded"] -    def coreReady(self) : -        hosts    = "" -        accounts = str(self.core.accountManager.getAccountInfos()) - -        while "[{" in accounts: -            startid  = accounts.rfind("[], ", 0, accounts.find("[{")) + 2 -            endid    = accounts.find("}]", startid) + 2 -            hosts    = hosts + "," + accounts[startid+3:accounts.find("'",startid+3)] -            accounts = accounts[0:startid] + accounts[endid:] - -        self.hosts    = map(str.strip, (hosts[1:] + "," + self.getConfig("nicehoster")).split(',')) -        self.badhosts = map(str.strip, accounts.replace("': [], '",",")[2:-6].split(',')) - -        self.logDebug("Hosts: %s" % ", ".join(self.hosts)) -        self.logDebug("Bad hosts: %s" % ", ".join(self.badhosts)) - -      def linksAdded(self, links, pid): -        linkdict  = self.core.api.checkURLs(links) +        linkdict       = self.core.api.checkURLs(links) +        premiumplugins = set(account.type for account in self.core.api.getAccounts(False) if account.valid and account.premium)          #: Found at least one hoster with account -        if not any(True for hoster in linkdict if hoster in self.hosts): +        if not any(True for pluginname in linkdict if pluginname in premiumplugins):              return -        if self.getConfig("freehosters"): -            bad_hosters = [hoster for hoster in linkdict.iterkeys() if hoster in self.badhosts] -        else: -            bad_hosters = [hoster for hoster in linkdict.iterkeys() if hoster not in self.hosts] +        excluded = map(lambda domain: "".join(part.capitalize() for part in re.split(r'(\.|\d+)', domain) if part != '.'), +                       self.getConfig('excluded').replace(' ', '').replace(',', '|').replace(';', '|').split('|')) -        for hoster in bad_hosters: -            self.logInfo(_("Remove links of hoster: %s") % hoster) -            for link in linkdict[hoster]: +        for pluginname in set(linkdict.keys()) - premiumplugins.union(excluded): +            self.logInfo(_("Remove links of plugin: %s") % pluginname) +            for link in linkdict[pluginname]:                  self.logDebug("Remove link: %s" % link)                  links.remove(link) | 
