summaryrefslogtreecommitdiffstats
path: root/pyload/plugins/internal/SimpleCrypter.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugins/internal/SimpleCrypter.py')
-rw-r--r--pyload/plugins/internal/SimpleCrypter.py135
1 files changed, 81 insertions, 54 deletions
diff --git a/pyload/plugins/internal/SimpleCrypter.py b/pyload/plugins/internal/SimpleCrypter.py
index 6c5c9593f..634ec5f12 100644
--- a/pyload/plugins/internal/SimpleCrypter.py
+++ b/pyload/plugins/internal/SimpleCrypter.py
@@ -2,22 +2,28 @@
import re
+from urlparse import urlparse
+
from pyload.plugins.Crypter import Crypter
-from pyload.plugins.internal.SimpleHoster import PluginParseError, replace_patterns, set_cookies
+from module.plugins.Plugin import Fail
+from module.plugins.internal.SimpleHoster import _error, _wait, parseFileInfo, replace_patterns, set_cookies
from pyload.utils import fixup, html_unescape
class SimpleCrypter(Crypter):
- __name__ = "SimpleCrypter"
- __type__ = "crypter"
- __version__ = "0.13"
+ __name__ = "SimpleCrypter"
+ __type__ = "crypter"
+ __version__ = "0.28"
- __pattern__ = None
+ __pattern__ = r'^unmatchable$'
+ __config__ = [("use_subfolder", "bool", "Save package to subfolder", True), #: Overrides core.config['general']['folder_per_package']
+ ("subfolder_per_package", "bool", "Create a subfolder for each package", True)]
__description__ = """Simple decrypter plugin"""
- __authors__ = [("stickell", "l.stickell@yahoo.it"),
- ("zoidberg", "zoidberg@mujmail.cz"),
- ("Walter Purcaro", "vuolter@gmail.com")]
+ __license__ = "GPLv3"
+ __authors__ = [("stickell", "l.stickell@yahoo.it"),
+ ("zoidberg", "zoidberg@mujmail.cz"),
+ ("Walter Purcaro", "vuolter@gmail.com")]
"""
@@ -26,8 +32,8 @@ class SimpleCrypter(Crypter):
LINK_PATTERN: group(1) must be a download link or a regex to catch more links
example: LINK_PATTERN = r'<div class="link"><a href="(.+?)"'
- TITLE_PATTERN: (optional) group(1) should be the folder name or the webpage title
- example: TITLE_PATTERN = r'<title>Files of: ([^<]+) folder</title>'
+ NAME_PATTERN: (optional) folder name or webpage title
+ example: NAME_PATTERN = r'<title>Files of: (?P<N>[^<]+) folder</title>'
OFFLINE_PATTERN: (optional) Checks if the file is yet available online
example: OFFLINE_PATTERN = r'File (deleted|not found)'
@@ -46,87 +52,103 @@ class SimpleCrypter(Crypter):
and its loadPage method:
+
def loadPage(self, page_n):
return the html of the page number page_n
"""
- TITLE_REPLACEMENTS = [("&#?\w+;", fixup)]
- URL_REPLACEMENTS = []
+ LINK_PATTERN = None
+
+ NAME_REPLACEMENTS = [("&#?\w+;", fixup)]
+ URL_REPLACEMENTS = []
TEXT_ENCODING = False #: Set to True or encoding name if encoding in http header is not correct
- COOKIES = True #: or False or list of tuples [(domain, name, value)]
+ COOKIES = True #: or False or list of tuples [(domain, name, value)]
LOGIN_ACCOUNT = False
LOGIN_PREMIUM = False
+ #@TODO: remove in 0.4.10
+ def init(self):
+ self.info = {}
+
+ account_name = (self.__name__ + ".py").replace("Folder.py", "").replace(".py", "")
+ account = self.core.accountManager.getAccountPlugin(account_name)
+
+ if account and account.canUse():
+ self.user, data = account.selectAccount()
+ self.req = account.getAccountRequest(self.user)
+ self.premium = account.isPremium(self.user)
+
+ self.account = account
+
+
def prepare(self):
if self.LOGIN_ACCOUNT and not self.account:
- self.fail('Required account not found!')
+ self.fail(_("Required account not found"))
if self.LOGIN_PREMIUM and not self.premium:
- self.fail('Required premium account not found!')
+ self.fail(_("Required premium account not found"))
if isinstance(self.COOKIES, list):
set_cookies(self.req.cj, self.COOKIES)
+ self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS)
- def decrypt(self, pyfile):
- self.prepare()
+ if self.html is None:
+ self.html = self.load(self.pyfile.url, decode=not self.TEXT_ENCODING, cookies=bool(self.COOKIES))
- pyfile.url = replace_patterns(pyfile.url, self.URL_REPLACEMENTS)
+ if isinstance(self.TEXT_ENCODING, basestring):
+ self.html = unicode(self.html, self.TEXT_ENCODING)
- self.html = self.load(pyfile.url, decode=not self.TEXT_ENCODING)
- self.checkOnline()
+ def decrypt(self, pyfile):
+ self.prepare()
- package_name, folder_name = self.getPackageNameAndFolder()
+ if self.html is None:
+ self.fail(_("No html retrieved"))
- self.package_links = self.getLinks()
+ if not self.info:
+ self.getFileInfo()
+
+ self.links = self.getLinks()
if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'):
self.handleMultiPages()
- self.logDebug("Package has %d links" % len(self.package_links))
+ self.logDebug("Package has %d links" % len(self.links))
- if self.package_links:
- self.packages = [(package_name, self.package_links, folder_name)]
- else:
- self.fail('Could not extract any links')
+ if self.links:
+ self.packages = [(self.info['name'], self.links, self.info['folder'])]
- def getLinks(self):
- """
- Returns the links extracted from self.html
- You should override this only if it's impossible to extract links using only the LINK_PATTERN.
- """
- return re.findall(self.LINK_PATTERN, self.html)
+ def getFileInfo(self):
+ name, size, status, url = parseFileInfo(self)
+ if name and name != url:
+ self.pyfile.name = name
+ else:
+ self.pyfile.name = self.info['name'] = urlparse(html_unescape(name)).path.split("/")[-1]
- def checkOnline(self):
- if hasattr(self, "OFFLINE_PATTERN") and re.search(self.OFFLINE_PATTERN, self.html):
+ if status is 1:
self.offline()
- elif hasattr(self, "TEMP_OFFLINE_PATTERN") and re.search(self.TEMP_OFFLINE_PATTERN, self.html):
+
+ elif status is 6:
self.tempOffline()
+ self.info['folder'] = self.pyfile.name
- def getPackageNameAndFolder(self):
- if hasattr(self, 'TITLE_PATTERN'):
- try:
- m = re.search(self.TITLE_PATTERN, self.html)
- name = replace_patterns(m.group(1).strip(), self.TITLE_REPLACEMENTS)
- folder = html_unescape(name)
- except:
- pass
- else:
- self.logDebug("Found name [%s] and folder [%s] in package info" % (name, folder))
- return name, folder
+ self.logDebug("FILE NAME: %s" % self.pyfile.name)
+ return self.info
- 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
+ def getLinks(self):
+ """
+ Returns the links extracted from self.html
+ You should override this only if it's impossible to extract links using only the LINK_PATTERN.
+ """
+ return re.findall(self.LINK_PATTERN, self.html)
def handleMultiPages(self):
@@ -138,8 +160,13 @@ class SimpleCrypter(Crypter):
for p in xrange(2, pages + 1):
self.html = self.loadPage(p)
- self.package_links += self.getLinks()
+ self.links += self.getLinks()
+
+
+ #@TODO: Remove in 0.4.10
+ def wait(self, seconds=0, reconnect=None):
+ return _wait(self, seconds, reconnect)
- def parseError(self, msg):
- raise PluginParseError(msg)
+ def error(self, reason="", type="parse"):
+ return _error(self, reason, type)