diff options
Diffstat (limited to 'pyload/threads/DecrypterThread.py')
-rw-r--r-- | pyload/threads/DecrypterThread.py | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/pyload/threads/DecrypterThread.py b/pyload/threads/DecrypterThread.py index e4df2ee75..e8b889ac8 100644 --- a/pyload/threads/DecrypterThread.py +++ b/pyload/threads/DecrypterThread.py @@ -2,10 +2,9 @@ # -*- coding: utf-8 -*- from time import sleep -from traceback import print_exc -from pyload.utils import uniqify -from pyload.plugins.Base import Retry +from pyload.utils import uniqify, accumulate +from pyload.plugins.Base import Abort, Retry from pyload.plugins.Crypter import Package from BaseThread import BaseThread @@ -14,30 +13,35 @@ class DecrypterThread(BaseThread): """thread for decrypting""" def __init__(self, manager, data, pid): - """constructor""" + # TODO: owner BaseThread.__init__(self, manager) + # [... (plugin, url) ...] self.data = data self.pid = pid self.start() def run(self): - plugin_map = {} - for url, plugin in self.data: - if plugin in plugin_map: - plugin_map[plugin].append(url) - else: - plugin_map[plugin] = [url] + pack = self.m.core.files.getPackage(self.pid) + links, packages = self.decrypt(accumulate(self.data), pack.password) - self.decrypt(plugin_map) + if links: + self.log.info(_("Decrypted %(count)d links into package %(name)s") % {"count": len(links), "name": pack.name}) + self.m.core.api.addFiles(self.pid, [l.url for l in links]) - def decrypt(self, plugin_map): - pack = self.m.core.files.getPackage(self.pid) + # TODO: add single package into this one and rename it? + # TODO: nested packages + for p in packages: + self.m.core.api.addPackage(p.name, p.getURLs(), pack.password) + + def decrypt(self, plugin_map, password=None): result = [] + # TODO QUEUE_DECRYPT + for name, urls in plugin_map.iteritems(): klass = self.m.core.pluginManager.loadClass("crypter", name) - plugin = klass(self.m.core, pack, pack.password) + plugin = klass(self.m.core, password) plugin_result = [] try: @@ -46,36 +50,37 @@ class DecrypterThread(BaseThread): except Retry: sleep(1) plugin_result = plugin._decrypt(urls) + except Abort: + plugin.logInfo(_("Decrypting aborted")) except Exception, e: plugin.logError(_("Decrypting failed"), e) - if self.m.core.debug: - print_exc() + if self.core.debug: + self.core.print_exc() self.writeDebugReport(plugin.__name__, plugin=plugin) + finally: + plugin.clean() plugin.logDebug("Decrypted", plugin_result) result.extend(plugin_result) - #TODO package names are optional - result = uniqify(result) + # generated packages pack_names = {} + # urls without package urls = [] + # merge urls and packages 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 + if not p.name: + urls.append(p) + 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.itervalues(): - self.m.core.api.addPackage(p.name, p.urls, pack.password) - - if not result: - self.log.info(_("No links decrypted")) + urls = uniqify(urls) + return urls, pack_names.values()
\ No newline at end of file |