use of com.biglybt.core.torrentdownloader.TorrentDownloader in project BiglyBT by BiglySoftware.
the class ConsoleInput method downloadRemoteTorrent.
/**
* downloads the remote torrent file. once we have downloaded the .torrent file, we
* pass the data to the downloadTorrent() method for further processing
* @param url
* @param outputDir
*/
public void downloadRemoteTorrent(String url, final String outputDir) {
TorrentDownloader downloader = TorrentDownloaderFactory.create(new TorrentDownloaderCallBackInterface() {
@Override
public void TorrentDownloaderEvent(int state, TorrentDownloader inf) {
if (state == TorrentDownloader.STATE_FINISHED) {
out.println("Torrent file download complete. Starting torrent");
TorrentDownloaderManager.getInstance().remove(inf);
downloadTorrent(inf.getFile().getAbsolutePath(), outputDir);
} else {
if (state == TorrentDownloader.STATE_ERROR) {
out.println("Torrent file download failed: " + inf.getError());
}
TorrentDownloaderManager.getInstance().TorrentDownloaderEvent(state, inf);
}
}
}, url, null, null, true);
TorrentDownloaderManager.getInstance().add(downloader);
}
use of com.biglybt.core.torrentdownloader.TorrentDownloader in project BiglyBT by BiglySoftware.
the class TorrentUIUtilsV3 method _loadTorrent.
private static void _loadTorrent(final Core core, final DownloadUrlInfo dlInfo, // open player
final boolean playNow, // as for open player but don't actually open it
final boolean playPrepare, final boolean bringToFront) {
if (dlInfo instanceof DownloadUrlInfoSWT) {
DownloadUrlInfoSWT dlInfoSWT = (DownloadUrlInfoSWT) dlInfo;
dlInfoSWT.invoke(playNow ? "play" : "download");
return;
}
String url = dlInfo.getDownloadURL();
try {
Matcher m = hashPattern.matcher(url);
if (m.find()) {
String hash = m.group(1);
GlobalManager gm = core.getGlobalManager();
final DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
if (dm != null) {
if (playNow || playPrepare) {
new AEThread2("playExisting", true) {
@Override
public void run() {
if (playNow) {
Debug.outNoStack("loadTorrent already exists.. playing", false);
TorrentListViewsUtils.playOrStream(dm, -1);
} else {
Debug.outNoStack("loadTorrent already exists.. preparing", false);
PlayUtils.prepareForPlay(dm);
}
}
}.start();
} else {
new MessageBoxShell(SWT.OK, MSG_ALREADY_EXISTS, new String[] { " ", dm.getDisplayName(), MessageText.getString(MSG_ALREADY_EXISTS_NAME) }).open(null);
}
return;
}
}
UIFunctionsSWT uiFunctions = (UIFunctionsSWT) UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
// if (!COConfigurationManager.getBooleanParameter("add_torrents_silently")) { not used 11/30/2015
if (bringToFront) {
uiFunctions.bringToFront();
}
// }
Shell shell = uiFunctions.getMainShell();
if (shell != null) {
new FileDownloadWindow(shell, url, dlInfo.getReferer(), dlInfo.getRequestProperties(), null, new TorrentDownloaderCallBackInterface() {
@Override
public void TorrentDownloaderEvent(int state, TorrentDownloader inf) {
if (state == TorrentDownloader.STATE_FINISHED) {
File file = inf.getFile();
file.deleteOnExit();
// Do a quick check to see if it's a torrent
if (!TorrentUtil.isFileTorrent(dlInfo.getDownloadURL(), file, file.getName(), true)) {
return;
}
TOTorrent torrent;
try {
torrent = TorrentUtils.readFromFile(file, false);
} catch (TOTorrentException e) {
Debug.out(e);
return;
}
// Security: Only allow torrents from whitelisted trackers
if (playNow && !PlatformTorrentUtils.isPlatformTracker(torrent)) {
Debug.out("stopped loading torrent because it's not in whitelist");
return;
}
HashWrapper hw;
try {
hw = torrent.getHashWrapper();
} catch (TOTorrentException e1) {
Debug.out(e1);
return;
}
GlobalManager gm = core.getGlobalManager();
if (playNow || playPrepare) {
DownloadManager existingDM = gm.getDownloadManager(hw);
if (existingDM != null) {
if (playNow) {
TorrentListViewsUtils.playOrStream(existingDM, -1);
} else {
PlayUtils.prepareForPlay(existingDM);
}
return;
}
}
final HashWrapper fhw = hw;
GlobalManagerListener l = new GlobalManagerAdapter() {
@Override
public void downloadManagerAdded(DownloadManager dm) {
try {
core.getGlobalManager().removeListener(this);
handleDMAdded(dm, playNow, playPrepare, fhw);
} catch (Exception e) {
Debug.out(e);
}
}
};
gm.addListener(l, false);
TorrentOpener.openTorrent(file.getAbsolutePath());
}
}
});
}
}
} catch (Exception e) {
Debug.out(e);
}
}
Aggregations