博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
将BT转为磁力链接
阅读量:4619 次
发布时间:2019-06-09

本文共 746 字,大约阅读时间需要 2 分钟。

实战代码

安装完成后,我们来看下代码:

系统环境:Linux

Python环境:Python2.7

请注意python版本

bt2url.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#! /usr/local/bin/python
# @desc python通过BT种子生成磁力链接 
# @date 2015/11/10
# @author pythontab.com
import 
bencode
import 
sys
import 
hashlib
import 
base64
import 
urllib
#获取参数
torrentName 
= 
sys.argv[
1
]
#读取种子文件
torrent 
= 
open
(torrentName, 
'rb'
).read()
#计算meta数据
metadata 
= 
bencode.bdecode(torrent)
hashcontents 
= 
bencode.bencode(metadata[
'info'
])
digest 
= 
hashlib.sha1(hashcontents).digest()
b32hash 
= 
base64.b32encode(digest)
#打印
print 
'magnet:?xt=urn:btih:%s' 
% 
b32hash

如何使用?

命令:

1
python bt2url.py 
test
.torrent

结果:

1
magnet:?xt=urn:btih:MWXFHXOGE2UMR7WBFZYEJPM3LF2VIHNH

转载于:https://www.cnblogs.com/work115/p/5581067.html

你可能感兴趣的文章
制作docker镜像
查看>>
第一阶段冲刺个人总结
查看>>
iOS - 静态类库 打包 C,C++文件及和OC混编
查看>>
版本号严格遵守semver语义化标准
查看>>
JVM性能调优监控命令jps、jinfo、jstat、jmap+jhat、jstack使用详解
查看>>
BZOJ1977 [BeiJing2010组队]次小生成树 Tree
查看>>
Meta http-equiv属性详解(转)
查看>>
Git的初步学习
查看>>
字符串匹配 ?kmp : hash
查看>>
mongod.service: control process exited, code=exited status=1
查看>>
vue npm 安装
查看>>
SQL表值函数和标量值函数的区别
查看>>
loj #2007. 「SCOI2015」国旗计划
查看>>
大照片背景在网页设计中应用的精美作品范例(下篇)
查看>>
c# 发送邮件、附件 分类: C# 2014-12-...
查看>>
对360来说,江湖上再无“搜狗”这个传说
查看>>
composer
查看>>
OpenCV特征点检测——ORB特征
查看>>
mysql的csv数据导入与导出
查看>>
leetcode笔记:Pascal's Triangle
查看>>