简单的 libtorrent Python 客户端 [英] Simple libtorrent Python client
问题描述
我尝试创建一个简单的 libtorrent python 客户端(用于磁铁 uri),但我失败了,该程序永远不会超过下载元数据".如果你能帮我写一个简单的客户端,那就太棒了.
I tried creating a simple libtorrent python client (for magnet uri), and I failed, the program never continues past the "downloading metadata". If you may help me write a simple client it would be amazing.
附言当我选择保存路径时,保存路径是我想要保存数据的文件夹吗?或数据本身的路径.
P.S. When I choose a save path, is the save path the folder which I want my data to be saved in? or the path for the data itself.
(我使用了某人在这里发布的代码)
(I used a code someone posted here)
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)
推荐答案
发生的情况是第一个 while 循环变成无限循环,因为状态没有改变.
What happens it is that the first while loop becomes infinite because the state does not change.
您必须添加一个 s = handle.status ();
以使元数据状态发生变化并停止循环.或者在另一个 while 内添加第一个 while 以便发生同样的情况.
You have to add a s = handle.status ();
for having the metadata the status changes and the loop stops. Alternatively add the first while inside the other while so that the same will happen.
这篇关于简单的 libtorrent Python 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!