从 torrent 中读取文件集
我想(快速)将程序/脚本放在一起以从 .torrent 文件中读取文件集。 然后我想使用该集删除特定目录中不属于 torrent 的任何文件。
关于从 .torrent 文件读取此索引的便捷库有什么建议吗? 虽然我不反对它,但我不想为了这个简单的目的而深入研究 BitTorrent 规范并从头开始编写大量代码。
我对语言没有偏好。
I want to (quickly) put a program/script together to read the fileset from a .torrent file. I want to then use that set to delete any files from a specific directory that do not belong to the torrent.
Any recommendations on a handy library for reading this index from the .torrent file? Whilst I don't object to it, I don't want to be digging deep into the bittorrent spec and rolling a load of code from scratch for this simple purpose.
I have no preference on language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我会使用 rasterbar 的 libtorrent,它是一个小型且快速的 C++ 库。
要迭代文件,您可以使用 torrent_info 类 (begin_files ()、end_files())。
libtorrent 还有一个 python 接口:
I would use rasterbar's libtorrent which is a small and fast C++ library.
To iterate over the files you could use the torrent_info class (begin_files(), end_files()).
There's also a python interface for libtorrent:
Effbot 已解答您的问题。 以下是从 .torrent 文件读取文件列表的完整代码(Python 2.4+):
Effbot has your question answered. Here is the complete code to read the list of files from .torrent file (Python 2.4+):
这是康斯坦丁上面的答案中的代码,稍作修改以处理 torrent 文件名中的 Unicode 字符和 torrent 信息中的文件集文件名:
Here's the code from Constantine's answer above, slightly modified to handle Unicode characters in torrent filenames and fileset filenames in torrent info:
来自原始主线 BitTorrent 5.x 客户端的 bencode.py (http:// /download.bittorrent.com/dl/BitTorrent-5.2.2.tar.gz)将为您提供几乎 Python 中的参考实现。
它对 BTL 包有导入依赖,但很容易删除。 然后您可以查看 bencode.bdecode(filecontent)['info']['files']。
bencode.py from the original Mainline BitTorrent 5.x client (http://download.bittorrent.com/dl/BitTorrent-5.2.2.tar.gz) would give you pretty much the reference implementation in Python.
It has an import dependency on the BTL package but that's trivially easy to remove. You'd then look at bencode.bdecode(filecontent)['info']['files'].
扩展上述想法,我做了以下操作:
您需要适当地设置权限以使 shell 脚本可执行:
希望这对某人有帮助:)
Expanding on the ideas above, I did the following:
You'll want to set permissions appropriately to make the shell script executable:
Hope this helps someone :)
这是上面 Alix 的代码,修改为在 python 3.x 下运行
Here is the code from Alix above, modified to run under python 3.x