python實現bt種子 torrent轉magnet


Python實現bt轉磁鏈 
參考前人資料主要兩種方式
1,利用python的bencode模塊
2,安裝libtorrent模塊
嘗試過兩種方法特記錄
環境:Windows系統  python 3
 
bencode模塊有很多,最早的一個不支持 python3,網上的實例代碼就是使用2.7 所以 結果是不行。
 選了一個bencoder.pyx 1.2.0 不知道為啥選這個 
可以參考一下他的示例
pip 安裝,上代碼
from bencoder import bencode, bdecode
import hashlib
import base64

with open("加勒比海盜5:死無對證.2017.BD720P.X264.AAC.English&Mandarin.CHS-ENG.laziku.mp4.torrent", mode='rb',) as f :
    torrent = bdecode(f.read())
    # print(bencode(torrent[b'info']))
    # print(torrent)
    # torrent = f.read()


digest = hashlib.sha1(bencode(torrent[b'info'])).digest()
# torrent[b'info'] 里面包含了種子文件的關鍵信息 對這部分進行哈希處理
b32hash = base64.b32encode(digest)
print('magnet:?xt=urn:btih:%s' % b32hash.decode())

#結果 magnet:?xt=urn:btih:7GI3YCSXAKTGIYBJYKVUVIKELGDBXLDF
我使用 bt轉磁鏈網站 得到結果 
 
用迅雷試一下 都能抓到種子
 
參考一下 關於bt種子的文件格式 文章
python2.7 的bt轉磁鏈 代碼
 
 
libtorrent 的處理代碼更加簡單,里面封裝好了方法 直接調用就可以
不 過我在win環境下 這個模塊安裝出錯,
 摘記一下代碼
 
參考文章:http://www.au92.com/archives/P-y-t-h-o-n-jiang-B-T-zhong-zi-wen-jian-zhuan-huan-wei-ci-li-lian-de-liang-zhong-fang-fa.html
 
 
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM