libtorrent4j icon indicating copy to clipboard operation
libtorrent4j copied to clipboard

TorrentInfo Incomplete

Open arpitjindal97 opened this issue 1 year ago • 1 comments

I have a magnet link, and trying to get the TorrentInfo of it using below code. The code works fine and is able to fetch details but some details like comment, creation_date, trackers, creator are missing in it. How to get complete information using this library. Also, Is it possible to download original .torrent file ?

public static void testRemoveAfterFetch() throws InterruptedException {

        String uri = "magnet:?xt=urn:btih:c8b5ec93ace754eb0f7461a4fcf38c51969ed91e";

        final SessionManager s = new SessionManager();
        //final SessionManager s = new SessionManager(true);

        /*s.addListener(new AlertListener() {
            @Override
            public int[] types() {
                return null;
            }
            @Override
            public void alert(Alert<?> alert) {
                System.out.println(alert);
            }
        });*/

        SettingsPack sp = new SettingsPack();
        //sp.listenInterfaces("0.0.0.0:43567");
        //sp.listenInterfaces("[::]:43567");
        //sp.listenInterfaces("0.0.0.0:43567,[::]:43567");
        //sp.setString(settings_pack.string_types.dht_bootstrap_nodes.swigValue(), "router.silotis.us:6881");
        //sp.setString(settings_pack.string_types.dht_bootstrap_nodes.swigValue(), "router.bittorrent.com:6881");
        //sp.setString(settings_pack.string_types.dht_bootstrap_nodes.swigValue(), "dht.transmissionbt.com:6881");

        SessionParams params = new SessionParams(sp);

        s.start(params);

        final CountDownLatch signal = new CountDownLatch(1);

        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                long nodes = s.stats().dhtNodes();
                // wait for at least 10 nodes in the DHT.
                if (nodes >= 10) {
                    System.out.println("DHT contains " + nodes + " nodes");
                    signal.countDown();
                    timer.cancel();
                }
            }
        }, 0, 1000);

        System.out.println("Waiting for nodes in DHT (10 seconds)...");
        boolean r = signal.await(40, TimeUnit.SECONDS);
        if (!r) {
            System.out.println("DHT bootstrap timeout");
            System.exit(0);
        }

        System.out.println("Fetching the magnet uri, please wait...");
        byte[] data = s.fetchMagnet(uri, 30, new File("/tmp"));

        if (data != null) {
            TorrentInfo torrentInfo = new TorrentInfo(data);

            System.out.println(torrentInfo.name());
            System.out.println(torrentInfo.numFiles());
            System.out.println(torrentInfo.totalSize());
            System.out.println(torrentInfo.trackers());
            System.out.println(torrentInfo.comment());
            System.out.println(torrentInfo.creator());

        } else {
            System.out.println("Failed to retrieve the magnet");
        }

        s.stop();
    

arpitjindal97 avatar Jul 31 '22 17:07 arpitjindal97

Hi @arpitjindal97, it is not really possible to download the original torrent file. The additional information needs to be provided as parameters in the magnet uri, but only a handful are supported, like trackers.

aldenml avatar Aug 15 '22 01:08 aldenml