Python Libtorrent没有种子 [英] Python Libtorrent doesn't seed

查看:193
本文介绍了Python Libtorrent没有种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成一个torrent并使用python libtorrent进行种子播发,它会生成torrent,但不对其进行播种.

I'm trying to generate a torrent and seed it with python libtorrent, it generates the torrent, but doesn't seed it.

我正在Ubuntu 14.04上将libtorrent-0.16.18与Python3.4一起使用

I am using libtorrent-0.16.18 with Python3.4 on Ubuntu 14.04

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添加到会话时,您指定了作为下载目录.大概test.txt/tmp中不存在.如果将save_path设置为."相反,它可能会播种.

Probably because you create the torrent from a file in current working directory ("."), but when you add the torrent to the session, you specify /tmp as the download directory. Presumably test.txt doesn't exist in /tmp. If you set the save_path to "." instead, it might seed.

这篇关于Python Libtorrent没有种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆