use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class DataSourceUtils method getTorrent.
public static TOTorrent getTorrent(Object ds) {
if (ds instanceof TOTorrent) {
return (TOTorrent) ds;
}
if (ds instanceof DownloadManager) {
TOTorrent torrent = ((DownloadManager) ds).getTorrent();
if (torrent != null) {
return torrent;
}
}
if (ds instanceof ActivitiesEntry) {
TOTorrent torrent = ((ActivitiesEntry) ds).getTorrent();
if (torrent == null) {
// getDM will check hash as well
DownloadManager dm = getDM(ds);
if (dm != null) {
torrent = dm.getTorrent();
}
}
return torrent;
}
if (ds instanceof TranscodeFile) {
TranscodeFile tf = (TranscodeFile) ds;
try {
DiskManagerFileInfo file = tf.getSourceFile();
if (file != null) {
Download download = file.getDownload();
if (download != null) {
Torrent torrent = download.getTorrent();
if (torrent != null) {
return PluginCoreUtils.unwrap(torrent);
}
}
}
} catch (Throwable e) {
}
}
if (ds instanceof TranscodeJob) {
TranscodeJob tj = (TranscodeJob) ds;
try {
DiskManagerFileInfo file = tj.getFile();
if (file != null) {
Download download = tj.getFile().getDownload();
if (download != null) {
Torrent torrent = download.getTorrent();
if (torrent != null) {
return PluginCoreUtils.unwrap(torrent);
}
}
}
} catch (DownloadException e) {
}
}
if (ds instanceof ISelectedContent) {
return ((ISelectedContent) ds).getTorrent();
}
if (ds instanceof String) {
String hash = (String) ds;
try {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
if (dm != null) {
return dm.getTorrent();
}
} catch (Exception e) {
// ignore
}
}
DownloadManager dm = getDM(ds);
if (dm != null) {
return dm.getTorrent();
}
return null;
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class TorrentCommand method execute.
@Override
public void execute(String commandName, ConsoleInput ci, List<String> args) {
if (!args.isEmpty()) {
String subcommand = (String) args.remove(0);
if (ci.torrents.isEmpty()) {
ci.out.println("> Command '" + getCommandName() + "': No torrents in list (Maybe you forgot to 'show torrents' first).");
} else {
String name;
DownloadManager dm;
try {
int number = Integer.parseInt(subcommand);
if ((number > 0) && (number <= ci.torrents.size())) {
dm = (DownloadManager) ci.torrents.get(number - 1);
if (dm.getDisplayName() == null)
name = "?";
else
name = dm.getDisplayName();
performCommandIfAllowed(ci, args, dm, "#" + subcommand, name);
} else
ci.out.println("> Command '" + getCommandName() + "': Torrent #" + subcommand + " unknown.");
} catch (NumberFormatException e) {
if ("all".equalsIgnoreCase(subcommand)) {
Iterator torrent = ci.torrents.iterator();
while (torrent.hasNext()) {
dm = (DownloadManager) torrent.next();
if (dm.getDisplayName() == null)
name = "?";
else
name = dm.getDisplayName();
performCommandIfAllowed(ci, args, dm, subcommand, name);
}
} else if ("hash".equalsIgnoreCase(subcommand)) {
String hash = (String) args.remove(0);
List torrents = ci.getGlobalManager().getDownloadManagers();
boolean foundit = false;
Iterator torrent = torrents.iterator();
while (torrent.hasNext()) {
dm = (DownloadManager) torrent.next();
if (hash.equals(TorrentUtils.nicePrintTorrentHash(dm.getTorrent(), true))) {
if (dm.getDisplayName() == null)
name = "?";
else
name = dm.getDisplayName();
// FIXME: check user permission here and fix it to take torrent hash instead of subcommand
performCommandIfAllowed(ci, args, dm, hash, name);
foundit = true;
break;
}
}
if (!foundit) {
// second check for
TRHost host = ci.getCore().getTrackerHost();
if (host != null) {
TRHostTorrent[] h_torrents = host.getTorrents();
for (int i = 0; i < h_torrents.length; i++) {
TRHostTorrent ht = h_torrents[i];
if (hash.equals(TorrentUtils.nicePrintTorrentHash(ht.getTorrent(), true))) {
name = TorrentUtils.getLocalisedName(ht.getTorrent());
// FIXME: check user permission here and fix it to take torrent hash instead of subcommand
performCommandIfAllowed(ci, args, ht, hash, name);
foundit = true;
break;
}
}
}
}
if (!foundit) {
ci.out.println("> Command '" + getCommandName() + "': Hash '" + hash + "' unknown.");
}
} else {
ci.out.println("> Command '" + getCommandName() + "': Subcommand '" + subcommand + "' unknown.");
}
}
}
} else {
ci.out.println("> Missing subcommand for '" + getCommandName() + "'");
printHelp(ci.out, args);
}
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class TorrentFilter method matchWildcard.
/**
* attempst to match a wildcard against the list of torrents by
* checking their display name
* @param torrents list of available torrents to match
* @param filter wildcard (glob) filter
* @return list of matched DownloadManager objects
*/
private List matchWildcard(List torrents, String filter) {
Pattern pattern = Pattern.compile(wildcardToPattern(filter), Pattern.CASE_INSENSITIVE);
List list = new ArrayList();
for (Iterator iter = torrents.iterator(); iter.hasNext(); ) {
DownloadManager dm = (DownloadManager) iter.next();
if (pattern.matcher(dm.getDisplayName()).matches())
list.add(dm);
}
return list;
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class TorrentLog method performCommand.
@Override
protected boolean performCommand(ConsoleInput ci, DownloadManager dm, List args) {
try {
dms_mon.enter();
if (!gm_listener_added) {
gm_listener_added = true;
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
gm.addListener(new GlobalManagerAdapter() {
@Override
public void downloadManagerRemoved(DownloadManager dm) {
dms.remove(dm);
}
}, false);
}
boolean turnOn;
if (mode == MODE_FLIP) {
turnOn = !dms.contains(dm);
} else {
turnOn = mode == MODE_ON;
}
if (turnOn) {
ci.out.print("->on] ");
if (dms.contains(dm)) {
return true;
}
dms.add(dm);
if (dms.size() == 1) {
Logger.addListener(this);
}
} else {
ci.out.print("->off] ");
dms.remove(dm);
if (dms.size() == 0) {
Logger.removeListener(this);
}
}
} catch (Exception e) {
e.printStackTrace(ci.out);
return false;
} finally {
dms_mon.exit();
}
return true;
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class Move method execute.
@Override
public void execute(String commandName, ConsoleInput ci, List args) {
if (args.isEmpty()) {
ci.out.println("> Missing subcommand for 'move'\r\n> move syntax: move <#from> [<#to>]");
return;
}
if (ci.torrents.isEmpty()) {
ci.out.println("> Command 'move': No torrents in list.");
return;
}
int ncommand;
int nmoveto = -1;
boolean moveto = false;
try {
ncommand = Integer.parseInt((String) args.get(0));
if (args.size() > 1) {
nmoveto = Integer.parseInt((String) args.get(1));
moveto = true;
}
} catch (NumberFormatException e) {
ci.out.println("> Command 'move': Subcommand '" + args.get(0) + "' unknown.");
return;
}
int number = Math.abs(ncommand);
if (number == 0 || number > ci.torrents.size()) {
ci.out.println("> Command 'move': Torrent #" + Integer.toString(number) + " unknown.");
return;
}
DownloadManager dm = (DownloadManager) ci.torrents.get(number - 1);
String name = dm.getDisplayName();
if (name == null)
name = "?";
GlobalManager gm = dm.getGlobalManager();
if (moveto) {
gm.moveTo(dm, nmoveto - 1);
gm.fixUpDownloadManagerPositions();
ci.out.println("> Torrent #" + Integer.toString(number) + " (" + name + ") moved to #" + Integer.toString(nmoveto) + ".");
} else if (ncommand > 0) {
if (gm.isMoveableUp(dm)) {
while (gm.isMoveableUp(dm)) gm.moveUp(dm);
gm.fixUpDownloadManagerPositions();
ci.out.println("> Torrent #" + Integer.toString(number) + " (" + name + ") moved to top.");
} else {
ci.out.println("> Torrent #" + Integer.toString(number) + " (" + name + ") already at top.");
}
} else {
if (gm.isMoveableDown(dm)) {
while (gm.isMoveableDown(dm)) gm.moveDown(dm);
gm.fixUpDownloadManagerPositions();
ci.out.println("> Torrent #" + Integer.toString(number) + " (" + name + ") moved to bottom.");
} else {
ci.out.println("> Torrent #" + Integer.toString(number) + " (" + name + ") already at bottom.");
}
}
}
Aggregations