Repository navigation
Expand file tree
/
Copy pathJustPremium.py
More file actions
53 lines (38 loc) · 2.27 KB
/
Copy pathJustPremium.py
File metadata and controls
53 lines (38 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
import re
from module.plugins.internal.Addon import Addon
class JustPremium(Addon):
__name__ = "JustPremium"
__type__ = "hook"
__version__ = "0.24"
__status__ = "testing"
__config__ = [("excluded", "str", "Exclude hosters (comma separated)", ""),
("included", "str", "Include hosters (comma separated)", "")]
__description__ = """Remove not-premium links from added urls"""
__license__ = "GPLv3"
__authors__ = [("mazleu" , "mazleica@gmail.com"),
("Walter Purcaro", "vuolter@gmail.com" ),
("immenz" , "immenz@gmx.net" )]
def init(self):
self.event_map = {'linksAdded': "links_added"}
def links_added(self, links, pid):
hosterdict = self.pyload.pluginManager.hosterPlugins
linkdict = self.pyload.api.checkURLs(links)
premiumplugins = set(account.type for account in self.pyload.api.getAccounts(False) \
if account.valid and account.premium)
multihosters = set(hoster for hoster in self.pyload.pluginManager.hosterPlugins \
if 'new_name' in hosterdict[hoster] \
and hosterdict[hoster]['new_name'] in premiumplugins)
excluded = map(lambda domain: "".join(part.capitalize() for part in re.split(r'(\.|\d+)', domain) if part != '.'),
self.get_config('excluded').replace(' ', '').replace(',', '|').replace(';', '|').split('|'))
included = map(lambda domain: "".join(part.capitalize() for part in re.split(r'(\.|\d+)', domain) if part != '.'),
self.get_config('included').replace(' ', '').replace(',', '|').replace(';', '|').split('|'))
hosterlist = (premiumplugins | multihosters).union(excluded).difference(included)
#: Found at least one hoster with account or multihoster
if not any( True for pluginname in linkdict if pluginname in hosterlist ):
return
for pluginname in set(linkdict.keys()) - hosterlist:
self.log_info(_("Remove links of plugin: %s") % pluginname)
for link in linkdict[pluginname]:
self.log_debug("Remove link: %s" % link)
links.remove(link)