【发布时间】:2019-02-19 21:42:02
【问题描述】:
我有一个 .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文件不包含文件本身,对吧?您需要先下载(通过 BitTorrent 协议)该文件,然后才能存在具有此类名称的文件。 -
而python不允许这样做?
-
您可以使用(或编写)库来实际执行下载,但 Python 并不能神奇地为您完成。这是魔法,但不是那种魔法。
-
是的,我非常依赖 python 的魔法和其他人(在 python 方面比我好)编写库。
标签: python bittorrent bz2