Search in sources :

Example 6 with TOTorrentAnnounceURLGroup

use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.

the class TorrentAnnounceURLListImpl method setAlreadyExists.

protected boolean setAlreadyExists(URL[] urls) {
    TOTorrentAnnounceURLGroup group = torrent.getTorrent().getAnnounceURLGroup();
    TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
    for (int i = 0; i < sets.length; i++) {
        URL[] u = sets[i].getAnnounceURLs();
        if (u.length != urls.length) {
            continue;
        }
        boolean all_found = true;
        for (int j = 0; j < urls.length; j++) {
            URL u1 = urls[j];
            boolean this_found = false;
            for (int k = 0; k < u.length; k++) {
                URL u2 = u[k];
                if (u1.toString().equals(u2.toString())) {
                    this_found = true;
                    break;
                }
            }
            if (!this_found) {
                all_found = false;
                break;
            }
        }
        if (all_found) {
            return (true);
        }
    }
    return (false);
}
Also used : TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) URL(java.net.URL)

Example 7 with TOTorrentAnnounceURLGroup

use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.

the class TorrentAnnounceURLListImpl method getSets.

@Override
public TorrentAnnounceURLListSet[] getSets() {
    TOTorrentAnnounceURLGroup group = torrent.getTorrent().getAnnounceURLGroup();
    TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
    TorrentAnnounceURLListSet[] res = new TorrentAnnounceURLListSet[sets.length];
    for (int i = 0; i < res.length; i++) {
        res[i] = new TorrentAnnounceURLListSetImpl(this, sets[i]);
    }
    return (res);
}
Also used : TorrentAnnounceURLListSet(com.biglybt.pif.torrent.TorrentAnnounceURLListSet) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)

Example 8 with TOTorrentAnnounceURLGroup

use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.

the class Create method execute.

@Override
public void execute(String commandName, final ConsoleInput ci, List<String> args) {
    if (args.size() < 3) {
        printHelp(ci.out, args);
        return;
    }
    File input_file = new File(args.get(0));
    if (!input_file.exists()) {
        ci.out.println("Input file '" + input_file.getAbsolutePath() + "' doesn't exist");
        return;
    }
    File output_file = new File(args.get(1));
    if (output_file.exists()) {
        ci.out.println("Output file '" + input_file.getAbsolutePath() + "' already exists");
        return;
    }
    List<URL> urls = new ArrayList<>();
    for (int i = 2; i < args.size(); i++) {
        try {
            urls.add(new URL(args.get(i)));
        } catch (Throwable e) {
            ci.out.println("Invalid URL: " + args.get(i));
            return;
        }
    }
    try {
        TOTorrentCreator creator = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(input_file, urls.get(0));
        creator.addListener(new TOTorrentProgressListener() {

            @Override
            public void reportProgress(int percent_complete) {
                ci.out.println("\t\t" + percent_complete + "%");
            }

            @Override
            public void reportCurrentTask(String task_description) {
                ci.out.println("\t" + task_description);
            }
        });
        TOTorrent torrent = creator.create();
        if (urls.size() > 1) {
            TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
            TOTorrentAnnounceURLSet[] sets = new TOTorrentAnnounceURLSet[urls.size()];
            for (int i = 0; i < urls.size(); i++) {
                sets[i] = group.createAnnounceURLSet(new URL[] { urls.get(i) });
                ci.out.println("\tAdded URL '" + urls.get(i) + "'");
            }
            group.setAnnounceURLSets(sets);
        }
        torrent.serialiseToBEncodedFile(output_file);
        ci.out.println("\tTorrent written to '" + output_file + "'");
    } catch (Throwable e) {
        ci.out.println("Failed to create torrent: " + Debug.getNestedExceptionMessage(e));
    }
}
Also used : TOTorrentProgressListener(com.biglybt.core.torrent.TOTorrentProgressListener) URL(java.net.URL) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) TOTorrent(com.biglybt.core.torrent.TOTorrent) TOTorrentCreator(com.biglybt.core.torrent.TOTorrentCreator) File(java.io.File) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet)

Aggregations

TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)8 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)7 URL (java.net.URL)6 TOTorrent (com.biglybt.core.torrent.TOTorrent)4 TOTorrentCreator (com.biglybt.core.torrent.TOTorrentCreator)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 TOTorrentProgressListener (com.biglybt.core.torrent.TOTorrentProgressListener)1 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)1 TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)1 DownloadTypeComplete (com.biglybt.pif.download.DownloadTypeComplete)1 DownloadTypeIncomplete (com.biglybt.pif.download.DownloadTypeIncomplete)1 Torrent (com.biglybt.pif.torrent.Torrent)1 TorrentAnnounceURLListSet (com.biglybt.pif.torrent.TorrentAnnounceURLListSet)1 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)1 SimpleXMLParserDocumentNode (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode)1 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)1 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)1 UISWTViewCoreEventListener (com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener)1