生活随笔
收集整理的這篇文章主要介紹了
将BT转为磁力链接
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實戰代碼
安裝完成后,我們來看下代碼:
系統環境: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
|
importbencode
importsys
importhashlib
importbase64
importurllib
torrentName=sys.argv[1]
torrent=open(torrentName,'rb').read()
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
|
pythonbt2url.pytest.torrent
|
結果:
|
1
|
magnet:?xt=urn:btih:MWXFHXOGE2UMR7WBFZYEJPM3LF2VIHNH
|
總結
以上是生活随笔為你收集整理的将BT转为磁力链接的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。