Search in sources :

Example 1 with TcpEndpoint

use of com.frostwire.jlibtorrent.TcpEndpoint in project frostwire by frostwire.

the class BTEngine method download.

public void download(TorrentInfo ti, File saveDir, boolean[] selection, List<TcpEndpoint> peers, boolean dontSaveTorrentFile) {
    if (swig() == null) {
        return;
    }
    saveDir = setupSaveDir(saveDir);
    if (saveDir == null) {
        return;
    }
    if (selection == null) {
        selection = new boolean[ti.numFiles()];
        Arrays.fill(selection, true);
    }
    Priority[] priorities = null;
    TorrentHandle th = find(ti.infoHash());
    boolean torrentHandleExists = th != null;
    if (torrentHandleExists) {
        try {
            priorities = th.filePriorities();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    } else {
        priorities = Priority.array(Priority.IGNORE, ti.numFiles());
    }
    if (priorities != null) {
        boolean changed = false;
        for (int i = 0; i < selection.length; i++) {
            if (selection[i] && i < priorities.length) {
                if (priorities[i] == Priority.IGNORE) {
                    priorities[i] = Priority.NORMAL;
                    changed = true;
                }
            }
        }
        if (!changed) {
            // nothing to do
            return;
        }
    }
    download(ti, saveDir, priorities, null, peers);
    if (!torrentHandleExists) {
        saveResumeTorrent(ti);
        if (!dontSaveTorrentFile) {
            saveTorrent(ti);
        }
    }
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle) Priority(com.frostwire.jlibtorrent.Priority) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Example 2 with TcpEndpoint

use of com.frostwire.jlibtorrent.TcpEndpoint in project frostwire by frostwire.

the class TorrentFetcherDownload method parsePeers.

private static List<TcpEndpoint> parsePeers(String magnet) {
    if (magnet == null || magnet.isEmpty() || magnet.startsWith("http")) {
        return Collections.emptyList();
    }
    // TODO: replace this with the public API
    error_code ec = new error_code();
    add_torrent_params params = add_torrent_params.parse_magnet_uri(magnet, ec);
    tcp_endpoint_vector v = params.get_peers();
    int size = (int) v.size();
    ArrayList<TcpEndpoint> l = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        l.add(new TcpEndpoint(v.get(i)));
    }
    return l;
}
Also used : TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint) com.frostwire.jlibtorrent.swig.tcp_endpoint_vector(com.frostwire.jlibtorrent.swig.tcp_endpoint_vector) ArrayList(java.util.ArrayList) com.frostwire.jlibtorrent.swig.error_code(com.frostwire.jlibtorrent.swig.error_code) com.frostwire.jlibtorrent.swig.add_torrent_params(com.frostwire.jlibtorrent.swig.add_torrent_params) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Aggregations

TcpEndpoint (com.frostwire.jlibtorrent.TcpEndpoint)2 Priority (com.frostwire.jlibtorrent.Priority)1 TorrentHandle (com.frostwire.jlibtorrent.TorrentHandle)1 com.frostwire.jlibtorrent.swig.add_torrent_params (com.frostwire.jlibtorrent.swig.add_torrent_params)1 com.frostwire.jlibtorrent.swig.error_code (com.frostwire.jlibtorrent.swig.error_code)1 com.frostwire.jlibtorrent.swig.tcp_endpoint_vector (com.frostwire.jlibtorrent.swig.tcp_endpoint_vector)1 ArrayList (java.util.ArrayList)1