python解析torrent文件庫:p
- 2020 年 1 月 3 日
- 筆記
pytorrent是一個非常小巧的用來解析解析torrent文件python庫。核心程式碼不足150行,卻能夠完備地解析torrent文件,並支援導出修改後的torrent文件。
使用演示:
import pytorrent t=pytorrent.Torrent() t.load("test.torrent") #your torrent file print t.data["info"]["name"].decode("utf-8") files=t.data["info"]["files"] for item in files: print item["path"][0].decode("utf-8") t.data["info"]["name"]="my_name" #change info. t.dump("dump.torrent") #the new torrent file
該庫把torrent文件結構映射到python的dict,list,integer,string四種類型,直接操作這四種數據就能讀取和修改torrent文件的一切資訊。