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);
}
}
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();
}
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());
}
}
}
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();
}
}
}
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);
}
}
Aggregations