summaryrefslogtreecommitdiffstats
path: root/module/threads/DecrypterThread.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/threads/DecrypterThread.py')
-rw-r--r--module/threads/DecrypterThread.py65
1 files changed, 54 insertions, 11 deletions
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"))
+