你如何获得种子文件的总大小?
有什么方法可以获取 torrent 中的文件数量和每个文件的大小?
如果您查看 C++ API,您会发现页面下方的torrent-info
和file_iterator
方法为您提供了您正在寻找的信息。python 绑定部分指出:
python 接口与 C++ 接口几乎相同。
因此,您应该能够轻松掌握这些方法。
h = ses.add_torrent(params)
s = h.status()
while (not h.is_seed()):
print s.total_wanted # prints total size wanted after meta data is obtained, before that 0 is printed.
/usr/local/bin/torrent-size.py
#!/usr/bin/env python3
import libtorrent
import sys
torsize = 0
info = libtorrent.torrent_info(str(sys.argv[1]))
for f in info.files():
torsize += f.size
print(torsize/1048576, "MB")
这将为您提供作为脚本第一个参数提供的 torrent 的文件大小。以下是安装 libtorrent 和 libtorrent python 绑定的说明。如果你在 Ubuntu 上遇到 cxxstd 的错误,你需要下载 boost 1.76,引导它,安装它,然后将源目录复制到 /usr/share/boost-build 并导出 BOOST_ROOT=/usr/share/boost-build 和导出 BOOST_BUILD=/usr/share/boost-build。
苹果系统:
brew install boost boost-build openssl@1.1 python3
git clone --recurse-submodules https://github.com/arvidn/libtorrent.git
cd libtorrent
echo "using darwin ;" >>~/user-config.jam
python3 setup.py build_ext --b2-args="cxxstd=14 openssl-include=/usr/local/opt/openssl@1.1/include dht=on asserts=production encryption=on crypto=openssl variant=release deprecated-functions=on i2p=on extensions=on streaming=on mmap-disk-io=on" install
echo '#!/usr/bin/env python3\n\nimport libtorrent\nimport sys\n\ntorsize = 0\ninfo = libtorrent.torrent_info(str(sys.argv[1]))\nfor f in info.files():\n\ttorsize += f.size\nprint(torsize/1048576, "MB")' > /usr/local/bin/torrent-size.py
chmod 0755 /usr/local/bin/torrent-size.py
torrent-size.py example.torrent
*buntu/debian/kali
sudo apt-get install libboost-tools-dev libboost-dev libboost-system-dev python3-all python3-dev build-essential gcc openssl
git clone --recurse-submodules https://github.com/arvidn/libtorrent.git
cd libtorrent
echo "using gcc ;" >>~/user-config.jam
python3 setup.py build_ext --b2-args="cxxstd=14 dht=on asserts=production encryption=on crypto=openssl variant=release deprecated-functions=on i2p=on extensions=on streaming=on mmap-disk-io=on" install
echo '#!/usr/bin/env python3\n\nimport libtorrent\nimport sys\n\ntorsize = 0\ninfo = libtorrent.torrent_info(str(sys.argv[1]))\nfor f in info.files():\n\ttorsize += f.size\nprint(torsize/1048576, "MB")' > /usr/local/bin/torrent-size.py
chmod 0755 /usr/local/bin/torrent-size.py
torrent-size.py example.torrent