se-bastiaan / TorrentStream-Android

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

Sequential download only for selected file #46

Closed proninyaroslav closed 5 years ago

proninyaroslav commented 6 years ago

Hi. I'm trying to implement streaming for a user-selected file from the torrent. In this case, other files normally have NORMALpriority, and for the selected file, as I read bytes from TorrentInputStream, I make setInterestedBytes() for the next byte portion. But this approach does not work and the file download doesn't get consistent, in fact the priority change to SEVEN is ignored and prioritized pieces are not downloaded first. Can you tell me how to be in a similar situation? I could use TorrentStream-Android as it is, but it works well only when you download one file from the entire torrent, and ignore the rest.

se-bastiaan commented 6 years ago

I don't think I completely understand your question, could you please clarify? What are you trying to do exactly?

proninyaroslav commented 6 years ago

This is the choice of one or more files from the torrent in order to stream them on HTTP. I looked at the code of your library, this is done for one file, and the rest are ignored. In my case, I want the user to be able to download the rest of the files in torrent, while he streams file selected by him in the same torrent. I use setInterestedBytes() in TorrentInputStream (after each reading) and nanohttpd, but this approach does not work and the file download does not succeed sequentially, as if changing the priority to SEVEN is ignored. This prioritized pieces are not downloaded first. That is, pieces are loaded completely randomly (including parts of other files), although if you follow the logic, it must download pieces with a high priority first.

se-bastiaan commented 6 years ago

It's not correct that it must download the higher priority pieces first, that's just what you want. It will download the pieces that are available first. Is the torrent itself put into sequential mode? Are you able to check the priorities of the pieces that your file consists of?

proninyaroslav commented 6 years ago

Sequential download only downloads from the beginning of the torrent and completely ignores the required pieces (of requiered file). A little bit better with the disabled sequential download, but still the necessary pieces aren't downloaded in the first place (only random). screenshot_1536682118

se-bastiaan commented 6 years ago

I must say that I'm out of ideas, it's been some time since I directly used the library myself. I don't get why it isn't correctly prioritising.

Are you using the sequential download code from the library or the sequential download flag of libtorrent?

proninyaroslav commented 6 years ago

I solved this problem, it turned out that I used the wrong piece indexes for havePiece(). Now the problem is that after I check pieces for the availability with havePiece() function, I read available piece from disk, but many pieces contains only zero bytes (by piece index, piece size and file offset I calculate the offset on the disk and read bytes). Does this mean that they are downloaded but not yet flushed to disk? I tried to use flushCache() and wait an alert, but this didn't work.

se-bastiaan commented 6 years ago

It might be possible that the pieces are not on disk yet indeed, I don't know how to make sure libtorrent writes them to disk however.

proninyaroslav commented 6 years ago

I will try to use readPiece() instead of file reading. If it works out I'll make a commit.

aiwinoo7 commented 5 years ago

@se-bastiaan please share your contact e-mail or anything. i need to clear some doubts about torrent streaming

contact me on niwia1997@gmail.com

se-bastiaan commented 5 years ago

@aiwinoo7 My email is in the commit messages of the repo.

aiwinoo7 commented 5 years ago

@aiwinoo7 My email is in the commit messages of the repo.

@se-bastiaan I need your help personally, Please contact me on niwia1997@gmail.com or Telegram: @aiwinoo7