Search in sources :

Example 11 with TorrentInfo

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

Example 12 with TorrentInfo

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

the class TransferDetailDetailsFragment method updateComponents.

@Override
protected void updateComponents() {
    if (uiBittorrentDownload != null) {
        // ensureComponentsReferenced();
        BTDownload btDL = uiBittorrentDownload.getDl();
        if (onCopyToClipboardListener == null) {
            onCopyToClipboardListener = new CopyToClipboardOnClickListener(uiBittorrentDownload);
        }
        // static data for this download is done only once
        if ("".equals(storagePath.getText())) {
            storagePath.setText(uiBittorrentDownload.getSavePath().getAbsolutePath());
        }
        if ("".equals(totalSize.getText())) {
            totalSize.setText(UIUtils.getBytesInHuman(uiBittorrentDownload.getSize()));
        }
        if ("".equals(numberOfFiles.getText())) {
            List<TransferItem> items = uiBittorrentDownload.getItems();
            int fileCount = items == null ? 0 : items.size();
            numberOfFiles.setText(fileCount + "");
        }
        if ("".equals(hash.getText())) {
            hash.setText(uiBittorrentDownload.getInfoHash());
            hash.setOnClickListener(onCopyToClipboardListener);
            hashCopyButton.setOnClickListener(onCopyToClipboardListener);
        }
        if ("".equals(magnet.getText())) {
            magnet.setText(uiBittorrentDownload.magnetUri());
            magnet.setOnClickListener(onCopyToClipboardListener);
            magnetCopyButton.setOnClickListener(onCopyToClipboardListener);
        }
        if ("".equals(createdOn.getText())) {
            createdOn.setText(DateUtils.formatDateTime(getActivity(), uiBittorrentDownload.getCreated().getTime(), DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR));
        }
        if ("".equals(comment.getText())) {
            TorrentInfo torrentInfo = uiBittorrentDownload.getDl().getTorrentHandle().torrentFile();
            String torrentComment = torrentInfo.comment();
            if (torrentComment != null && !"".equals(torrentComment)) {
                comment.setText(torrentComment);
            } else {
                comment.setText(" ");
                View view = findView(comment.getRootView(), R.id.fragment_transfer_detail_details_comment_container);
                view.setVisibility(View.GONE);
            }
        }
        if (onSequentialDownloadCheckboxCheckedListener == null) {
            onSequentialDownloadCheckboxCheckedListener = new SequentialDownloadCheckboxCheckedListener(uiBittorrentDownload);
        }
        sequentialDownloadCheckBox.setOnCheckedChangeListener(null);
        sequentialDownloadCheckBox.setChecked(btDL.isSequentialDownload());
        sequentialDownloadCheckBox.setOnCheckedChangeListener(onSequentialDownloadCheckboxCheckedListener);
        if (onRateLimitClickListener == null) {
            onRateLimitClickListener = new OnSpeedLimitClickListener(uiBittorrentDownload, this, getFragmentManager());
            downloadSpeedLimit.setOnClickListener(onRateLimitClickListener);
            downloadSpeedLimitArrow.setOnClickListener(onRateLimitClickListener);
            uploadSpeedLimit.setOnClickListener(onRateLimitClickListener);
            uploadSpeedLimitArrow.setOnClickListener(onRateLimitClickListener);
        }
        int downloadRateLimit = btDL.getDownloadRateLimit();
        int uploadRateLimit = btDL.getUploadRateLimit();
        if (downloadRateLimit > 0) {
            downloadSpeedLimit.setText(UIUtils.getBytesInHuman(downloadRateLimit) + "/s");
        } else if (downloadRateLimit == DOWNLOAD_UNLIMITED_VALUE || downloadRateLimit == -1) {
            downloadSpeedLimit.setText(R.string.unlimited);
        }
        if (uploadRateLimit > 0) {
            uploadSpeedLimit.setText(UIUtils.getBytesInHuman(uploadRateLimit) + "/s");
        } else if (uploadRateLimit == UPLOAD_UNLIMITED_VALUE || uploadRateLimit == -1) {
            uploadSpeedLimit.setText(R.string.unlimited);
        }
    }
}
Also used : BTDownload(com.frostwire.bittorrent.BTDownload) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) TransferItem(com.frostwire.transfers.TransferItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 13 with TorrentInfo

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

the class TransferDetailPiecesFragment method updateComponents.

@Override
protected void updateComponents() {
    if (uiBittorrentDownload == null) {
        return;
    }
    ensureTorrentHandleAsync();
    if (torrentHandle == null) {
        return;
    }
    TorrentStatus status = torrentHandle.status(TorrentHandle.QUERY_PIECES);
    TorrentInfo torrentInfo = torrentHandle.torrentFile();
    if (pieceSizeString == null) {
        pieceSizeString = UIUtils.getBytesInHuman(torrentInfo.pieceSize(0));
    }
    if (totalPieces == -1) {
        totalPieces = torrentInfo.numPieces();
        piecesNumberTextView.setText(String.valueOf(totalPieces));
        // progressBar.setVisibility(View.VISIBLE);
        hexHiveView.setVisibility(View.GONE);
    }
    PieceIndexBitfield pieces = status.pieces();
    long piecesCount = pieces.count();
    if (isAdded()) {
        // I do this color look-up only once and pass it down to the view holder
        // otherwise it has to be done thousands of times.
        pieceSizeTextView.setText(pieceSizeString);
        hexDataAdapter = new PieceAdapter(totalPieces, pieces);
        hexHiveView.setVisibility(View.VISIBLE);
    }
    if (hexDataAdapter != null) {
        if (piecesCount >= 0) {
            hexDataAdapter.updateData(pieces);
        }
        // noinspection unchecked
        hexHiveView.updateData(hexDataAdapter);
        piecesNumberTextView.setText(piecesCount + "/" + totalPieces);
    }
}
Also used : TorrentStatus(com.frostwire.jlibtorrent.TorrentStatus) PieceIndexBitfield(com.frostwire.jlibtorrent.PieceIndexBitfield) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo)

Example 14 with TorrentInfo

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

the class TorrentFetcherDownload method downloadTorrent.

private void downloadTorrent(final byte[] data) {
    try {
        TorrentInfo ti = TorrentInfo.bdecode(data);
        boolean[] selection = null;
        if (info.getRelativePath() != null) {
            selection = calculateSelection(ti, info.getRelativePath());
        }
        BTEngine.getInstance().download(ti, null, selection, null, TransferManager.instance().isDeleteStartedTorrentEnabled());
    } catch (Throwable e) {
        LOG.error("Error downloading torrent", e);
    }
}
Also used : TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo)

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