TorrentUIUtilsV3public class TorrentUIUtilsV3 extends Object
Fields Summary |
---|
private static final Pattern | hashPattern |
Methods Summary |
---|
public static void | loadTorrent(com.aelitis.azureus.core.AzureusCore core, java.lang.String url, java.lang.String referer, boolean playNow)
boolean blocked = PlatformConfigMessenger.isURLBlocked(url);
// Security: Only allow torrents from whitelisted urls
if (blocked) {
Debug.out("stopped loading torrent URL because it's not in whitelist");
return;
}
try {
if (playNow) {
Matcher m = hashPattern.matcher(url);
if (m.find()) {
String hash = m.group(1);
System.out.println("HASH? " + hash);
GlobalManager gm = core.getGlobalManager();
DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
if (dm != null) {
Debug.outNoStack("loadTorrent already exists.. playing", false);
TorrentListViewsUtils.playOrStream(dm);
return;
}
}
}
// If it's going to our URLs, add some extra authenication
if (url.indexOf("azid=") < 0) {
url += (url.indexOf('?") < 0 ? "?" : "&") + Constants.URL_SUFFIX;
}
UIFunctionsSWT uiFunctions = (UIFunctionsSWT) UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
if (!COConfigurationManager.getBooleanParameter("add_torrents_silently")) {
uiFunctions.bringToFront();
}
Shell shell = uiFunctions.getMainShell();
if (shell != null) {
new FileDownloadWindow(core, shell, url, referer,
new TorrentDownloaderCallBackInterface() {
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(file, Utils.findAnyShell(),
file.getName())) {
return;
}
TOTorrent torrent;
try {
torrent = TorrentUtils.readFromFile(file, false);
} catch (TOTorrentException e) {
Debug.out(e);
return;
}
// Security: Only allow torrents from whitelisted trackers
if (!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) {
DownloadManager existingDM = gm.getDownloadManager(hw);
if (existingDM != null) {
TorrentListViewsUtils.playOrStream(existingDM);
return;
}
}
final HashWrapper fhw = hw;
GlobalManagerListener l = new GlobalManagerAdapter() {
public void downloadManagerAdded(DownloadManager dm) {
try {
core.getGlobalManager().removeListener(this);
HashWrapper hw = dm.getTorrent().getHashWrapper();
if (!hw.equals(fhw)) {
return;
}
boolean showHomeHint = true;
if (playNow) {
showHomeHint = !TorrentListViewsUtils.playOrStream(dm);
}
if (showHomeHint) {
TorrentListViewsUtils.showHomeHint(dm);
}
} catch (Exception e) {
Debug.out(e);
}
}
};
gm.addListener(l, false);
if (playNow) {
PlayNowList.add(hw);
}
TorrentOpener.openTorrent(file.getAbsolutePath());
}
}
});
}
}
} catch (Exception e) {
Debug.out(e);
}
|
|