Search in sources :

Example 1 with Priority

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

the class BTEngine method download.

public void download(TorrentCrawledSearchResult sr, File saveDir, boolean dontSaveTorrentFile) {
    if (swig() == null) {
        return;
    }
    saveDir = setupSaveDir(saveDir);
    if (saveDir == null) {
        return;
    }
    TorrentInfo ti = sr.getTorrentInfo();
    int fileIndex = sr.getFileIndex();
    TorrentHandle th = find(ti.infoHash());
    boolean exists = th != null;
    if (th != null) {
        Priority[] priorities = th.filePriorities();
        if (priorities[fileIndex] == Priority.IGNORE) {
            priorities[fileIndex] = Priority.NORMAL;
            download(ti, saveDir, priorities, null, null);
        }
    } else {
        Priority[] priorities = Priority.array(Priority.IGNORE, ti.numFiles());
        priorities[fileIndex] = Priority.NORMAL;
        download(ti, saveDir, priorities, null, null);
    }
    if (!exists) {
        saveResumeTorrent(ti);
        if (!dontSaveTorrentFile) {
            saveTorrent(ti);
        }
    }
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle) Priority(com.frostwire.jlibtorrent.Priority) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Example 2 with Priority

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

the class BTEngine method download.

private void download(TorrentInfo ti, File saveDir, Priority[] priorities, File resumeFile, List<TcpEndpoint> peers) {
    TorrentHandle th = find(ti.infoHash());
    if (th != null) {
        // found a download with the same hash, just adjust the priorities if needed
        if (priorities != null) {
            if (ti.numFiles() != priorities.length) {
                throw new IllegalArgumentException("The priorities length should be equals to the number of files");
            }
            th.prioritizeFiles(priorities);
            fireDownloadUpdate(th);
            th.resume();
        } else {
            // did they just add the entire torrent (therefore not selecting any priorities)
            final Priority[] wholeTorrentPriorities = Priority.array(Priority.NORMAL, ti.numFiles());
            th.prioritizeFiles(wholeTorrentPriorities);
            fireDownloadUpdate(th);
            th.resume();
        }
    } else {
        // new download
        download(ti, saveDir, resumeFile, priorities, peers);
    }
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle) Priority(com.frostwire.jlibtorrent.Priority)

Example 3 with Priority

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

the class BTEngine method download.

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

Example 4 with Priority

use of com.frostwire.jlibtorrent.Priority 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 5 with Priority

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

the class BTEngine method migrateVuzeDownloads.

private void migrateVuzeDownloads() {
    try {
        File dir = new File(ctx.homeDir.getParent(), "azureus");
        File file = new File(dir, "downloads.config");
        if (file.exists()) {
            Entry configEntry = Entry.bdecode(file);
            List<Entry> downloads = configEntry.dictionary().get("downloads").list();
            for (Entry d : downloads) {
                try {
                    Map<String, Entry> map = d.dictionary();
                    File saveDir = new File(map.get("save_dir").string());
                    File torrent = new File(map.get("torrent").string());
                    List<Entry> filePriorities = map.get("file_priorities").list();
                    Priority[] priorities = Priority.array(Priority.IGNORE, filePriorities.size());
                    for (int i = 0; i < filePriorities.size(); i++) {
                        long p = filePriorities.get(i).integer();
                        if (p != 0) {
                            priorities[i] = Priority.NORMAL;
                        }
                    }
                    if (torrent.exists() && saveDir.exists()) {
                        LOG.info("Restored old vuze download: " + torrent);
                        restoreDownloadsQueue.add(new RestoreDownloadTask(torrent, saveDir, priorities, null));
                        saveResumeTorrent(new TorrentInfo(torrent));
                    }
                } catch (Throwable e) {
                    LOG.error("Error restoring vuze torrent download", e);
                }
            }
            file.delete();
        }
    } catch (Throwable e) {
        LOG.error("Error migrating old vuze downloads", e);
    }
}
Also used : Entry(com.frostwire.jlibtorrent.Entry) Priority(com.frostwire.jlibtorrent.Priority) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) File(java.io.File) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Aggregations

Priority (com.frostwire.jlibtorrent.Priority)5 TcpEndpoint (com.frostwire.jlibtorrent.TcpEndpoint)4 TorrentHandle (com.frostwire.jlibtorrent.TorrentHandle)4 TorrentInfo (com.frostwire.jlibtorrent.TorrentInfo)3 Entry (com.frostwire.jlibtorrent.Entry)1 File (java.io.File)1