diff --git a/bindings/python/simple_client.py b/bindings/python/simple_client.py index 1b5edfd53..f146990fe 100755 --- a/bindings/python/simple_client.py +++ b/bindings/python/simple_client.py @@ -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: diff --git a/docs/python_binding.rst b/docs/python_binding.rst index e6539984f..fe918d660 100644 --- a/docs/python_binding.rst +++ b/docs/python_binding.rst @@ -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