3

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 ?

Community
  • 1
  • 1
AlvaroAV
  • 10,335
  • 12
  • 60
  • 91

1 Answers1

6

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.

Arvid
  • 10,915
  • 1
  • 32
  • 40
  • Thanks so much for your answer ! I read about sequential download, but as you've said that not force the pieces to download in order. How would you use `set_piece_deadline()` to ensure the file is download ordered ? – AlvaroAV Dec 19 '14 at 08:25
  • set increasing deadlines for the pieces you want to be downloaded later. for instance, you could increment the timeout by 1 ms per piece. – Arvid Feb 03 '15 at 01:57