Python脚本将种子文件转换为磁力链接的方法
最编程
2024-01-23 19:17:57
...
本地保存了好多种子,现在用python将种子转成磁力连接,看着好看一点,记录下在代码
2022-01-10
pip install bencode
import bencode
import hashlib
import base64
import urllib
#获取参数
torrentName = ""
#读取种子文件
torrent = open(torrentName, 'rb').read()
#计算meta数据
metadata = bencode.bdecode(torrent)
print(metadata)
hashcontents = bencode.bencode(metadata['info'])
digest = hashlib.sha1(hashcontents).digest()
b32hash = base64.b32encode(digest)
#输出打印
print('magnet:?xt=urn:btih:%s' % b32hash)
我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=cg04kvurzr22
上一篇: 将Java磁力链接转化为种子文件的方法