# -*- coding: utf-8 -*- # # * cnl2 and web links are skipped if JS is not available (instead of failing the package) # * only best available link source is used (priority: cnl2>rsdf>ccf>dlc>web import base64 import binascii import re from Crypto.Cipher import AES from pyload.plugins.internal.SimpleCrypter import SimpleCrypter from pyload.utils import html_unescape class LinkSaveIn(SimpleCrypter): __name__ = "LinkSaveIn" __type__ = "crypter" __version__ = "2.02" __pattern__ = r'http://(?:www\.)?linksave\.in/(?P\w+)$' __config__ = [("use_subfolder", "bool", "Save package to subfolder", True), ("subfolder_per_package", "bool", "Create a subfolder for each package", True)] __description__ = """LinkSave.in decrypter plugin""" __license__ = "GPLv3" __authors__ = [("fragonib", "fragonib[AT]yahoo[DOT]es")] COOKIES = [("linksave.in", "Linksave_Language", "english")] # Constants _JK_KEY_ = "jk" _CRYPTED_KEY_ = "crypted" def setup(self): self.fileid = None self.captcha = False self.package = None self.preferred_sources = ["cnl2", "rsdf", "ccf", "dlc", "web"] def decrypt(self, pyfile): # Init self.package = pyfile.package() self.fileid = re.match(self.__pattern__, pyfile.url).group('id') # Request package self.html = self.load(pyfile.url) if not self.isOnline(): self.offline() # Check for protection if self.isPasswordProtected(): self.unlockPasswordProtection() self.handleErrors() if self.isCaptchaProtected(): self.captcha = True self.unlockCaptchaProtection() self.handleErrors() # Get package name and folder (package_name, folder_name) = self.getPackageInfo() # Extract package links package_links = [] for type_ in self.preferred_sources: package_links.extend(self.handleLinkSource(type_)) if package_links: # use only first source which provides links break package_links = set(package_links) # Pack if package_links: self.packages = [(package_name, package_links, folder_name)] def isOnline(self): if "Error 404 - Folder not found!" in self.html: self.logDebug("File not found") return False return True def isPasswordProtected(self): if re.search(r'''Captcha:" in self.html: self.logDebug("Links are captcha protected") return True return False def unlockPasswordProtection(self): password = self.getPassword() self.logDebug("Submitting password [%s] for protected links" % password) post = {"id": self.fileid, "besucherpasswort": password, 'login': 'submit'} self.html = self.load(self.pyfile.url, post=post) def unlockCaptchaProtection(self): captcha_hash = re.search(r'name="hash" value="([^"]+)', self.html).group(1) captcha_url = re.search(r'src=".(/captcha/cap.php\?hsh=[^"]+)', self.html).group(1) captcha_code = self.decryptCaptcha("http://linksave.in" + captcha_url, forceUser=True) self.html = self.load(self.pyfile.url, post={"id": self.fileid, "hash": captcha_hash, "code": captcha_code}) def getPackageInfo(self): name = self.pyfile.package().name folder = self.pyfile.package().folder self.logDebug("Defaulting to pyfile name [%s] and folder [%s] for package" % (name, folder)) return name, folder def handleErrors(self): if "The visitorpassword you have entered is wrong" in self.html: self.logDebug("Incorrect password, please set right password on 'Edit package' form and retry") self.fail(_("Incorrect password, please set right password on 'Edit package' form and retry")) if self.captcha: if "Wrong code. Please retry" in self.html: self.invalidCaptcha() self.retry() else: self.correctCaptcha() def handleLinkSource(self, type_): if type_ == "cnl2": return self.handleCNL2() elif type_ in ("rsdf", "ccf", "dlc"): return self.handleContainer(type_) elif type_ == "web": return self.handleWebLinks() else: self.error('Unknown source type "%s" (this is probably a bug)' % type_) def handleWebLinks(self): package_links = [] self.logDebug("Search for Web links") if not self.js: self.logDebug("No JS -> skip Web links") else: #@TODO: Gather paginated web links pattern = r'(.*)', res)[-1] jseval = self.js.eval("document = { write: function(e) { return e; } }; %s" % jscode) dlLink = re.search(r'http://linksave\.in/dl-\w+', jseval).group(0) self.logDebug("JsEngine returns value [%s] for redirection link" % dlLink) res = self.load(dlLink) link = html_unescape(re.search(r'