def download_file(self, magnet_link, filename, download_subtitles=True): assert self.thread.is_alive() assert any( filename.endswith(ext) for ext in settings.SUPPORTED_EXTENSIONS) magnet_hash = torrent.get_hash(magnet_link) if self.get_file_status(magnet_hash, filename)["status"] in [ FileStatus.READY, FileStatus.CONVERTING, ]: return download_path = _get_download_path(magnet_hash, filename) if download_path: http_download_progress = self.http_downloader.downloads.get( download_path) if http_download_progress is None: cached_url = http_cache.get_cached_url(magnet_hash, filename) if cached_url: self.http_downloader.download_file(cached_url, download_path) self.torrent_client.download_file(magnet_link, filename) h = self.torrent_client.torrents.get(magnet_hash) h.set_download_limit(settings.TORRENT_DOWNLOAD_LIMIT) h.set_upload_limit(settings.TORRENT_UPLOAD_LIMIT) if download_subtitles: for filename in _subtitle_filenames( self.torrent_client.torrents.get(magnet_hash), filename): self.torrent_client.download_file(magnet_link, filename)
def magnet_download(): magnet_link = request.form.get("magnet_link") filename = request.form.get("filename") magnet_hash = torrent.get_hash(magnet_link) if daemon.get_file_status(magnet_hash, filename)["status"] != FileStatus.READY: daemon.download_file(magnet_link, filename) return jsonify(magnet_hash=magnet_hash)
def download_file(self, magnet_link, filename, download_subtitles=True): assert self.thread.is_alive() assert any( filename.endswith(ext) for ext in settings.SUPPORTED_EXTENSIONS) magnet_hash = torrent.get_hash(magnet_link) if self.get_file_status(magnet_hash, filename)["status"] in [ FileStatus.READY, FileStatus.CONVERTING, ]: return self.torrent_client.download_file(magnet_link, filename) if download_subtitles: for filename in _subtitle_filenames( self.torrent_client.torrents.get(magnet_hash), filename): self.torrent_client.download_file(magnet_link, filename)
def search(searchterm): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) piratebay_results, kat_results = loop.run_until_complete( asyncio.gather( * [piratebay.search(searchterm), kickasstorrents.search(searchterm)])) merged_results = sorted(piratebay_results + kat_results, key=lambda x: x["seeds"], reverse=True) result_map = {} for result in merged_results: magnet_link = result["magnet"] magnet_hash = torrent.get_hash(magnet_link) if not result_map.get(magnet_hash): result_map[magnet_hash] = result cleaned_results = sorted(result_map.values(), key=lambda x: x["seeds"], reverse=True) return jsonify(results=cleaned_results)
def magnet_info(): magnet_link = request.form.get("magnet_link") magnet_hash = torrent.get_hash(magnet_link) if not _get_files(magnet_hash): daemon.fetch_filelist_from_link(magnet_link) return jsonify(magnet_hash=magnet_hash)
def search(searchterm): magnet_links = [] try: resp = requests.get( f"{settings.JACKETT_HOST}/api/v2.0/indexers/all/results?apikey={settings.JACKETT_API_KEY}&Query={searchterm}" ) data = resp.json() results = data["Results"] hashes = [] results = sorted(results, key=lambda x: x.get("Seeders", 0), reverse=True) pattern = re.compile("\s(s\d\d)(e\d\d)?") season = None episode = None try: season = pattern.search(searchterm.lower())[1] episode = pattern.search(searchterm.lower())[2] except Exception as e: pass if season and (episode is None): def sort_by_only_season(x): pattern = re.compile("([e|E]\d\d)") try: pattern.search(x.get("Title", ""))[0] return 0 except: return 1 results = sorted(results, key=sort_by_only_season, reverse=True) for result in results: if (searchterm == "" and result.get("TrackerId") in settings.EXCLUDE_TRACKERS_FROM_TRENDING): continue elif (result.get("Link") or result.get("MagnetUri")) and result.get("Title"): magnet_uri = result.get("MagnetUri") if magnet_uri: magnet_hash = torrent.get_hash(magnet_uri) if torrent.get_hash(magnet_uri) in hashes: continue hashes.append(magnet_hash) if result.get("Seeders") == 0: continue published = result.get("PublishDate") magnet_links.append( dict( seeds=result.get("Seeders", 0), title=result["Title"], magnet=result.get("MagnetUri"), torrent_link=result.get("Link"), published=parse(published) if published else None, )) except Exception: log.write_log() return magnet_links
def magnet_download(): magnet_link = request.form.get("magnet_link") filename = request.form.get("filename") magnet_hash = torrent.get_hash(magnet_link) daemon.download_file(magnet_link, filename) return jsonify(magnet_hash=magnet_hash)