Search in sources :

Example 1 with RPTorrent

use of com.biglybt.pifimpl.remote.torrent.RPTorrent in project BiglyBT by BiglySoftware.

the class RPTracker method _process.

@Override
public RPReply _process(RPRequest request) {
    String method = request.getMethod();
    Object[] params = request.getParams();
    if (method.equals("host[Torrent,boolean]")) {
        try {
            Torrent torrent = params[0] == null ? null : (Torrent) ((RPTorrent) params[0])._setLocal();
            if (torrent == null) {
                throw (new RPException("Invalid torrent"));
            }
            TrackerTorrent tt = delegate.host(torrent, ((Boolean) params[1]).booleanValue());
            RPTrackerTorrent res = RPTrackerTorrent.create(tt);
            return (new RPReply(res));
        } catch (TrackerException e) {
            return (new RPReply(e));
        }
    } else if (method.equals("getTorrents")) {
        TrackerTorrent[] torrents = delegate.getTorrents();
        RPTrackerTorrent[] res = new RPTrackerTorrent[torrents.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = RPTrackerTorrent.create(torrents[i]);
        }
        return (new RPReply(res));
    }
    throw (new RPException("Unknown method: " + method));
}
Also used : TrackerException(com.biglybt.pif.tracker.TrackerException) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) Torrent(com.biglybt.pif.torrent.Torrent) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) RPException(com.biglybt.pifimpl.remote.RPException) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) RPReply(com.biglybt.pifimpl.remote.RPReply) RPObject(com.biglybt.pifimpl.remote.RPObject)

Example 2 with RPTorrent

use of com.biglybt.pifimpl.remote.torrent.RPTorrent in project BiglyBT by BiglySoftware.

the class RPDownloadManager method _process.

@Override
public RPReply _process(RPRequest request) {
    String method = request.getMethod();
    Object[] params = request.getParams();
    if (method.equals("getDownloads")) {
        Download[] downloads = delegate.getDownloads();
        // unfortunately downloads with broken torrents can exist and have no associated
        // Torrent. Easiest fix here is to filter them out.
        RPDownload[] res = new RPDownload[downloads.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = RPDownload.create(downloads[i]);
        }
        return (new RPReply(res));
    } else if (method.equals("getDownloads[boolean]")) {
        Download[] downloads = delegate.getDownloads(((Boolean) request.getParams()[0]).booleanValue());
        RPDownload[] res = new RPDownload[downloads.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = RPDownload.create(downloads[i]);
        }
        return (new RPReply(res));
    } else if (method.equals("addDownload[Torrent]")) {
        try {
            RPTorrent torrent = (RPTorrent) request.getParams()[0];
            Download res = delegate.addDownload((Torrent) torrent._setLocal());
            return (new RPReply(RPDownload.create(res)));
        } catch (DownloadException e) {
            throw (new RPException("DownloadManager::addDownload failed", e));
        }
    } else if (method.equals("addDownload[Torrent,String,String]")) {
        try {
            RPTorrent torrent = (RPTorrent) request.getParams()[0];
            File f1 = params[1] == null ? null : new File((String) params[1]);
            File f2 = params[2] == null ? null : new File((String) params[2]);
            Download res = delegate.addDownload((Torrent) torrent._setLocal(), f1, f2);
            return (new RPReply(RPDownload.create(res)));
        } catch (DownloadException e) {
            throw (new RPException("DownloadManager::addDownload failed", e));
        }
    } else if (method.equals("addDownload[URL]")) {
        try {
            delegate.addDownload((URL) request.getParams()[0]);
        } catch (DownloadException e) {
            throw (new RPException("DownloadManager::addDownload failed", e));
        }
        return (new RPReply(null));
    } else if (method.equals("pauseDownloads")) {
        delegate.pauseDownloads();
        return (null);
    } else if (method.equals("resumeDownloads")) {
        delegate.resumeDownloads();
        return (null);
    } else if (method.equals("stopAllDownloads")) {
        delegate.stopAllDownloads();
        return (null);
    } else if (method.equals("startAllDownloads")) {
        delegate.startAllDownloads();
        return (null);
    }
    throw (new RPException("Unknown method: " + method));
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) RPException(com.biglybt.pifimpl.remote.RPException) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) RPReply(com.biglybt.pifimpl.remote.RPReply) RPObject(com.biglybt.pifimpl.remote.RPObject) File(java.io.File)

Aggregations

Torrent (com.biglybt.pif.torrent.Torrent)2 RPException (com.biglybt.pifimpl.remote.RPException)2 RPObject (com.biglybt.pifimpl.remote.RPObject)2 RPReply (com.biglybt.pifimpl.remote.RPReply)2 RPTorrent (com.biglybt.pifimpl.remote.torrent.RPTorrent)2 TrackerException (com.biglybt.pif.tracker.TrackerException)1 TrackerTorrent (com.biglybt.pif.tracker.TrackerTorrent)1 File (java.io.File)1