Search in sources :

Example 1 with Entry

use of com.frostwire.jlibtorrent.Entry in project frostwire by frostwire.

the class SeedAction method buildTorrentAndSeedIt.

private void buildTorrentAndSeedIt(final FileDescriptor fd) {
    try {
        // TODO: Do this so it works with SD Card support / New BS File storage api from Android.
        File file = new File(fd.filePath);
        File saveDir = file.getParentFile();
        file_storage fs = new file_storage();
        fs.add_file(file.getName(), file.length());
        fs.set_name(file.getName());
        // , 0, -1, create_torrent.flags_t.merkle.swigValue());
        create_torrent ct = new create_torrent(fs);
        // commented out the merkle flag above because torrent doesn't appear as "Seeding", piece count doesn't work
        // as the algorithm in BTDownload.getProgress() doesn't make sense at the moment for merkle torrents.
        ct.set_creator("FrostWire " + Constants.FROSTWIRE_VERSION_STRING + " build " + Constants.FROSTWIRE_BUILD);
        ct.set_priv(false);
        final error_code ec = new error_code();
        libtorrent.set_piece_hashes_ex(ct, saveDir.getAbsolutePath(), new set_piece_hashes_listener(), ec);
        final byte[] torrent_bytes = new Entry(ct.generate()).bencode();
        final TorrentInfo tinfo = TorrentInfo.bdecode(torrent_bytes);
        // so the TorrentHandle object is created and added to the libtorrent session.
        BTEngine.getInstance().download(tinfo, saveDir, new boolean[] { true }, null, TransferManager.instance().isDeleteStartedTorrentEnabled());
    } catch (Throwable e) {
        // TODO: better handling of this error
        LOG.error("Error creating torrent for seed", e);
    }
}
Also used : Entry(com.frostwire.jlibtorrent.Entry) com.frostwire.jlibtorrent.swig.set_piece_hashes_listener(com.frostwire.jlibtorrent.swig.set_piece_hashes_listener) com.frostwire.jlibtorrent.swig.create_torrent(com.frostwire.jlibtorrent.swig.create_torrent) com.frostwire.jlibtorrent.swig.file_storage(com.frostwire.jlibtorrent.swig.file_storage) com.frostwire.jlibtorrent.swig.error_code(com.frostwire.jlibtorrent.swig.error_code) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) File(java.io.File)

Example 2 with Entry

use of com.frostwire.jlibtorrent.Entry in project frostwire by frostwire.

the class CreateTorrentDialog method addAvailableCopyrightLicense.

private void addAvailableCopyrightLicense(final Map<String, Entry> entryMap) {
    if (licenseSelectorPanel.hasConfirmedRightfulUseOfLicense()) {
        CopyrightLicenseBroker license = licenseSelectorPanel.getLicenseBroker();
        if (license != null) {
            final Map<String, Entry> info = entryMap.get("info").dictionary();
            info.put("license", Entry.fromMap(license.asMap()));
            entryMap.put("info", Entry.fromMap(info));
        }
    }
}
Also used : Entry(com.frostwire.jlibtorrent.Entry) CopyrightLicenseBroker(com.frostwire.bittorrent.CopyrightLicenseBroker)

Example 3 with Entry

use of com.frostwire.jlibtorrent.Entry in project frostwire by frostwire.

the class CreateTorrentDialog method makeTorrent.

private boolean makeTorrent() {
    boolean result;
    disableSaveCloseButtons();
    File f = new File((create_from_dir) ? directoryPath : singlePath);
    try {
        file_storage fs = new file_storage();
        reportCurrentTask(I18n.tr("Adding files..."));
        libtorrent.add_files(fs, f.getPath());
        create_torrent torrent = new create_torrent(fs, pieceSize);
        torrent.set_priv(false);
        torrent.set_creator("FrostWire " + FrostWireUtils.getFrostWireVersion() + " build " + FrostWireUtils.getBuildNumber());
        if (trackers != null && !trackers.isEmpty()) {
            reportCurrentTask(I18n.tr("Adding trackers..."));
            for (String trackerUrl : trackers) {
                torrent.add_tracker(trackerUrl, 0);
            }
        }
        if (addAvailableWebSeeds(torrent, create_from_dir)) {
            reportCurrentTask(I18n.tr("Calculating piece hashes..."));
            saveDir = f.getParentFile();
            error_code ec = new error_code();
            libtorrent.set_piece_hashes(torrent, saveDir.getAbsolutePath(), ec);
            reportCurrentTask(I18n.tr("Generating torrent entry..."));
            Entry entry = new Entry(torrent.generate());
            Map<String, Entry> entryMap = entry.dictionary();
            addAvailablePaymentOptions(entryMap);
            addAvailableCopyrightLicense(entryMap);
            final File torrent_file = new File(dotTorrentSavePath);
            reportCurrentTask(I18n.tr("Saving torrent to disk..."));
            Entry entryFromUpdatedMap = entryFromMap(entryMap);
            final byte[] bencoded_torrent_bytes = entryFromUpdatedMap.bencode();
            FileOutputStream fos = new FileOutputStream(torrent_file);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            bos.write(bencoded_torrent_bytes);
            bos.flush();
            bos.close();
            result = true;
            reportCurrentTask("");
        } else {
            result = false;
            revertSaveCloseButtons();
            textWebSeeds.selectAll();
        }
    } catch (Throwable e) {
        result = false;
        revertSaveCloseButtons();
        Debug.printStackTrace(e);
        reportCurrentTask(I18n.tr("Operation failed."));
    }
    return result;
}
Also used : Entry(com.frostwire.jlibtorrent.Entry) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with Entry

use of com.frostwire.jlibtorrent.Entry in project frostwire by frostwire.

the class BTEngine method migrateVuzeDownloads.

private void migrateVuzeDownloads() {
    try {
        File dir = new File(ctx.homeDir.getParent(), "azureus");
        File file = new File(dir, "downloads.config");
        if (file.exists()) {
            Entry configEntry = Entry.bdecode(file);
            List<Entry> downloads = configEntry.dictionary().get("downloads").list();
            for (Entry d : downloads) {
                try {
                    Map<String, Entry> map = d.dictionary();
                    File saveDir = new File(map.get("save_dir").string());
                    File torrent = new File(map.get("torrent").string());
                    List<Entry> filePriorities = map.get("file_priorities").list();
                    Priority[] priorities = Priority.array(Priority.IGNORE, filePriorities.size());
                    for (int i = 0; i < filePriorities.size(); i++) {
                        long p = filePriorities.get(i).integer();
                        if (p != 0) {
                            priorities[i] = Priority.NORMAL;
                        }
                    }
                    if (torrent.exists() && saveDir.exists()) {
                        LOG.info("Restored old vuze download: " + torrent);
                        restoreDownloadsQueue.add(new RestoreDownloadTask(torrent, saveDir, priorities, null));
                        saveResumeTorrent(new TorrentInfo(torrent));
                    }
                } catch (Throwable e) {
                    LOG.error("Error restoring vuze torrent download", e);
                }
            }
            file.delete();
        }
    } catch (Throwable e) {
        LOG.error("Error migrating old vuze downloads", e);
    }
}
Also used : Entry(com.frostwire.jlibtorrent.Entry) Priority(com.frostwire.jlibtorrent.Priority) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) File(java.io.File) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Example 5 with Entry

use of com.frostwire.jlibtorrent.Entry in project frostwire by frostwire.

the class CreateTorrentDialog method addAvailablePaymentOptions.

private void addAvailablePaymentOptions(final Map<String, Entry> entryMap) {
    if (paymentOptionsPanel.hasPaymentOptions()) {
        PaymentOptions paymentOptions = paymentOptionsPanel.getPaymentOptions();
        if (paymentOptions != null) {
            final Map<String, Entry> info = entryMap.get("info").dictionary();
            info.put("paymentOptions", Entry.fromMap(paymentOptions.asMap()));
            entryMap.put("info", Entry.fromMap(info));
        }
    }
}
Also used : Entry(com.frostwire.jlibtorrent.Entry) PaymentOptions(com.frostwire.bittorrent.PaymentOptions)

Aggregations

Entry (com.frostwire.jlibtorrent.Entry)5 File (java.io.File)3 TorrentInfo (com.frostwire.jlibtorrent.TorrentInfo)2 CopyrightLicenseBroker (com.frostwire.bittorrent.CopyrightLicenseBroker)1 PaymentOptions (com.frostwire.bittorrent.PaymentOptions)1 Priority (com.frostwire.jlibtorrent.Priority)1 TcpEndpoint (com.frostwire.jlibtorrent.TcpEndpoint)1 com.frostwire.jlibtorrent.swig.create_torrent (com.frostwire.jlibtorrent.swig.create_torrent)1 com.frostwire.jlibtorrent.swig.error_code (com.frostwire.jlibtorrent.swig.error_code)1 com.frostwire.jlibtorrent.swig.file_storage (com.frostwire.jlibtorrent.swig.file_storage)1 com.frostwire.jlibtorrent.swig.set_piece_hashes_listener (com.frostwire.jlibtorrent.swig.set_piece_hashes_listener)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1