se-bastiaan / TorrentStream-Android

A torrent streamer library for Android based on libtorrent4j
Other
343 stars 108 forks source link

Identifying file download progress #28

Closed 4gus71n closed 7 years ago

4gus71n commented 7 years ago

Hi,

Quick question here, I was wondering if I can select more than one file to download per torrent? For example I have something like this:

TorrentStream torrentStream = mTorrentStreamCache.getDownloadTorrent(abcTorrent);

torrentStream.addListener(new DefaultTorrentListener(abcTorrent) {
    @Override
    public void onStreamPrepared(Torrent torrent) {
        Log.d(TAG, "The DefaultTorrentListener#onStreamPrepared(Torrent) method was fired");
        EventBus.getDefault().post(new AbcTunesEvents.TrackBufferingEvent(torrent, getAbcTorrent().getSelectedFile()));
        torrent.setSelectedFileIndex(getAbcTorrent().getSelectedFile());
        torrent.startDownload();
    }

    @Override
    public void onStreamProgress(Torrent torrent, StreamStatus streamStatus) {
        super.onStreamProgress(torrent, streamStatus);
        //Show download progress
    }
});

if (torrentStream.isStreaming()) {
    Torrent torrent = torrentStream.getCurrentTorrent();
    torrent.setSelectedFileIndex(abcTorrent.getSelectedFile());
    torrent.startDownload();

    EventBus.getDefault().post(new AbcTunesEvents.TrackBufferingEvent(torrent, abcTorrent.getSelectedFile()));
} else {
   torrentStream.startStream(abcTorrent.getMagneticLink());
}

If I want to download the first and third file from a torrent that contains six files, how can I set that? Calling Torrent#setSelectedFileIndex(int) unselects the previous selected file?

se-bastiaan commented 7 years ago

Torrent#setSelectedFileIndex(int) sets all files in the torrent to the IGNORE priority, which means that the currently downloading file is paused and the new index identifies the file that should be downloaded now. However, I do not really know what the behaviour will be like. The library was specifically built to do single file sequential downloading, but I can imagine that it would work.

If you really want to download files then it might be better to directly use jlibtorrent. Or you could use TorrentStream and use Torrent#getTorrentHandle to get the underlaying TorrentHandle to directly modify the file and piece priorities.

4gus71n commented 7 years ago

Oh I imagine that It will be something like that. I'm gonna to take a shot at Torrent#getTorrentHandle(). Thank you very much for the quick response!