def decrypt(cls, core, 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 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(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.get_all_urls()) elif isinstance(url_or_pack, LinkStatus): #: link ret.append(url_or_pack.url) else: core.log.debug( "Invalid decrypter result: {0}".format(url_or_pack)) return uniqify(ret)
def check_html(self, html, url): """ Parses html content or any arbitrary text for links and returns result of `check_urls` :param html: html source :return: """ urls = [] if html: urls += [x[0] for x in _re_urlmatch.findall(html)] if url: page = get_url(url) urls += [x[0] for x in _re_urlmatch.findall(page)] return self.check_links(uniqify(urls))
def _pack_result(self, packages): # generated packages packs = {} # urls without package urls = [] # merge urls and packages for pack in packages: if isinstance(pack, Package): if pack.name in packs: packs[pack.name].urls.extend(pack.urls) elif not pack.name: urls.extend(pack.links) else: packs[pack.name] = pack else: urls.append(pack) return uniqify(urls), list(packs.values())
def decrypt(self, plugin_map, password=None, err=False): result = [] self.progress = ProgressInfo("BasePlugin", "", _("decrypting"), 0, 0, len(self.data), self.owner, ProgressType.Decrypting) # TODO: QUEUE_DECRYPT for name, urls in plugin_map.items(): klass = self.pyload.pgm.load_class("crypter", name) plugin = None plugin_result = [] # updating progress self.progress.plugin = name self.progress.name = _("Decrypting {0} links").format( len(urls) if len(urls) > 1 else urls[0]) # TODO: dependency check, there is a new error code for this # TODO: decrypting with result yielding if not klass: self.error = True if err: plugin_result.extend( LinkStatus(url, url, -1, DownloadStatus.NotPossible, name) for url in urls) self.pyload.log.debug( "Plugin '{0}' for decrypting was not loaded".format(name)) else: try: plugin = klass(self.pyload, password) try: plugin_result = plugin._decrypt(urls) except Retry: time.sleep(1) plugin_result = plugin._decrypt(urls) plugin.log_debug("Decrypted", plugin_result) except Abort: plugin.log_info(_("Decrypting aborted")) except Exception as e: plugin.log_error(_("Decrypting failed"), e.message) self.error = True # generate error linkStatus if err: plugin_result.extend( LinkStatus(url, url, -1, DownloadStatus.Failed, name) for url in urls) # no debug for intentional errors if self.pyload.debug and not isinstance(e, Fail): # self.pyload.print_exc() self.write_debug_report(plugin.__name__, plugin=plugin) finally: if plugin: plugin.clean() self.progress.done += len(urls) result.extend(plugin_result) # clear the progress self.progress = None # generated packages packs = {} # urls without package urls = [] # merge urls and packages for p in result: if isinstance(p, Package): if p.name in packs: packs[p.name].urls.extend(p.urls) else: if not p.name: urls.extend(p.links) else: packs[p.name] = p else: urls.append(p) urls = uniqify(urls) return urls, list(packs.values())
def search_suggestions(self, pattern): names = self.pyload_core.db.get_matching_filenames(pattern) # TODO: stemming and reducing the names to provide better suggestions return uniqify(names)
def search_suggestions(self, pattern): names = self.pyload.db.get_matching_filenames( pattern, self.primary_uid) # TODO: stemming and reducing the names to provide better suggestions return uniqify(names)