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, password) try: result = p._decrypt(urls) finally: p.clean() ret = [] for url_or_pack in result: if isinstance(url_or_pack, Package): # package ret.extend(url_or_pack.getAllURLs()) else: # single url ret.append(url_or_pack) # eliminate duplicates return uniqify(ret)
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, password) try: result = p._decrypt(urls) finally: p.clean() ret = [] for url_or_pack in result: if isinstance(url_or_pack, Package): #package ret.extend(url_or_pack.getAllURLs()) elif isinstance(url_or_pack, LinkStatus): #link ret.append(url_or_pack.url) else: core.log.debug("Invalid decrypter result: " + url_or_pack) return uniqify(ret)
def _decrypt(self, urls): """Internal method to select decrypting method :param urls: List of urls/content :return: """ cls = self.__class__ # separate local and remote files content, urls = self.getLocalContent(urls) result = [] if urls and has_method(cls, "decrypt"): self.logDebug("Deprecated .decrypt() method in Crypter plugin") result = [] for url in urls: self.pyfile = PyFileMockup(url) self.setup() self.decrypt(self.pyfile) result.extend(self.convertPackages()) elif urls: method = True try: self.setup() 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
def _decrypt(self, urls): """Internal method to select decrypting method :param urls: List of urls/content :return: (links, packages) """ cls = self.__class__ # separate local and remote files content, urls = self.getLocalContent(urls) result = [] if urls and has_method(cls, "decrypt"): self.logDebug("Deprecated .decrypt() method in Crypter plugin") result = [] for url in urls: self.pyfile = PyFileMockup(url, cls.__name__) self.setup() self.decrypt(self.pyfile) result.extend(self.convertPackages()) elif urls: method = True try: self.setup() 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 to_link_list(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 _decrypt(self, urls): """ Internal method to select decrypting method :param urls: List of urls/content :return: """ cls = self.__class__ # separate local and remote files content, urls = self.getLocalContent(urls) 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"): self.logDebug("Deprecated .decrypt() method in Crypter plugin") result = [] for url in urls: self.pyfile = PyFileMockup(url, self.package) 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: self.setup() result.extend(to_list(self.decryptFile(c))) try: if f.startswith("tmp_"): remove(f) except: pass return result
def _decrypt(self, urls): """Internal method to select decrypting method :param urls: List of urls/content :return: """ cls = self.__class__ # separate local and remote files content, urls = self.getLocalContent(urls) 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"): self.logDebug("Deprecated .decrypt() method in Crypter plugin") result = [] for url in urls: self.pyfile = PyFileMockup(url) 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: 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
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) self.links.append(link)
def getProgressList(self, user=None): info = [] for thread in self.threads: # skip if not belong to current user if user is not None and thread.owner != user: continue progress = thread.getProgress() if progress: info.extend(to_list(progress)) return info
def getProgressList(self, user=None): info = [] for thread in self.threads + self.localThreads: # skip if not belong to current user if user is not None and thread.owner != user: continue progress = thread.getProgress() if progress: info.extend(to_list(progress)) return info
def decrypt(cls, core, url_or_urls): """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 :return: List of decrypted urls, all package info removed """ urls = to_list(url_or_urls) p = cls(core) try: result = p.processDecrypt(urls) finally: p.clean() ret = [] for url_or_pack in result: if isinstance(url_or_pack, Package): #package ret.extend(url_or_pack.getAllURLs()) else: # single url ret.append(url_or_pack) # eliminate duplicates return uniqify(ret)
def __new__(cls, f, *args, **kwargs): for ev in to_list(event): addonManager.addEventListener(class_name(f.__module__), f.func_name, ev) return f
def addLinks(self, links): """ Add one or multiple links to the package :param links: One or list of urls or :class:`LinkStatus` """ self.links.extend(to_link_list(to_list(links)))