Search in sources :

Example 11 with TRTrackerScraperResponse

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 + "??";
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) DecimalFormat(java.text.DecimalFormat)

Aggregations

TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)11 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 TRTrackerBTScraperResponseImpl (com.biglybt.core.tracker.client.impl.bt.TRTrackerBTScraperResponseImpl)2 URL (java.net.URL)2 DecimalFormat (java.text.DecimalFormat)2 DiskManager (com.biglybt.core.disk.DiskManager)1 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)1 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)1 TrackerPeerSource (com.biglybt.core.tracker.TrackerPeerSource)1 DownloadTypeComplete (com.biglybt.pif.download.DownloadTypeComplete)1 DownloadTypeIncomplete (com.biglybt.pif.download.DownloadTypeIncomplete)1 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)1 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)1 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1