Python Libtorrent 没有种子

标签 python seeding libtorrent torrent

我正在尝试生成一个 torrent 并使用 python libtorrent 为其提供种子,它会生成 torrent,但不会为其提供种子。

我在 Ubuntu 14.04 上使用 libtorrent-0.16.18 和 Python3.4

import sys
import time
import libtorrent as lt

fs = lt.file_storage()
lt.add_files(fs, "./test.txt")
t = lt.create_torrent(fs)
t.add_tracker("udp://tracker.publicbt.com:80")
t.set_creator("My Torrent")
t.set_comment("Test")
lt.set_piece_hashes(t, ".")
torrent = t.generate()

f = open("mytorrent.torrent", "wb")
f.write(lt.bencode(torrent))
f.close()

ses = lt.session()
ses.listen_on(6881, 6891)
h = ses.add_torrent({'ti': lt.torrent_info(torrent), 'save_path': '/tmp', 'seed_mode': True})

while h.is_seed():
    s = h.status()
    state_str = ['queued', 'checking', 'downloading metadata', \
      'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']

    print('\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \
      (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state]))
    sys.stdout.flush()

    time.sleep(1)

最佳答案

可能是因为您从当前工作目录(“.”)中的文件创建 torrent,但是当您将 torrent 添加到 session 时,您指定 /tmp 作为下载目录。据推测 test.txt 不存在于 /tmp 中。如果将 save_path 设置为“.”相反,它可能会播种。

关于Python Libtorrent 没有种子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27090466/

相关文章:

c++ - 链接静态库与共享库问题

python - 为什么 utorrents Magnet 到 Torrent 文件的获取速度比我的 python 脚本更快?

javascript - 我如何从客户端(html)拍照并将其保存到服务器端(Python)

ruby-on-rails - 显示页面未能沿(rails)传递种子数据

python - 在 python 中使用 "*"

ruby-on-rails - rails : Invalid byte sequence in US-ASCII (Argument Error) when I run rake db:seed

php - Laravel 迁移过程中出现 SQL Error 20006

hadoop - 如何通过hdfs MapReduce直接计算hdfs上文件的磁链?

python - 在 forms.py 中使用请求对象

python - Django 模型 ForeignKey 返回 ID