if (!parseParameters(args))
usage();
String torrentFile = args[args.length - 2];
String path = args[args.length - 1];
DownloadManager manager = DownloadManagerFactory.create(null, null, torrentFile, path, DownloadManager.STATE_WAITING, false, false, null, null );
manager.initialize();
while (true) {
StringBuffer buf = new StringBuffer();
int state = manager.getState();
switch (state) {
case DownloadManager.STATE_WAITING :
buf.append("Waiting");
break;
case DownloadManager.STATE_ALLOCATING :
buf.append("Allocating");
break;
case DownloadManager.STATE_CHECKING :
buf.append("Checking");
break;
case DownloadManager.STATE_READY :
buf.append("Ready");
manager.startDownload();
break;
case DownloadManager.STATE_DOWNLOADING :
buf.append("Downloading");
break;
case DownloadManager.STATE_SEEDING :
buf.append("Seeding");
break;
case DownloadManager.STATE_STOPPED :
buf.append("Stopped");
break;
case DownloadManager.STATE_ERROR :
buf.append("Error : " + manager.getErrorDetails());
break;
}
buf.append(" C:");
DownloadManagerStats stats = manager.getStats();
int completed = stats.getCompleted();
buf.append(completed/10);
buf.append('.");
buf.append(completed%10);
buf.append('%");
buf.append(" S:");
buf.append(manager.getNbSeeds());
buf.append(" P:");
buf.append(manager.getNbPeers());
buf.append(" D:");
buf.append(DisplayFormatters.formatDownloaded(stats));
buf.append(" U:");
buf.append(DisplayFormatters.formatByteCountToKiBEtc(stats.getTotalDataBytesSent()));
buf.append(" DS:");
buf.append(DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate()));
buf.append(" US:");
buf.append(DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate()));
buf.append(" T:");
buf.append(manager.getTrackerStatus());
while(buf.length() < 80) {
buf.append(' ");
}
System.out.print("\r".concat(buf.toString()));
if(state == DownloadManager.STATE_ERROR)
return;
try {
Thread.sleep(500);
} catch (Exception e) {
//Do nothing
}
}