summaryrefslogtreecommitdiffstats
path: root/pyload/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-10-08 18:47:27 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-10-08 18:47:27 +0200
commitc0f373528c55fc11d3ef592b3b1f7207306852c0 (patch)
tree822f0e717d167043887be058a56540f47d9ab4e2 /pyload/plugins
parentgzip compression for api (diff)
downloadpyload-c0f373528c55fc11d3ef592b3b1f7207306852c0.tar.xz
adapter simplecrypter plugin
Diffstat (limited to 'pyload/plugins')
-rw-r--r--pyload/plugins/Crypter.py57
-rw-r--r--pyload/plugins/internal/SimpleCrypter.py30
2 files changed, 37 insertions, 50 deletions
diff --git a/pyload/plugins/Crypter.py b/pyload/plugins/Crypter.py
index 2a65a9da2..af3d5aba7 100644
--- a/pyload/plugins/Crypter.py
+++ b/pyload/plugins/Crypter.py
@@ -3,10 +3,9 @@
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
+
class Package:
""" Container that indicates that a new package should be created """
@@ -186,15 +185,6 @@ class Crypter(Base):
"""
raise NotImplementedError
- def generatePackages(self, urls):
- """Generates :class:`Package` instances and names from urls. Useful for many different links and no\
- given package name.
-
- :param urls: list of urls
- :return: list of `Package`
- """
- 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
@@ -205,16 +195,9 @@ class Crypter(Base):
# separate local and remote files
content, urls = self.getLocalContent(urls)
+ result = []
- if has_method(cls, "decryptURLs"):
- self.setup()
- result = to_list(self.decryptURLs(urls))
- elif has_method(cls, "decryptURL"):
- result = []
- for url in urls:
- self.setup()
- result.extend(to_list(self.decryptURL(url)))
- elif has_method(cls, "decrypt"):
+ if urls and has_method(cls, "decrypt"):
self.logDebug("Deprecated .decrypt() method in Crypter plugin")
result = []
for url in urls:
@@ -222,20 +205,28 @@ class Crypter(Base):
self.setup()
self.decrypt(self.pyfile)
result.extend(self.convertPackages())
- else:
- if not has_method(cls, "decryptFile") or urls:
- self.logDebug("No suited decrypting method was overwritten in plugin")
- result = []
-
- if has_method(cls, "decryptFile"):
- for f, c in content:
+ elif urls:
+ method = True
+ try:
self.setup()
- result.extend(to_list(self.decryptFile(c)))
- try:
- if f.startswith("tmp_"): remove(f)
- except IOError:
- self.logWarning(_("Could not remove file '%s'") % f)
- self.core.print_exc()
+ result = to_list(self.decryptURLs(urls))
+ except NotImplementedError:
+ method = False
+
+ # this will raise error if not implemented
+ if not method:
+ for url in urls:
+ self.setup()
+ result.extend(to_list(self.decryptURL(url)))
+
+ for f, c in content:
+ self.setup()
+ result.extend(to_list(self.decryptFile(c)))
+ try:
+ if f.startswith("tmp_"): remove(f)
+ except IOError:
+ self.logWarning(_("Could not remove file '%s'") % f)
+ self.core.print_exc()
return result
diff --git a/pyload/plugins/internal/SimpleCrypter.py b/pyload/plugins/internal/SimpleCrypter.py
index f0fe0b764..e26bf6644 100644
--- a/pyload/plugins/internal/SimpleCrypter.py
+++ b/pyload/plugins/internal/SimpleCrypter.py
@@ -19,9 +19,8 @@
import re
-from module.plugins.Crypter import Crypter
-from module.utils import html_unescape
-
+from pyload.plugins.Crypter import Crypter, Package
+from pyload.utils import html_unescape
class SimpleCrypter(Crypter):
__name__ = "SimpleCrypter"
@@ -52,11 +51,10 @@ class SimpleCrypter(Crypter):
must return the html of the page number 'page_n'
"""
- def decrypt(self, pyfile):
- self.html = self.load(pyfile.url, decode=True)
-
- package_name, folder_name = self.getPackageNameAndFolder()
+ def decryptURL(self, url):
+ self.html = self.load(url, decode=True)
+ package_name = self.getPackageName()
self.package_links = self.getLinks()
if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'):
@@ -65,10 +63,11 @@ class SimpleCrypter(Crypter):
self.logDebug('Package has %d links' % len(self.package_links))
if self.package_links:
- self.packages = [(package_name, self.package_links, folder_name)]
+ return Package(package_name, self.package_links)
else:
self.fail('Could not extract any links')
+
def getLinks(self):
"""
Returns the links extracted from self.html
@@ -76,18 +75,15 @@ class SimpleCrypter(Crypter):
"""
return re.findall(self.LINK_PATTERN, self.html)
- def getPackageNameAndFolder(self):
+ def getPackageName(self):
if hasattr(self, 'TITLE_PATTERN'):
m = re.search(self.TITLE_PATTERN, self.html)
if m:
- name = folder = html_unescape(m.group('title').strip())
- self.logDebug("Found name [%s] and folder [%s] in package info" % (name, folder))
- return name, folder
-
- name = self.pyfile.package().name
- folder = self.pyfile.package().folder
- self.logDebug("Package info not found, defaulting to pyfile name [%s] and folder [%s]" % (name, folder))
- return name, folder
+ name = html_unescape(m.group('title').strip())
+ self.logDebug("Found name [%s] in package info" % (name))
+ return name
+
+ return None
def handleMultiPages(self):
pages = re.search(self.PAGES_PATTERN, self.html)