forked from premiere/premiere-libtorrent
fix simple_client.py example, and reference it from the documentation
This commit is contained in:
parent
5e7666526e
commit
cfd50ae736
|
@ -8,8 +8,7 @@ import libtorrent as lt
|
|||
import time
|
||||
import sys
|
||||
|
||||
ses = lt.session()
|
||||
ses.listen_on(6881, 6891)
|
||||
ses = lt.session({'listen_interfaces': '0.0.0.0:6881'})
|
||||
|
||||
info = lt.torrent_info(sys.argv[1])
|
||||
h = ses.add_torrent({'ti': info, 'save_path': '.'})
|
||||
|
@ -18,11 +17,9 @@ print('starting', h.name())
|
|||
while (not 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]), end=' ')
|
||||
s.num_peers, s.state), end=' ')
|
||||
|
||||
alerts = ses.pop_alerts()
|
||||
for a in alerts:
|
||||
|
|
|
@ -110,31 +110,10 @@ To get a python dictionary of the settings, call ``session::get_settings``.
|
|||
For an example python program, see ``client.py`` in the ``bindings/python``
|
||||
directory.
|
||||
|
||||
A very simple example usage of the module would be something like this::
|
||||
A very simple example usage of the module would be something like this:
|
||||
|
||||
import libtorrent as lt
|
||||
import time
|
||||
|
||||
ses = lt.session()
|
||||
ses.listen_on(6881, 6891)
|
||||
|
||||
e = lt.bdecode(open("test.torrent", 'rb').read())
|
||||
info = lt.torrent_info(e)
|
||||
|
||||
params = { 'save_path': '.', \
|
||||
'storage_mode': lt.storage_mode_t.storage_mode_sparse, \
|
||||
'ti': info }
|
||||
h = ses.add_torrent(params)
|
||||
|
||||
s = h.status()
|
||||
while (not s.is_seeding):
|
||||
s = h.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' % \
|
||||
(s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
|
||||
s.num_peers, state_str[s.state])
|
||||
|
||||
time.sleep(1)
|
||||
.. include:: ../bindings/python/simple_client.py
|
||||
:code: python
|
||||
:tab-width: 2
|
||||
:start-after: from __future__ import print_function
|
||||
|
||||
|
|
Loading…
Reference in New Issue