Search in sources :

Example 6 with TOTorrentProgressListener

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

the class TOTorrentCreatorImpl method create.

@Override
public TOTorrent create(boolean skip_hashing) throws TOTorrentException {
    try {
        if (announce_url == null) {
            throw (new TOTorrentException("Skeleton creator", TOTorrentException.RT_WRITE_FAILS));
        }
        File base_to_use;
        if (is_desc) {
            base_to_use = createLayoutMap();
        } else {
            base_to_use = torrent_base;
        }
        if (piece_length > 0) {
            torrent = new TOTorrentCreateImpl(torrent_type, linkage_map, base_to_use, announce_url, add_other_hashes, piece_length);
        } else {
            torrent = new TOTorrentCreateImpl(torrent_type, linkage_map, base_to_use, announce_url, add_other_hashes, piece_min_size, piece_max_size, piece_num_lower, piece_num_upper);
        }
        for (TOTorrentProgressListener l : listeners) {
            torrent.addListener(l);
        }
        torrent.create(skip_hashing);
        return (torrent);
    } finally {
        if (is_desc) {
            destroyLayoutMap();
        }
    }
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) File(java.io.File) TOTorrentProgressListener(com.biglybt.core.torrent.TOTorrentProgressListener)

Example 7 with TOTorrentProgressListener

use of com.biglybt.core.torrent.TOTorrentProgressListener 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

TOTorrentProgressListener (com.biglybt.core.torrent.TOTorrentProgressListener)7 File (java.io.File)7 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)6 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 TOTorrentCreator (com.biglybt.core.torrent.TOTorrentCreator)2 URL (java.net.URL)2 Core (com.biglybt.core.Core)1 CoreOperation (com.biglybt.core.CoreOperation)1 CoreOperationTask (com.biglybt.core.CoreOperationTask)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)1 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)1 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)1 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)1 PluginInterface (com.biglybt.pif.PluginInterface)1 UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)1 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)1