# Print usage message
def usage():
- print "Usage: python cmdlinedl.py [options] torrentfile_or_url"
+ print "Usage: python cmdlinedl.py [options] <list of torrentfile_or_urls separated by spaces>"
print "Options:"
print "\t--port <port>"
print "\t-p <port>\t\tuse <port> to listen for connections"
# Print torrent statistics
def state_callback(ds):
d = ds.get_download()
- print >>sys.stderr, 'peers: %s status: %s progres: %5.2f%% up: %8.2fKB/s down: %8.2fKB/s error: %s' % \
- (ds.get_num_peers(), \
+ print >>sys.stderr, 'dlname: %s peers: %s status: %s progres: %5.2f%% up: %8.2fKB/s down: %8.2fKB/s error: %s\n' % \
+ (ds.get_download().get_def().get_name(), \
+ ds.get_num_peers(), \
dlstatus_strings[ds.get_status()], \
ds.get_progress() * 100, \
ds.get_current_speed(UPLOAD), \
ds.get_current_speed(DOWNLOAD), \
ds.get_error())
+ sys.stdout.flush()
# no peer listing if peer logging is disabled
if not peer_logging:
usage()
sys.exit(2)
- if len(args) > 1:
- print "Too many arguments"
- usage()
- sys.exit(2)
- torrentfile_or_url = args[0]
+ torrentfile_or_urls = args[0:]
print "Press Ctrl-C to stop the download"
s = Session(sscfg)
- # setup and start download
- dscfg = DownloadStartupConfig()
- dscfg.set_check_hashes(enable_hash_check)
- dscfg.set_dest_dir(output_dir);
- if download_limit > 0:
- dscfg.set_max_speed(DOWNLOAD, download_limit)
- if upload_limit > 0:
- dscfg.set_max_speed(UPLOAD, upload_limit)
- if max_conns > 0:
- dscfg.set_max_conns(max_conns)
-
- if torrentfile_or_url.startswith("http") or torrentfile_or_url.startswith(P2PURL_SCHEME):
- tdef = TorrentDef.load_from_url(torrentfile_or_url)
- else:
- tdef = TorrentDef.load(torrentfile_or_url)
- if tdef.get_live():
- raise ValueError("cmdlinedl does not support live torrents")
-
- d = s.start_download(tdef, dscfg)
- d.set_state_callback(state_callback, getpeerlist=peer_logging)
+ for torrentfile_or_url in set(torrentfile_or_urls):
+ # setup and start download
+ dscfg = DownloadStartupConfig()
+ dscfg.set_check_hashes(enable_hash_check)
+ dscfg.set_dest_dir(output_dir);
+ if download_limit > 0:
+ dscfg.set_max_speed(DOWNLOAD, download_limit)
+ if upload_limit > 0:
+ dscfg.set_max_speed(UPLOAD, upload_limit)
+ if max_conns > 0:
+ dscfg.set_max_conns(max_conns)
+
+ if torrentfile_or_url.startswith("http") or torrentfile_or_url.startswith(P2PURL_SCHEME):
+ tdef = TorrentDef.load_from_url(torrentfile_or_url)
+ else:
+ tdef = TorrentDef.load(torrentfile_or_url)
+ if tdef.get_live():
+ raise ValueError("cmdlinedl does not support live torrents")
+
+ d = s.start_download(tdef, dscfg)
+ d.set_state_callback(state_callback, getpeerlist=peer_logging)
#
# loop while waiting for CTRL-C (or any other signal/interrupt)