Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TorrentInfo Incomplete #225

Open
arpitjindal97 opened this issue Jul 31, 2022 · 1 comment
Open

TorrentInfo Incomplete #225

arpitjindal97 opened this issue Jul 31, 2022 · 1 comment

Comments

@arpitjindal97
Copy link

arpitjindal97 commented Jul 31, 2022

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();
    
@aldenml
Copy link
Owner

aldenml commented Aug 15, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants