Select which part of file to download

1.2k Views Asked by At

I'm trying to develop my own torrent app using Python. After some research I decided to go with libtorrent, and found this interesting answer:

I've found also another similar question with one answer:

but there I couldn't understand how to do it, I read the full documentation they link in the question and didn't get any idea about how to face this.

I've been looking around libtorrent trying to understand how could I manage the download...

  • How could I to start downloading from the beginning to the end ?

My goal is to start the download the torrent "ordered", meaning I don't want to download random parts of the torrent, the ones availables at the moment, I would like to download it from the beginning to the end.

If anybody has try this and could point me to the right libtorrent documentation would be awesome !!!


  • How could I start to download the file ordered ? --> set_sequential_download()

But how could I wait for the pieces ? How do I configure libtorrent to wait for the first 10 pieces until begin with the next 10 ?

1

There are 1 best solutions below

2
On

The simplest way to download pieces in order is to call set_sequential_download() on the torrent_handle for that torrent. That's piece order, starting with piece 0, 1, 2 etc. The order files are downloaded depend on the order they are specified in the .torrent file (i.e. often a seemingly arbitrary order).

Note that this will make libtorrent request pieces in order, they won't necessarily complete in-order. If what you really want is to stream files, i.e. play back as you're downloading, you want to aim for completing pieces in order, which has a subtle difference. For streaming, you want to look at set_piece_deadline(), which will request such pieces using a different piece-picking mechanism.