use of com.biglybt.core.tracker.client.TRTrackerScraperResponse in project BiglyBT by BiglySoftware.
the class IConsoleCommand method expandVariable.
/**
* expands the specified variable character into a string. <br>currently available
* variables that can be expanded are:<br>
* <hr>
* %a for state<br>
* %c percentage complete<br>
* %t torrent details - error message if error, otherwise torrent name<br>
* %z size<br>
* %e ETA<br>
* %r progress, if we have disabled some files<br>
* %d download speed<br>
* %u upload speed<br>
* %D amount downloaded<br>
* %U amount uploaded<br>
* %v upload slots
* %s connected seeds<br>
* %p connected peers<br>
* %S tracker seeds<br>
* %P tracker peers<br>
* @param variable variable character, eg: 'e' for ETA
* @param dm download manager object
* @return string expansion of the variable
*/
protected String expandVariable(char variable, DownloadManager dm) {
switch(variable) {
case 'a':
return getShortStateString(dm.getState());
case 'c':
DecimalFormat df = new DecimalFormat("000.0%");
return df.format(dm.getStats().getCompleted() / 1000.0);
case 't':
if (dm.getState() == DownloadManager.STATE_ERROR)
return dm.getErrorDetails();
else {
if (dm.getDisplayName() == null)
return "?";
else
return dm.getDisplayName();
}
case 'z':
return DisplayFormatters.formatByteCountToKiBEtc(dm.getSize());
case 'e':
return DisplayFormatters.formatETA(dm.getStats().getSmoothedETA());
case 'r':
long to = 0;
long tot = 0;
if (dm.getDiskManager() != null) {
DiskManagerFileInfo[] files = dm.getDiskManager().getFiles();
if (files != null) {
if (files.length > 1) {
int c = 0;
for (int i = 0; i < files.length; i++) {
if (files[i] != null) {
if (!files[i].isSkipped()) {
c += 1;
tot += files[i].getLength();
to += files[i].getDownloaded();
}
}
}
if (c == files.length)
tot = 0;
}
}
}
DecimalFormat df1 = new DecimalFormat("000.0%");
if (tot > 0) {
return " (" + df1.format(to * 1.0 / tot) + ")";
} else
return "\t";
case 'd':
return DisplayFormatters.formatByteCountToKiBEtcPerSec(dm.getStats().getDataReceiveRate());
case 'u':
return DisplayFormatters.formatByteCountToKiBEtcPerSec(dm.getStats().getDataSendRate());
case 'D':
return DisplayFormatters.formatDownloaded(dm.getStats());
case 'U':
return DisplayFormatters.formatByteCountToKiBEtc(dm.getStats().getTotalDataBytesSent());
case 's':
return Integer.toString(dm.getNbSeeds());
case 'p':
return Integer.toString(dm.getNbPeers());
case 'v':
return Integer.toString(dm.getMaxUploads());
case 'I':
int downloadSpeed = dm.getStats().getDownloadRateLimitBytesPerSecond();
if (downloadSpeed <= 0)
return "";
return "(max " + DisplayFormatters.formatByteCountToKiBEtcPerSec(downloadSpeed) + ")";
case 'O':
int uploadSpeed = dm.getStats().getUploadRateLimitBytesPerSecond();
if (uploadSpeed <= 0)
return "";
return "(max " + DisplayFormatters.formatByteCountToKiBEtcPerSec(uploadSpeed) + ")";
case 'S':
case 'P':
TRTrackerScraperResponse hd = dm.getTrackerScrapeResponse();
if (hd == null || !hd.isValid())
return "?";
else {
if (variable == 'S')
return Integer.toString(hd.getSeeds());
else
return Integer.toString(hd.getPeers());
}
default:
return "??" + variable + "??";
}
}
Aggregations