diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-09-26 16:40:38 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-09-26 16:40:50 +0200 |
commit | 967d6dd16c25ceba22dcd105079f72534ddb87e9 (patch) | |
tree | 4c971ff446dc955f1884e5aa80ef4cb62bbf55fe /pyload/plugins | |
parent | new DLC plugins (diff) | |
download | pyload-967d6dd16c25ceba22dcd105079f72534ddb87e9.tar.xz |
rewritten decrypter and info fetching thread
Diffstat (limited to 'pyload/plugins')
-rw-r--r-- | pyload/plugins/Base.py | 30 | ||||
-rw-r--r-- | pyload/plugins/Crypter.py | 77 | ||||
-rw-r--r-- | pyload/plugins/Hoster.py | 6 | ||||
-rw-r--r-- | pyload/plugins/network/CurlRequest.py | 1 |
4 files changed, 56 insertions, 58 deletions
diff --git a/pyload/plugins/Base.py b/pyload/plugins/Base.py index 3ca8abdd0..abb59a7bc 100644 --- a/pyload/plugins/Base.py +++ b/pyload/plugins/Base.py @@ -1,21 +1,19 @@ # -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - - @author: RaNaN -""" +############################################################################### +# Copyright(c) 2008-2013 pyLoad Team +# http://www.pyload.org +# +# This file is part of pyLoad. +# pyLoad is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Subjected to the terms and conditions in LICENSE +# +# @author: RaNaN +############################################################################### import sys from time import time, sleep diff --git a/pyload/plugins/Crypter.py b/pyload/plugins/Crypter.py index cce43fb56..2175b5f94 100644 --- a/pyload/plugins/Crypter.py +++ b/pyload/plugins/Crypter.py @@ -1,50 +1,60 @@ # -*- coding: utf-8 -*- -from traceback import print_exc - -from pyload.Api import LinkStatus +from pyload.Api import LinkStatus, DownloadStatus as DS from pyload.utils import to_list, has_method, uniqify from pyload.utils.fs import exists, remove, fs_encode from pyload.utils.packagetools import parseNames -from Base import Base, Retry +from Base import Base, Fail, Retry, Abort class Package: """ Container that indicates that a new package should be created """ - def __init__(self, name=None, urls=None): + def __init__(self, name=None, links=None): self.name = name - self.urls = urls if urls else [] + self.links = [] + + if links: + self.addLinks(links) # nested packages self.packs = [] - def addURL(self, url): - self.urls.append(url) + def addLinks(self, links): + """ Add one or multiple links to the package + + :param links: One or list of urls or :class:`LinkStatus` + """ + links = to_list(links) + for link in links: + if not isinstance(link, LinkStatus): + link = LinkStatus(link, link, -1, DS.Queued) - def addLink(self, url, name, status, size): - # TODO: allow to add urls with known information - pass + self.links.append(link) def addPackage(self, pack): self.packs.append(pack) + def getURLs(self): + return [link.url for link in self.links] + def getAllURLs(self): - urls = self.urls + urls = self.getURLs() for p in self.packs: urls.extend(p.getAllURLs()) return urls # same name and urls is enough to be equal for packages def __eq__(self, other): - return self.name == other.name and self.urls == other.urls + return self.name == other.name and self.links == other.links def __repr__(self): - return u"<CrypterPackage name=%s, links=%s, packs=%s" % (self.name, self.urls, self.packs) + return u"<CrypterPackage name=%s, links=[%s], packs=%s" % (self.name, ",".join(str(l) for l in self.links), + self.packs) def __hash__(self): - return hash(self.name) ^ hash(frozenset(self.urls)) ^ hash(self.name) + return hash(self.name) ^ hash(frozenset(self.links)) ^ hash(self.name) class PyFileMockup: @@ -53,7 +63,7 @@ class PyFileMockup: def __init__(self, url, pack): self.url = url self.name = url - self._package = pack + self._package = None self.packageid = pack.id if pack else -1 def package(self): @@ -91,18 +101,21 @@ class Crypter(Base): QUEUE_DECRYPT = False @classmethod - def decrypt(cls, core, url_or_urls): + def decrypt(cls, core, url_or_urls, password=None): """Static method to decrypt urls or content. Can be used by other plugins. To decrypt file content prefix the string with ``CONTENT_PREFIX `` as seen above. :param core: pyLoad `Core`, needed in decrypt context :param url_or_urls: List of urls or single url/ file content + :param password: optional password used for decrypting + + :raises Exception: No decryption errors are cascaded :return: List of decrypted urls, all package info removed """ urls = to_list(url_or_urls) - p = cls(core) + p = cls(core, password) try: - result = p.processDecrypt(urls) + result = p._decrypt(urls) finally: p.clean() @@ -113,12 +126,12 @@ class Crypter(Base): ret.extend(url_or_pack.getAllURLs()) else: # single url ret.append(url_or_pack) - # eliminate duplicates + # eliminate duplicates return uniqify(ret) # TODO: pass user to crypter # TODO: crypter could not only know url, but also the name and size - def __init__(self, core, package=None, password=None): + def __init__(self, core, password=None): Base.__init__(self, core) self.req = None @@ -131,8 +144,6 @@ class Crypter(Base): if self.req is None: self.req = core.requestFactory.getRequest() - # Package the plugin was initialized for, don't use this, its not guaranteed to be set - self.package = package #: Password supplied by user self.password = password @@ -186,7 +197,7 @@ class Crypter(Base): return [Package(name, purls) for name, purls in parseNames([(url, url) for url in urls]).iteritems()] def _decrypt(self, urls): - """ Internal method to select decrypting method + """Internal method to select decrypting method :param urls: List of urls/content :return: @@ -208,7 +219,7 @@ class Crypter(Base): self.logDebug("Deprecated .decrypt() method in Crypter plugin") result = [] for url in urls: - self.pyfile = PyFileMockup(url, self.package) + self.pyfile = PyFileMockup(url) self.setup() self.decrypt(self.pyfile) result.extend(self.convertPackages()) @@ -223,22 +234,12 @@ class Crypter(Base): result.extend(to_list(self.decryptFile(c))) try: if f.startswith("tmp_"): remove(f) - except: - pass + except IOError: + self.logWarning(_("Could not remove file '%s'") % f) + self.core.print_exc() return result - def processDecrypt(self, urls): - """Catches all exceptions in decrypt methods and return results - - :return: Decrypting results - """ - try: - return to_list(self._decrypt(urls)) - except Exception: - self.core.print_exc() - return [] - def getLocalContent(self, urls): """Load files from disk and separate to file content and url list diff --git a/pyload/plugins/Hoster.py b/pyload/plugins/Hoster.py index bc1e4f9d0..4d96c5730 100644 --- a/pyload/plugins/Hoster.py +++ b/pyload/plugins/Hoster.py @@ -58,16 +58,14 @@ class Hoster(Base): @staticmethod def getInfo(urls): """This method is used to retrieve the online status of files for hoster plugins. - It has to *yield* list of tuples with the result in this format (name, size, status, url), - where status is one of API pyfile statuses. :param urls: List of urls - :return: yield list of tuple with results (name, size, status, url) + :return: yield list of :class:`LinkStatus` as result """ pass def __init__(self, pyfile): - Base.__init__(self, pyfile.m.core) + Base.__init__(self, pyfile.m.core, pyfile.owner) self.wantReconnect = False #: enables simultaneous processing of multiple downloads diff --git a/pyload/plugins/network/CurlRequest.py b/pyload/plugins/network/CurlRequest.py index 182553ed1..8d1f22450 100644 --- a/pyload/plugins/network/CurlRequest.py +++ b/pyload/plugins/network/CurlRequest.py @@ -40,6 +40,7 @@ def myurlencode(data): bad_headers = range(400, 418) + range(500, 506) +pycurl.global_init(pycurl.GLOBAL_DEFAULT) class CurlRequest(Request): """ Request class based on libcurl """ |