from BaseLib.Core.API import *
from BaseLib.Core.BitTornado.__init__ import version, report_email
+
+# use -l/--peer-logging option to enable peer logging
+peer_logging = False
+
+
# Print usage message
def usage():
print "Usage: python cmdlinedl.py [options] torrentfile_or_url"
print "\t\t\t\t(default is no upload limit)"
print "\t--no-hash-check"
print "\t-c\t\t\tdisable downloaded file hash checking"
+ print "\t--peer-logging"
+ print "\t-l\t\t\tenable peer logging (per-peer information)"
print "\t--version"
print "\t-v\t\t\tprint version and exit"
print "\t--help"
ds.get_current_speed(UPLOAD), \
ds.get_current_speed(DOWNLOAD))
- return (1.0, False)
+ peers = ds.get_num_peers()
+ (seeds, leechers) = ds.get_num_seeds_peers()
+ if seeds is None:
+ print >>sys.stderr, '%d peers' % ds.get_num_peers()
+ else:
+ print >>sys.stderr, '%d peers (%d seeds, %d leechers)' % (peers, seeds, leechers)
+
+ peerlist = ds.get_peerlist()
+ if peerlist is None:
+ pass
+ else:
+ print "list: ", peerlist
+
+ global peer_logging
+ return (1.0, peer_logging)
def main():
try:
# opts = a list of (option, value) pairs
# args = the list of program arguments left after the option list was stripped
- opts, args = getopt.getopt(sys.argv[1:], "hvcu:d:o:p:", ["help", "version", "no-hash-check", "upload-limit=", "download-limit=", "output-dir=", "port="])
+ opts, args = getopt.getopt(sys.argv[1:], "hvclu:d:o:p:", ["help", "version", "no-hash-check", "peer-logging", "upload-limit=", "download-limit=", "output-dir=", "port="])
except getopt.GetoptError, err:
print str(err)
usage()
output_dir = os.getcwd()
port = random.randint(10000, 65535)
enable_hash_check = True
-
+ global peer_logging
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit(0)
elif o in ("-c", "--no-hash-check"):
enable_hash_check = False
+ elif o in ("-l", "--peer-logging"):
+ peer_logging = True
else:
assert False, "unhandled option"
raise ValueError("cmdlinedl does not support live torrents")
d = s.start_download(tdef, dscfg)
- d.set_state_callback(state_callback, getpeerlist=False)
+ d.set_state_callback(state_callback, getpeerlist=peer_logging)
#
# loop while waiting for CTRL-C (or any other signal/interrupt)