From d35c003cc53d4723d1dfe0d81eeb9bea78cee594 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 31 Dec 2011 16:01:24 +0100 Subject: new crypter plugin API, now decrypting possible for now. --- module/threads/DecrypterThread.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 module/threads/DecrypterThread.py (limited to 'module/threads/DecrypterThread.py') diff --git a/module/threads/DecrypterThread.py b/module/threads/DecrypterThread.py new file mode 100644 index 000000000..5ce59a65e --- /dev/null +++ b/module/threads/DecrypterThread.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from BaseThread import BaseThread + +class DecrypterThread(BaseThread): + """thread for decrypting""" + + def __init__(self, manager, data, package): + """constructor""" + BaseThread.__init__(self, manager) + self.queue = data + self.package = package + + self.m.log.debug("Starting Decrypt thread") + + self.start() + + def add(self, data): + self.queue.extend(data) + + def run(self): + plugin_map = {} + for plugin, url in self.queue: + if plugin in plugin_map: + plugin_map[plugin].append(url) + else: + plugin_map[plugin] = [url] + + + self.decrypt(plugin_map) + + def decrypt(self, plugin_map): + for name, urls in plugin_map.iteritems(): + p = self.m.core.pluginManager.loadClass("crypter", name) -- cgit v1.2.3 From 35742c2cb023ac49ab3056752d2040cdb030cc2b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 1 Jan 2012 13:36:59 +0100 Subject: Happy new Year ! --- module/threads/DecrypterThread.py | 65 ++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 11 deletions(-) (limited to 'module/threads/DecrypterThread.py') diff --git a/module/threads/DecrypterThread.py b/module/threads/DecrypterThread.py index 5ce59a65e..a1b7e4f38 100644 --- a/module/threads/DecrypterThread.py +++ b/module/threads/DecrypterThread.py @@ -1,35 +1,78 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from time import sleep +from traceback import print_exc + +from module.plugins.Base import Retry +from module.plugins.Crypter import Package + from BaseThread import BaseThread class DecrypterThread(BaseThread): """thread for decrypting""" - def __init__(self, manager, data, package): + def __init__(self, manager, data, pid): """constructor""" BaseThread.__init__(self, manager) - self.queue = data - self.package = package - - self.m.log.debug("Starting Decrypt thread") + self.data = data + self.pid = pid self.start() - def add(self, data): - self.queue.extend(data) - def run(self): plugin_map = {} - for plugin, url in self.queue: + for url, plugin in self.data: if plugin in plugin_map: plugin_map[plugin].append(url) else: plugin_map[plugin] = [url] - self.decrypt(plugin_map) def decrypt(self, plugin_map): + pack = self.m.core.files.getPackage(self.pid) + result = [] + for name, urls in plugin_map.iteritems(): - p = self.m.core.pluginManager.loadClass("crypter", name) + klass = self.m.core.pluginManager.loadClass("crypter", name) + plugin = klass(self.m.core, pack, pack.password) + plugin_result = [] + + try: + try: + plugin_result = plugin._decrypt(urls) + except Retry: + sleep(1) + plugin_result = plugin._decrypt(urls) + except Exception, e: + plugin.logError(_("Decrypting failed"), e) + if self.m.core.debug: + print_exc() + self.writeDebugReport(plugin.__name__, plugin=plugin) + + plugin.logDebug("Decrypted", plugin_result) + result.extend(plugin_result) + + pack_names = {} + urls = [] + + for p in result: + if isinstance(p, Package): + if p.name in pack_names: + pack_names[p.name].urls.extend(p.urls) + else: + pack_names[p.name] = p + else: + urls.append(p) + + if urls: + self.log.info(_("Decrypted %(count)d links into package %(name)s") % {"count": len(urls), "name": pack.name}) + self.m.core.api.addFiles(self.pid, urls) + + for p in pack_names: + self.m.core.api.addPackage(p.name, p.urls, p.dest, pack.password) + + if not result: + self.log.info(_("No links decrypted")) + -- cgit v1.2.3 From b877847094b0ba03a098dff0fd769eb456b48dd1 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 6 Jan 2012 17:54:53 +0100 Subject: several improvements, also closes #486, #487 --- module/threads/DecrypterThread.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'module/threads/DecrypterThread.py') diff --git a/module/threads/DecrypterThread.py b/module/threads/DecrypterThread.py index a1b7e4f38..8edb97c34 100644 --- a/module/threads/DecrypterThread.py +++ b/module/threads/DecrypterThread.py @@ -4,6 +4,7 @@ from time import sleep from traceback import print_exc +from module.utils import uniqify from module.plugins.Base import Retry from module.plugins.Crypter import Package @@ -54,6 +55,7 @@ class DecrypterThread(BaseThread): plugin.logDebug("Decrypted", plugin_result) result.extend(plugin_result) + result = uniqify(result) pack_names = {} urls = [] -- cgit v1.2.3 From 1bb6ebf544b43cacf7c0755c5a8608b79b95e2d6 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 7 Jan 2012 20:11:16 +0100 Subject: MultiHoster plugin type, some fixes, new documentation structure --- module/threads/DecrypterThread.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/threads/DecrypterThread.py') diff --git a/module/threads/DecrypterThread.py b/module/threads/DecrypterThread.py index 8edb97c34..ce3c8cd83 100644 --- a/module/threads/DecrypterThread.py +++ b/module/threads/DecrypterThread.py @@ -72,7 +72,7 @@ class DecrypterThread(BaseThread): self.log.info(_("Decrypted %(count)d links into package %(name)s") % {"count": len(urls), "name": pack.name}) self.m.core.api.addFiles(self.pid, urls) - for p in pack_names: + for p in pack_names.itervalues(): self.m.core.api.addPackage(p.name, p.urls, p.dest, pack.password) if not result: -- cgit v1.2.3 From 4df2b77fdf42046fe19bd371be7c7255986b5980 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 6 Mar 2012 13:36:39 +0100 Subject: renamed hooks to addons, new filemanager and database, many new api methods you will loose ALL your LINKS, webinterface will NOT work --- module/threads/DecrypterThread.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'module/threads/DecrypterThread.py') diff --git a/module/threads/DecrypterThread.py b/module/threads/DecrypterThread.py index ce3c8cd83..39448a620 100644 --- a/module/threads/DecrypterThread.py +++ b/module/threads/DecrypterThread.py @@ -55,6 +55,7 @@ class DecrypterThread(BaseThread): plugin.logDebug("Decrypted", plugin_result) result.extend(plugin_result) + #TODO result = uniqify(result) pack_names = {} urls = [] @@ -73,7 +74,7 @@ class DecrypterThread(BaseThread): self.m.core.api.addFiles(self.pid, urls) for p in pack_names.itervalues(): - self.m.core.api.addPackage(p.name, p.urls, p.dest, pack.password) + self.m.core.api.addPackage(p.name, p.urls, pack.password) if not result: self.log.info(_("No links decrypted")) -- cgit v1.2.3