【问题标题】:How do you get the total size of a torrent in libtorrent?您如何获得 libtorrent 中 torrent 的总大小?
【发布时间】:2013-08-09 11:23:10
【问题描述】:

如何获取 torrent 中文件的总大小?

有没有什么方法可以获取一个 torrent 中的文件数量和每个文件的大小?

【问题讨论】:

    标签: python libtorrent


    【解决方案1】:

    如果您查看 C++ API,您会发现页面下方的 torrent-info 和 file_iterator 方法为您提供了您正在寻找的信息。 python bindings 部分指出:

    python 接口与 C++ 接口几乎相同。

    因此,您应该能够轻松掌握这些方法。

    【讨论】:

      【解决方案2】:
      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.
      

      【讨论】:

        【解决方案3】:

        /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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-04-11
          • 1970-01-01
          • 2017-06-04
          • 1970-01-01
          • 2014-03-04
          相关资源
          最近更新 更多