python: 从 torrent 文件中提取 .bz2 压缩文件

python: extracting a .bz2 compressed file from a torrent file

我有一个包含 .bz2 文件的 .torrent 文件。我确信这样的文件实际上在 .torrent 中,因为我用 utorrent 提取了 .bz2。

如何在 python 中做同样的事情而不是使用 utorrent?

我在 python 中看到了很多用于处理 .torrent 文件的库,但显然 none 可以满足我的需要。在我不成功的尝试中,我可以提到:

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文件只是一个metadata file,指明从哪里获取数据和文件的文件名。您无法从该文件中获取文件内容。

只有在您成功将此 torrent 文件下载到磁盘后(使用 torrent 软件),您才能使用 BZ2File 打开它(如果它是 .bz2 格式)。

如果你想用 Python 执行实际下载,我找到的唯一选项是 torrent-dl,它已经 2 年没有更新了。