gpt4 book ai didi

python - 使用 libtorrent-python 下载 Torrent

转载 作者:太空狗 更新时间:2023-10-29 16:56:27 27 4
gpt4 key购买 nike

我有以下 python 代码:

import libtorrent as lt
import time

ses = lt.session()
ses.listen_on(6881, 6891)
params = {
'save_path': '/home/downloads/',
'storage_mode': lt.storage_mode_t(2),
'paused': False,
'auto_managed': True,
'duplicate_is_error': True}
link = "magnet:?xt=urn:btih:4MR6HU7SIHXAXQQFXFJTNLTYSREDR5EI&tr=http://tracker.vodo.net:6970/announce"
handle = lt.add_magnet_uri(ses, link, params)
ses.start_dht()

print 'downloading metadata...'
while (not handle.has_metadata()):
time.sleep(1)
print 'got metadata, starting torrent download...'
while (handle.status().state != lt.torrent_status.seeding):
s = handle.status()
state_str = ['queued', 'checking', 'downloading metadata', \
'downloading', 'finished', 'seeding', 'allocating']
print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s %.3' % \
(s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
s.num_peers, state_str[s.state], s.total_download/1000000)
time.sleep(5)

这似乎工作正常,但随后减慢到不到一个字节/秒:

$ python test.py 
downloading metadata...
got metadata, starting torrent download...
0.00% complete (down: 195.0 kb/s up: 8.0 kB/s peers: 28) checking 3.069
0.00% complete (down: 133.0 kb/s up: 5.0 kB/s peers: 28) checking 3.342
0.00% complete (down: 29.0 kb/s up: 1.0 kB/s peers: 28) checking 3.359
0.00% complete (down: 5.0 kb/s up: 0.0 kB/s peers: 28) checking 3.398
0.00% complete (down: 4.0 kb/s up: 0.0 kB/s peers: 28) checking 3.401
0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 28) checking 3.405
0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 28) checking 3.408
0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 28) checking 3.412

它会变慢并且永远不会完成。知道为什么会这样吗?

最佳答案

这个问题原来是微不足道的。 save_path 不存在,因此 libtorrent 库只要它不必刷新缓存就可以下载,但是一旦它尝试写入文件,它就会失败并且无法继续下载,因此速度变慢并最终停止。一旦添加了现有路径,它就可以正常工作。

关于python - 使用 libtorrent-python 下载 Torrent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6556657/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com