forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTORRENT.py
More file actions
77 lines (60 loc) · 3.21 KB
/
Copy pathTORRENT.py
File metadata and controls
77 lines (60 loc) · 3.21 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import re
from ..base.addon import BaseAddon
class TORRENT(BaseAddon):
__name__ = "TORRENT"
__type__ = "addon"
__version__ = "0.07"
__status__ = "testing"
__config__ = [("enabled", "bool", "Activated", True),
("torrent_plugin",
"None;c:AlldebridComTorrent;c:DebridlinkFrTorrent;h:LinksnappyComTorrent;c:RealdebridComTorrent;c:TorboxAppTorrent;h:ZbigzCom",
"Associate torrents / magnets with plugin", "None")]
__description__ = """Associate torrents / magnets with plugin"""
__license__ = "GPLv3"
__authors__ = [("GammaC0de", "nitzo2001@yahoo.com")]
def activate(self):
self.pyload.addon_manager.add_event("plugin_updated", self.plugins_updated)
self.torrent_plugin = self.config.get("torrent_plugin")
self._associate(self.torrent_plugin)
self._report_status()
def deactivate(self):
self.pyload.addon_manager.remove_event("plugin_updated", self.plugins_updated)
self._remove_association(self.torrent_plugin)
self.torrent_plugin = "None"
if self.pyload.exiting is False:
self._report_status()
def plugins_updated(self, updated_plugins):
if self.torrent_plugin != "None":
self._remove_association(self.torrent_plugin)
self._associate(self.torrent_plugin)
def config_changed(self, *args):
if args[3] == "plugin" and args[0] == "TORRENT" and args[1] == "torrent_plugin" and args[2] != self.torrent_plugin:
self._remove_association(self.torrent_plugin)
self.torrent_plugin = args[2]
self._associate(self.torrent_plugin)
self._report_status()
def _report_status(self):
if self.torrent_plugin == "None":
self.log_warning(self._("torrents / magnets are not associated with any plugin"))
else:
self.log_info(self._("Using {} to handle torrents / magnets").format(self.torrent_plugin.split(":")[1]))
def _associate(self, plugin):
if plugin != "None":
plugin_type, plugin_name = plugin.split(":")
plugin_type = "decrypter" if plugin_type == "c" else "downloader"
hdict = self.pyload.plugin_manager.plugins["container"]["TORRENT"]
hdict["pattern"] = r"(?!(?:file|https?)://).+\.(?:torrent|magnet)"
hdict["re"] = re.compile(hdict["pattern"])
hdict = self.pyload.plugin_manager.plugins[plugin_type][plugin_name]
hdict["pattern"] = r"(?:file|https?)://.+\.torrent|magnet:\?.+"
hdict["re"] = re.compile(hdict["pattern"])
def _remove_association(self, plugin):
if plugin != "None":
plugin_type, plugin_name = plugin.split(":")
plugin_type = "decrypter" if plugin_type == "c" else "downloader"
hdict = self.pyload.plugin_manager.plugins[plugin_type][plugin_name]
hdict["pattern"] = r"^unmatchable$"
hdict["re"] = re.compile(hdict["pattern"])
hdict = self.pyload.plugin_manager.plugins["container"]["TORRENT"]
hdict["pattern"] = r"(?:file|https?)://.+\.torrent|magnet:\?.+|(?!(?:file|https?)://).+\.(?:torrent|magnet)"
hdict["re"] = re.compile(hdict["pattern"])