【问题标题】:python: extracting a .bz2 compressed file from a torrent filepython:从种子文件中提取.bz2压缩文件
【发布时间】: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


【解决方案1】:

.torrent 文件只是一个metadata file,指示从何处获取数据和文件的文件名。您无法从该文件中获取文件内容。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多