Added support for loading multiple .torrent files using the cmd-line version
authorGeorge Milescu <george.milescu@gmail.com>
Fri, 25 Mar 2011 13:39:39 +0000 (14:39 +0100)
committerGeorge Milescu <george.milescu@gmail.com>
Fri, 25 Mar 2011 13:39:39 +0000 (14:39 +0100)
Signed-off-by: George Milescu <george.milescu@gmail.com>
instrumentation/next-share/BaseLib/Tools/cmdlinedl.py

index eddac2b..c7c5ebe 100644 (file)
@@ -28,7 +28,7 @@ from BaseLib.Core.BitTornado.__init__ import version, report_email
 
 # 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"
@@ -69,13 +69,15 @@ PEERLIST_OUTPUT_INTERVAL = 5
 # 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:
@@ -143,11 +145,7 @@ def main():
         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"
 
@@ -163,26 +161,27 @@ def main():
 
     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)