From 7974e50bb8d10019ee11f146e3c43145d7fe3532 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 13 Oct 2012 16:50:07 +0000 Subject: [PATCH] merged python fix from RC_0_16 --- ChangeLog | 2 ++ bindings/python/client.py | 42 ++++++++++++++++++++------------- bindings/python/src/session.cpp | 2 +- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index fede7d334..241bb3755 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * add support for magnet links and URLs in python example client + * fixed typo in python bindings' add_torrent_params * introduce a way to add built-in plugins from python * consistently disconnect the same peer when two peers simultaneously connect * fix local endpoint queries for uTP connections diff --git a/bindings/python/client.py b/bindings/python/client.py index 35a5de893..c8429774b 100755 --- a/bindings/python/client.py +++ b/bindings/python/client.py @@ -219,22 +219,26 @@ def main(): alerts = [] for f in args: - e = lt.bdecode(open(f, 'rb').read()) - info = lt.torrent_info(e) - print('Adding \'%s\'...' % info.name()) atp = {} - try: - atp["resume_data"] = open(os.path.join(options.save_path, info.name() + '.fastresume'), 'rb').read() - except: - pass - - atp["ti"] = info atp["save_path"] = options.save_path atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse atp["paused"] = False atp["auto_managed"] = True atp["duplicate_is_error"] = True + if f.startswith('magnet:') or f.startswith('http://') or f.startswith('https://'): + atp["url"] = f + else: + e = lt.bdecode(open(f, 'rb').read()) + info = lt.torrent_info(e) + print('Adding \'%s\'...' % info.name()) + + try: + atp["resume_data"] = open(os.path.join(options.save_path, info.name() + '.fastresume'), 'rb').read() + except: + pass + + atp["ti"] = info h = ses.add_torrent(atp) @@ -293,14 +297,18 @@ def main(): print_peer_info(console, h.get_peer_info()) print_download_queue(console, h.get_download_queue()) - if True and s.state != lt.torrent_status.seeding: - out = '\n' - fp = h.file_progress() - ti = h.get_torrent_info() - for f,p in zip(ti.files(), fp): - out += progress_bar(p / f.size, 20) - out += ' ' + f.path + '\n' - write_line(console, out) + if s.state != lt.torrent_status.seeding: + try: + out = '\n' + fp = h.file_progress() + fp = 0 + ti = h.get_torrent_info() + for f,p in zip(ti.files(), fp): + out += progress_bar(p / f.size, 20) + out += ' ' + f.path + '\n' + write_line(console, out) + except: + pass write_line(console, 76 * '-' + '\n') write_line(console, '(q)uit), (p)ause), (u)npause), (r)eannounce\n') diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index ff5642ca1..21cc4fe8d 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -187,7 +187,7 @@ namespace if (params.has_key("storage_mode")) p.storage_mode = extract(params["storage_mode"]); - if (params.has_key("tracker_url")) + if (params.has_key("trackers")) { list l = extract(params["trackers"]); int n = boost::python::len(l);