Giter Site home page Giter Site logo

Comments (11)

se-bastiaan avatar se-bastiaan commented on August 11, 2024

Are the trackers up? Are you able to use DHT? You should try using https://github.com/frostwire/frostwire-jlibtorrent directly to see if it works.

from torrentstream-android.

vonclutch avatar vonclutch commented on August 11, 2024

Hey,

@se-bastiaan There is a bug with magnet torrents, some trakers are just broken with frostwire it just pause the torrent or take more than 1min/2min to launch the download ( bug with the TorrenHandle who contains errors after the metadata alert ) and slow down the process or even stop the torrent).
To avoid such behavior you need to destroy the torrent if it download from magnet after receive metadata, create a torrent file from the metada and launch a new torrent from the torrent file you create.

With this method your download start after 10/15sec instead of 1/2min.
If you need some code ( it's not the best but it worked :) )

from torrentstream-android.

se-bastiaan avatar se-bastiaan commented on August 11, 2024

Is that a problem with jlibtorrent or Frostwire? Fetching of the magnet is entirely split from the download (TorrentStream.java#L185) what I understand now is that the magnet download inside the library doesn't work? Moreover, I can't find any issues mentioning this problem?

from torrentstream-android.

vonclutch avatar vonclutch commented on August 11, 2024

There is some issues on jlibtorrent's github about this and it's clearly not fixed yet. (even with last version)

issue on frostwire-jlibtorrent

So some people don't use download magnethe from jlibttorent library, they prefer to download metadata and create a torrent file.

from torrentstream-android.

se-bastiaan avatar se-bastiaan commented on August 11, 2024

So some people don't use download magnethe from jlibttorent library, they prefer to download metadata and create a torrent file.

That is exactly what happens in the code: https://github.com/TorrentStream/TorrentStream-Android/blob/develop/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentStream.java#L185

The issues mentions that the torrent is added but is paused. I cannot reproduce that, the sample app just doesn't receive any metadata at all.

from torrentstream-android.

vonclutch avatar vonclutch commented on August 11, 2024

I just add the alert.type METADATA_RECEIVED in the TorrentAddedAlertListener class

    case METADATA_RECEIVED:
            MetadataReceivedAlert metadataAlert = ((MetadataReceivedAlert) alert);
            byte[] bytes = null;

            int size = metadataAlert.metadataSize();
            int maxSize = 2 * 1024 * 1024;

            if (0 < size && size <= maxSize)
                bytes = metadataAlert.torrentData(true);

            torrentMetadata(bytes, metadataAlert.handle().infoHash().toHex(), (MetadataReceivedAlert) alert);
            break;

and to create the file i just check if i'ts a magnet and restart the process.

    @Override
    public void torrentMetadata(byte[] data, String hash, MetadataReceivedAlert alert) {
        try {
            if (isMagnet) {
                File dataDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/torrents/");

                if (!dataDir.exists()) {
                    if (!dataDir.mkdir()) {
                        throw new FileNotFoundException();
                    }
                }

                File torrentFile = new File(dataDir, hash);

                if (!torrentFile.exists()) {
                    if (!torrentFile.createNewFile()) {
                        throw new FileNotFoundException();
                    }

                    try (FileOutputStream stream = new FileOutputStream(torrentFile)) {
                        stream.write(data);
                    }
                }

                String pathToTorrent = torrentFile.getAbsolutePath();

                if (streamingThread != null)
                    streamingThread.interrupt();
                if (streamingHandler != null)
                    streamingHandler.removeCallbacksAndMessages(null);

                if (currentTorrent != null) {
                    currentTorrent.pause();
                    removeListener(currentTorrent);
                    remove(currentTorrent.getTorrentHandle());
                    currentTorrent = null;
                }

                startStream(pathToTorrent);
            }
        } catch(Exception e){
            e.printStackTrace();
        }
    }

from torrentstream-android.

yedajiang44 avatar yedajiang44 commented on August 11, 2024

@se-bastiaan First of all, I'm very sorry for my late reply , and
Thank you very much for your reply!
I don't know more about magnet link, because this magnet link is from your demo。。。

from torrentstream-android.

se-bastiaan avatar se-bastiaan commented on August 11, 2024

I know that the magnet is from the example, but that doesn't mean that the trackers are up and more specifically: that DHT is working in your situation.

Alas, I do not think I'll be able to fix this. It seems to be something upstream. I could try using the download method from TorrentSession instead of fetchMagnet but I don't have time for it.

from torrentstream-android.

se-bastiaan avatar se-bastiaan commented on August 11, 2024

@vonclutch I don't think I completely understand what you mean.

There is already different behaviour based on what kind of url is passed to getTorrentInfo.

If it's a magnet fetchMagnet is called (which is blocking):

            byte[] data = torrentSession.fetchMagnet(torrentUrl, 30000);
            if (data != null)
                try {
                    return TorrentInfo.bdecode(data);
                } catch (IllegalArgumentException e) {
                    throw new TorrentInfoException(e);
                }

This decodes the data array into TorrentInfo which can be used to download the torrent. The METADATA_RECEIVED should never be called based on this code iirc.

To compare this to a regular .torrent file: bytes are read from the file into a data array which decodes in the same way.

from torrentstream-android.

yedajiang44 avatar yedajiang44 commented on August 11, 2024

@se-bastiaan I get it , thank you~~~~~~~~~

from torrentstream-android.

vonclutch avatar vonclutch commented on August 11, 2024

@se-bastiaan frostwire used the same for the SessionManager#fetchmagnet(), they just listen the METADATA_RECEIVED and return the byte[] from this. I didn't want to rewrite the TorrentStream class so i make it fast. I just bypass the fetchmagnet() and make it by myself since you already use the AlertListener here and re-start with a file.

Clearly something is wrong with the lib, delay or even no download at all for magnet ( which take 10-15sec max with a file). From what i saw on their issue it could come from TorrentHandle but could come from anywhere rly :/

from torrentstream-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.