[英]python: extracting a .bz2 compressed file from a torrent file
我有一個.torrent文件,其中包含.bz2文件。 我確信這樣的文件實際上在.torrent中,因為我用utorrent提取了.bz2。
我該如何在python中做同樣的事情而不是使用utorrent?
我已經看到了很多用於處理python中的.torrent文件的庫,但是顯然沒有我需要的庫。 在我失敗的嘗試中,我可以提到:
import torrent_parser as tp
file_cont = tp.parse_torrent_file('RC_2015-01.bz2.torrent')
file_cont
現在是字典,並且file_cont['info']['name']='RC_2015-01.bz2'
但是如果我嘗試打開文件,即
from bz2 import BZ2File
with BZ2File(file_cont['info']['name']) as f:
what_I_want = f.read()
那么字典的內容(顯然,我會說)被解釋為路徑,我得到
No such file or directory: 'RC_2015-01.bz2'
其他嘗試甚至更具破壞性。
.torrent
文件只是一個元數據文件 ,指示從何處獲取數據和文件名。 您無法從該文件獲取文件內容。
僅當您成功(使用torrent軟件)將該torrent文件下載到磁盤后,才可以使用BZ2File打開它(如果是.bz2
格式)。
如果要使用Python進行實際下載,我發現的唯一選擇是torrent-dl ,該文件兩年沒有更新。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.