Search in sources :

Example 86 with DownloadManager

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;
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) Torrent(com.biglybt.pif.torrent.Torrent) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeJob(com.biglybt.core.devices.TranscodeJob) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) TOTorrent(com.biglybt.core.torrent.TOTorrent) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeFile(com.biglybt.core.devices.TranscodeFile) Download(com.biglybt.pif.download.Download)

Example 87 with DownloadManager

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);
    }
}
Also used : Iterator(java.util.Iterator) List(java.util.List) TRHost(com.biglybt.core.tracker.host.TRHost) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 88 with DownloadManager

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;
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 89 with DownloadManager

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;
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) GlobalManagerAdapter(com.biglybt.core.global.GlobalManagerAdapter) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 90 with DownloadManager

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.");
        }
    }
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)307 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)54 TOTorrent (com.biglybt.core.torrent.TOTorrent)35 GlobalManager (com.biglybt.core.global.GlobalManager)33 PEPeerManager (com.biglybt.core.peer.PEPeerManager)29 File (java.io.File)29 List (java.util.List)21 Core (com.biglybt.core.Core)17 Download (com.biglybt.pif.download.Download)17 Point (org.eclipse.swt.graphics.Point)17 UIFunctions (com.biglybt.ui.UIFunctions)16 Tag (com.biglybt.core.tag.Tag)15 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)14 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)13 ArrayList (java.util.ArrayList)13 DiskManager (com.biglybt.core.disk.DiskManager)12 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)12 CoreRunningListener (com.biglybt.core.CoreRunningListener)11 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)11 PEPeer (com.biglybt.core.peer.PEPeer)11