如何获得torrent中文件的总大小?
有没有办法获取torrent中的文件数量和每个文件的大小?
答案 0 :(得分:1)
如果您查看C ++ API,您会发现页面上的torrent-info
和file_iterator
方法可以为您提供所需的信息。 python bindings部分声明:
python接口几乎与C ++接口相同。
所以你应该能够轻松地完成这些方法。
答案 1 :(得分:1)
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.
答案 2 :(得分:0)
/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。
macOS:
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