Search in sources :

Example 1 with TorrentInfo

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

the class SeedAction method buildTorrentAndSeedIt.

private void buildTorrentAndSeedIt(final FileDescriptor fd) {
    try {
        // TODO: Do this so it works with SD Card support / New BS File storage api from Android.
        File file = new File(fd.filePath);
        File saveDir = file.getParentFile();
        file_storage fs = new file_storage();
        fs.add_file(file.getName(), file.length());
        fs.set_name(file.getName());
        // , 0, -1, create_torrent.flags_t.merkle.swigValue());
        create_torrent ct = new create_torrent(fs);
        // commented out the merkle flag above because torrent doesn't appear as "Seeding", piece count doesn't work
        // as the algorithm in BTDownload.getProgress() doesn't make sense at the moment for merkle torrents.
        ct.set_creator("FrostWire " + Constants.FROSTWIRE_VERSION_STRING + " build " + Constants.FROSTWIRE_BUILD);
        ct.set_priv(false);
        final error_code ec = new error_code();
        libtorrent.set_piece_hashes_ex(ct, saveDir.getAbsolutePath(), new set_piece_hashes_listener(), ec);
        final byte[] torrent_bytes = new Entry(ct.generate()).bencode();
        final TorrentInfo tinfo = TorrentInfo.bdecode(torrent_bytes);
        // so the TorrentHandle object is created and added to the libtorrent session.
        BTEngine.getInstance().download(tinfo, saveDir, new boolean[] { true }, null, TransferManager.instance().isDeleteStartedTorrentEnabled());
    } catch (Throwable e) {
        // TODO: better handling of this error
        LOG.error("Error creating torrent for seed", e);
    }
}
Also used : Entry(com.frostwire.jlibtorrent.Entry) com.frostwire.jlibtorrent.swig.set_piece_hashes_listener(com.frostwire.jlibtorrent.swig.set_piece_hashes_listener) com.frostwire.jlibtorrent.swig.create_torrent(com.frostwire.jlibtorrent.swig.create_torrent) com.frostwire.jlibtorrent.swig.file_storage(com.frostwire.jlibtorrent.swig.file_storage) com.frostwire.jlibtorrent.swig.error_code(com.frostwire.jlibtorrent.swig.error_code) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) File(java.io.File)

Example 2 with TorrentInfo

use of com.frostwire.jlibtorrent.TorrentInfo 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 3 with TorrentInfo

use of com.frostwire.jlibtorrent.TorrentInfo 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 TorrentInfo

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

the class BTDownload method getIncompleteFiles.

public Set<File> getIncompleteFiles() {
    Set<File> s = new HashSet<>();
    try {
        if (!th.isValid()) {
            return s;
        }
        long[] progress = th.fileProgress(TorrentHandle.FileProgressFlags.PIECE_GRANULARITY);
        TorrentInfo ti = th.torrentFile();
        if (ti == null) {
            // still downloading the info (from magnet)
            return s;
        }
        FileStorage fs = ti.files();
        String prefix = savePath.getAbsolutePath();
        long createdTime = created.getTime();
        for (int i = 0; i < progress.length; i++) {
            String fePath = fs.filePath(i);
            long feSize = fs.fileSize(i);
            if (progress[i] < feSize) {
                // lets see if indeed the file is incomplete
                File f = new File(prefix, fePath);
                if (!f.exists()) {
                    // nothing to do here
                    continue;
                }
                if (f.lastModified() >= createdTime) {
                    // we have a file modified (supposedly) by this transfer
                    s.add(f);
                }
            }
        }
    } catch (Throwable e) {
        LOG.error("Error calculating the incomplete files set", e);
    }
    return s;
}
Also used : FileStorage(com.frostwire.jlibtorrent.FileStorage) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with TorrentInfo

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

the class PerformersHelper method crawlTorrent.

/**
 * This method is only public allow reuse inside the package search, consider it a private API
 */
public static List<? extends SearchResult> crawlTorrent(SearchPerformer performer, TorrentCrawlableSearchResult sr, byte[] data, boolean detectAlbums) {
    List<TorrentCrawledSearchResult> list = new LinkedList<>();
    if (data == null) {
        return list;
    }
    TorrentInfo ti;
    try {
        ti = TorrentInfo.bdecode(data);
    } catch (Throwable t) {
        // LOG.error("Can't bdecode:\n" + new String(data) + "\n\n");
        throw t;
    }
    int numFiles = ti.numFiles();
    FileStorage fs = ti.files();
    for (int i = 0; !performer.isStopped() && i < numFiles; i++) {
        // TODO: Check for the hidden attribute
        if (fs.padFileAt(i)) {
            continue;
        }
        list.add(new TorrentCrawledSearchResult(sr, ti, i, fs.filePath(i), fs.fileSize(i)));
    }
    if (detectAlbums) {
        List<SearchResult> temp = new LinkedList<>();
        temp.addAll(list);
        temp.addAll(new AlbumCluster().detect(sr, list));
        return temp;
    } else {
        return list;
    }
}
Also used : TorrentCrawledSearchResult(com.frostwire.search.torrent.TorrentCrawledSearchResult) FileStorage(com.frostwire.jlibtorrent.FileStorage) TorrentCrawlableSearchResult(com.frostwire.search.torrent.TorrentCrawlableSearchResult) TorrentCrawledSearchResult(com.frostwire.search.torrent.TorrentCrawledSearchResult) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) LinkedList(java.util.LinkedList)

Aggregations

TorrentInfo (com.frostwire.jlibtorrent.TorrentInfo)14 FileStorage (com.frostwire.jlibtorrent.FileStorage)4 File (java.io.File)4 Priority (com.frostwire.jlibtorrent.Priority)3 TcpEndpoint (com.frostwire.jlibtorrent.TcpEndpoint)3 Entry (com.frostwire.jlibtorrent.Entry)2 TorrentHandle (com.frostwire.jlibtorrent.TorrentHandle)2 TorrentStatus (com.frostwire.jlibtorrent.TorrentStatus)2 TransferItem (com.frostwire.transfers.TransferItem)2 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BTDownload (com.frostwire.bittorrent.BTDownload)1 PieceIndexBitfield (com.frostwire.jlibtorrent.PieceIndexBitfield)1 com.frostwire.jlibtorrent.swig.create_torrent (com.frostwire.jlibtorrent.swig.create_torrent)1 com.frostwire.jlibtorrent.swig.error_code (com.frostwire.jlibtorrent.swig.error_code)1 com.frostwire.jlibtorrent.swig.file_storage (com.frostwire.jlibtorrent.swig.file_storage)1 com.frostwire.jlibtorrent.swig.set_piece_hashes_listener (com.frostwire.jlibtorrent.swig.set_piece_hashes_listener)1 TorrentCrawlableSearchResult (com.frostwire.search.torrent.TorrentCrawlableSearchResult)1 TorrentCrawledSearchResult (com.frostwire.search.torrent.TorrentCrawledSearchResult)1