Search in sources :

Example 1 with BittorrentDownload

use of com.frostwire.transfers.BittorrentDownload in project frostwire by frostwire.

the class TransferManager method newBittorrentDownload.

private BittorrentDownload newBittorrentDownload(TorrentSearchResult sr) {
    try {
        BittorrentDownload bittorrentDownload = createBittorrentDownload(this, sr);
        if (bittorrentDownload != null) {
            bittorrentDownloadsList.add(bittorrentDownload);
            bittorrentDownloadsMap.put(bittorrentDownload.getInfoHash(), bittorrentDownload);
        }
        return bittorrentDownload;
    } catch (Throwable e) {
        LOG.warn("Error creating download from search result: " + sr);
        return new InvalidBittorrentDownload(R.string.empty_string);
    }
}
Also used : BittorrentDownload(com.frostwire.transfers.BittorrentDownload)

Example 2 with BittorrentDownload

use of com.frostwire.transfers.BittorrentDownload in project frostwire by frostwire.

the class TransferManager method loadTorrentsTask.

private void loadTorrentsTask() {
    bittorrentDownloadsList.clear();
    bittorrentDownloadsMap.clear();
    final BTEngine btEngine = BTEngine.getInstance();
    btEngine.setListener(new BTEngineAdapter() {

        @Override
        public void downloadAdded(BTEngine engine, BTDownload dl) {
            String name = dl.getName();
            if (name != null && name.contains("fetch_magnet")) {
                return;
            }
            File savePath = dl.getSavePath();
            if (savePath != null && savePath.toString().contains("fetch_magnet")) {
                return;
            }
            UIBittorrentDownload uiBittorrentDownload = new UIBittorrentDownload(TransferManager.this, dl);
            bittorrentDownloadsList.add(uiBittorrentDownload);
            bittorrentDownloadsMap.put(dl.getInfoHash(), uiBittorrentDownload);
        }

        @Override
        public void downloadUpdate(BTEngine engine, BTDownload dl) {
            try {
                BittorrentDownload bittorrentDownload = bittorrentDownloadsMap.get(dl.getInfoHash());
                if (bittorrentDownload instanceof UIBittorrentDownload) {
                    UIBittorrentDownload bt = (UIBittorrentDownload) bittorrentDownload;
                    bt.updateUI(dl);
                }
            } catch (Throwable e) {
                LOG.error("Error updating bittorrent download", e);
            }
        }
    });
    btEngine.restoreDownloads();
}
Also used : BTEngine(com.frostwire.bittorrent.BTEngine) BTDownload(com.frostwire.bittorrent.BTDownload) BittorrentDownload(com.frostwire.transfers.BittorrentDownload) File(java.io.File) BTEngineAdapter(com.frostwire.bittorrent.BTEngineAdapter)

Example 3 with BittorrentDownload

use of com.frostwire.transfers.BittorrentDownload in project frostwire by frostwire.

the class StartDownloadTask method onPostExecute.

@Override
protected void onPostExecute(Context ctx, Transfer transfer) {
    if (transfer != null) {
        if (ctx instanceof Activity) {
            Offers.showInterstitialOfferIfNecessary((Activity) ctx, Offers.PLACEMENT_INTERSTITIAL_EXIT, false, false);
        }
        if (!(transfer instanceof InvalidTransfer)) {
            TransferManager tm = TransferManager.instance();
            if (tm.isBittorrentDownloadAndMobileDataSavingsOn(transfer)) {
                UIUtils.showLongMessage(ctx, R.string.torrent_transfer_enqueued_on_mobile_data);
                ((BittorrentDownload) transfer).pause();
            } else {
                if (tm.isBittorrentDownloadAndMobileDataSavingsOff(transfer)) {
                    UIUtils.showLongMessage(ctx, R.string.torrent_transfer_consuming_mobile_data);
                }
                if (message != null) {
                    UIUtils.showShortMessage(ctx, message);
                }
            }
            UIUtils.showTransfersOnDownloadStart(ctx);
        } else if (!(transfer instanceof ExistingDownload)) {
            UIUtils.showLongMessage(ctx, ((InvalidTransfer) transfer).getReasonResId());
        }
    }
}
Also used : TransferManager(com.frostwire.android.gui.transfers.TransferManager) ExistingDownload(com.frostwire.android.gui.transfers.ExistingDownload) BittorrentDownload(com.frostwire.transfers.BittorrentDownload) Activity(android.app.Activity) InvalidTransfer(com.frostwire.android.gui.transfers.InvalidTransfer)

Example 4 with BittorrentDownload

use of com.frostwire.transfers.BittorrentDownload in project frostwire by frostwire.

the class AbstractTransferDetailFragment method recoverUIBittorrentDownload.

private void recoverUIBittorrentDownload(String infoHash) {
    if (infoHash != null) {
        BittorrentDownload bittorrentDownload = TransferManager.instance().getBittorrentDownload(infoHash);
        if (bittorrentDownload instanceof UIBittorrentDownload) {
            uiBittorrentDownload = (UIBittorrentDownload) bittorrentDownload;
            ensureTorrentHandleAsync();
        }
    }
}
Also used : UIBittorrentDownload(com.frostwire.android.gui.transfers.UIBittorrentDownload) BittorrentDownload(com.frostwire.transfers.BittorrentDownload) UIBittorrentDownload(com.frostwire.android.gui.transfers.UIBittorrentDownload)

Example 5 with BittorrentDownload

use of com.frostwire.transfers.BittorrentDownload in project frostwire by frostwire.

the class TransferManager method downloadTorrent.

public BittorrentDownload downloadTorrent(String uri, TorrentFetcherListener fetcherListener, String tempDownloadTitle) {
    String url = uri.trim();
    try {
        if (url.contains("urn%3Abtih%3A")) {
            // fixes issue #129: over-encoded url coming from intent
            url = url.replace("urn%3Abtih%3A", "urn:btih:");
        }
        if (isAlreadyDownloadingTorrentByUri(url)) {
            return null;
        }
        Uri u = Uri.parse(url);
        String scheme = u.getScheme();
        if (!scheme.equalsIgnoreCase("file") && !scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https") && !scheme.equalsIgnoreCase("magnet")) {
            LOG.warn("Invalid URI scheme: " + u.toString());
            return new InvalidBittorrentDownload(R.string.torrent_scheme_download_not_supported);
        }
        BittorrentDownload download = null;
        if (fetcherListener == null) {
            if (scheme.equalsIgnoreCase("file")) {
                BTEngine.getInstance().download(new File(u.getPath()), null, null);
            } else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("magnet")) {
                download = new TorrentFetcherDownload(this, new TorrentUrlInfo(u.toString(), tempDownloadTitle));
                bittorrentDownloadsList.add(download);
                bittorrentDownloadsMap.put(download.getInfoHash(), download);
            }
        } else {
            if (scheme.equalsIgnoreCase("file")) {
                fetcherListener.onTorrentInfoFetched(FileUtils.readFileToByteArray(new File(u.getPath())), null, -1);
            } else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("magnet")) {
                // this executes the listener method when it fetches the bytes.
                download = new TorrentFetcherDownload(this, new TorrentUrlInfo(u.toString(), tempDownloadTitle), fetcherListener);
                bittorrentDownloadsList.add(download);
                bittorrentDownloadsMap.put(download.getInfoHash(), download);
                return download;
            }
            return null;
        }
        return download;
    } catch (Throwable e) {
        LOG.warn("Error creating download from uri: " + url, e);
        return new InvalidBittorrentDownload(R.string.torrent_scheme_download_not_supported);
    }
}
Also used : BittorrentDownload(com.frostwire.transfers.BittorrentDownload) Uri(android.net.Uri) File(java.io.File)

Aggregations

BittorrentDownload (com.frostwire.transfers.BittorrentDownload)6 UIBittorrentDownload (com.frostwire.android.gui.transfers.UIBittorrentDownload)2 File (java.io.File)2 Activity (android.app.Activity)1 Uri (android.net.Uri)1 CancelMenuAction (com.frostwire.android.gui.adapters.menu.CancelMenuAction)1 CopyToClipboardMenuAction (com.frostwire.android.gui.adapters.menu.CopyToClipboardMenuAction)1 OpenMenuAction (com.frostwire.android.gui.adapters.menu.OpenMenuAction)1 PauseDownloadMenuAction (com.frostwire.android.gui.adapters.menu.PauseDownloadMenuAction)1 ResumeDownloadMenuAction (com.frostwire.android.gui.adapters.menu.ResumeDownloadMenuAction)1 TransferDetailsMenuAction (com.frostwire.android.gui.adapters.menu.TransferDetailsMenuAction)1 ExistingDownload (com.frostwire.android.gui.transfers.ExistingDownload)1 InvalidTransfer (com.frostwire.android.gui.transfers.InvalidTransfer)1 TransferManager (com.frostwire.android.gui.transfers.TransferManager)1 MenuAction (com.frostwire.android.gui.views.MenuAction)1 MenuAdapter (com.frostwire.android.gui.views.MenuAdapter)1 BTDownload (com.frostwire.bittorrent.BTDownload)1 BTEngine (com.frostwire.bittorrent.BTEngine)1 BTEngineAdapter (com.frostwire.bittorrent.BTEngineAdapter)1 Transfer (com.frostwire.transfers.Transfer)1