使用libtorrent-python下载Torrent [英] Downloading a Torrent with libtorrent-python

查看:303
本文介绍了使用libtorrent-python下载Torrent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下python代码:

I have the following python code:

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)

似乎可以正常工作,但随后会降低到小于一个字节/秒的速度:

Which seems to work fine, but then slows down to less than a byte/s:

$ 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

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

It slows down and never completes. Any idea why this happens?

推荐答案

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

The problem turned out to be trivial. The save_path did not exist, thus the libtorrent library downloaded as long as it did not have to flush the cache, but once it attempted to write the file, it failed and could not continue downloading, therefore the slowdown and eventual halt. Once an existing path was added it worked fine.

这篇关于使用libtorrent-python下载Torrent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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