|
发表于 2020-2-11 13:48:59
|
显示全部楼层
本帖最后由 pwlm 于 2020-2-11 16:51 编辑
update: 这是多线程版本,如果有下载种子全部内容的需求而且种子内容非常多的情况可以用这个版本,一般下面的那个版本就够用了。
[ol]import jsonimport timeimport pyperclipimport requestsimport threadingfrom queue import Queuedef get_download_url(file_key, file_name, file_size): print(f"成功获取到文件名: {file_name} 的file_key! \n文件大小: {file_size}\n") download_url_in_json = requests.get(file_key, proxies=proxies) download_url_in_json = json.loads(download_url_in_json.text) if download_url_in_json["code"] == 1: print("无法获取下载链接! 返回中...") return "" else: download_url = download_url_in_json["data"]["download_url"] download_url_with_name = download_url + "/" + file_name return download_url_with_namedef return_download_url(result_data): global url while not qurl.empty(): index = qurl.get() file_key = analyze_download_url + result_data[index]["file_key"] file_name = result_data[index]["name"] file_size = result_data[index]["size"] file_download_url = get_download_url(file_key, file_name, file_size) if "" != file_download_url: lock.acquire() url = url + file_download_url + "\r" lock.release()def get_file_key(hash_key): hash_url = torrent_hash + hash_key analyze_result = requests.get(hash_url) analyze_result = json.loads(analyze_result.text) if analyze_result["code"] == 1: print("该hash无法解析! 返回中...") return None else: if len(analyze_result["data"]) >= 1: for i in range(len(analyze_result["data"])): print(str(i) + ": " + analyze_result["data"]["size"] + ": " + analyze_result["data"]["name"]) try: index = int(input("\n\n请输入文件前面的序列号,如果需要下载全部文件,请直接回车: ")) if index > len(analyze_result["data"]): print("\n你输入了错误的序号!") return None qurl.put(index) except ValueError: print("\n您选择下载全部文件, 开始获取下载链接\n") for x in range(len(analyze_result["data"])): qurl.put(x) finally: ths = list([]) for _ in range(thread_num): th = threading.Thread(target=return_download_url, args=(analyze_result["data"],)) th.start() ths.append(th) for th in ths: th.join() return urlproxies = Nonethread_num = 8 # 指定线程数量,如果设置的过高会获取不到下载链接analyze_download_url = "http://bt.i0x0.cn/?key=" # 后面加上上面返回的file_keytorrent_hash = "http://bt.i0x0.cn/?hash=" # 后面加上hash值qurl = Queue()lock = threading.Lock()url = ""if __name__ == '__main__': key = input("请输入种子的hash值: ") result = get_file_key(key) if result: pyperclip.copy(result) print("成功将下载链接复制到粘贴板! 去下载吧") time.sleep(2)[/ol]复制代码
------------------------------------------------------------------------
update: 楼主说: 一个次磁力里可能包含很多文件.最好是提交磁力 0是选择全部,选择其他则下载对应key值的文件...这样更人性化一下..
所以我加上了,选择序号的时候直接回车就行了
------------------------------------------------------------------------
取之用之,用楼主的api写了个脚本
[ol]import jsonimport timeimport pyperclipimport requestsdef return_download_url(result_data, index): analyze_download_url = "http://bt.i0x0.cn/?key=" # 后面加上上面返回的file_key url = str() if -1 == index: # 全部文件 for file in result_data: file_key = analyze_download_url + file["file_key"] file_name = file["name"] file_size = file["size"] url = url + get_download_url(file_key, file_name, file_size) + "\r" else: file_key = analyze_download_url + result_data[index]["file_key"] file_name = result_data[index]["name"] file_size = result_data[index]["size"] url = get_download_url(file_key, file_name, file_size) return urldef get_download_url(file_key, file_name, file_size): print(f"成功获取到file_key! \n文件名: {file_name} \n文件大小: {file_size}\n") download_url_in_json = requests.get(file_key, proxies=proxies) download_url_in_json = json.loads(download_url_in_json.text) if download_url_in_json["code"] == 1: print("无法获取下载链接! 返回中...") return "" else: download_url = download_url_in_json["data"]["download_url"] download_url_with_name = download_url + "/" + file_name return download_url_with_namedef get_file_key(hash_key): torrent_hash = "http://bt.i0x0.cn/?hash=" # 后面加上hash值 hash_url = torrent_hash + hash_key analyze_result = requests.get(hash_url) analyze_result = json.loads(analyze_result.text) if analyze_result["code"] == 1: print("该hash无法解析! 返回中...") return None else: index = 0 if len(analyze_result["data"]) >= 1: for i in range(len(analyze_result["data"])): print(str(i) + ": " + analyze_result["data"]["size"] + ": " + analyze_result["data"]["name"]) try: index = int(input("\n\n请输入文件前面的序列号,如果需要下载全部文件,请直接回车: ")) if index > len(analyze_result["data"]): print("你输入了错误的序号!") return None except: print("您选择下载全部文件, 开始获取下载链接\n") index = -1 finally: return return_download_url(analyze_result["data"], index)proxies = Noneopen_thread = Falseif __name__ == '__main__': key = input("请输入种子的hash值: ") result = get_file_key(key) if result: pyperclip.copy(result) print("成功将下载链接复制到粘贴板! 去下载吧") time.sleep(2)[/ol]复制代码
只支持python3,执行粘贴种子的hash码就行了 |
|