Discussion:
[libtorrent] How to select which files to download within a torrent
Ronald Degmar
2017-03-18 21:50:36 UTC
Permalink
Hi guys,

Just a short question.

By applying the files() method to the torrent info I can get a list of all
the files within a torrent to download.

for h in handles:
for f in h.get_torrent_info().files():
six.print_(f.path)

However, how can I specify the pieces for a file I don't want to download?

According to documentation, I should get a peer request for

struct peer_request
{
int piece;
int start;
int length;
bool operator==(peer_request const& r) const;
};

So basically what I should do is:


for i in range(torrent_info.num_pieces()):
if i in range(peerrequest.piece,
peerrequest.piece+peerrequest.length/torrent_info.piece_length +1):
h.piece_priority(i,0) //here I chose not to download

Is this correct?

Also, *what is "start" in the peer_request*? Documentation says:
"piece is the index of the piece in which the range starts. start is the
offset within that piece where the range starts. length is the size of the
range, in bytes."
I read this again and again, and I'm not able to understand. *Does it mean
I have to include this start offset in my formula??????*
I kind of need a graph or picture. Is there somewhere like this in
documentation?

Thanks,

Ronald Barrios
Ronald Degmar
2017-03-18 22:57:23 UTC
Permalink
OK I didn't understand clearly all the field concepts of the peer request
object, but the code worked successfully.
Post by Ronald Degmar
Hi guys,
Just a short question.
By applying the files() method to the torrent info I can get a list of all
the files within a torrent to download.
six.print_(f.path)
However, how can I specify the pieces for a file I don't want to download?
According to documentation, I should get a peer request for
struct peer_request
{
int piece;
int start;
int length;
bool operator==(peer_request const& r) const;
};
if i in range(peerrequest.piece, peerrequest.piece+peerrequest.
h.piece_priority(i,0) //here I chose not to download
Is this correct?
"piece is the index of the piece in which the range starts. start is the
offset within that piece where the range starts. length is the size of the
range, in bytes."
I read this again and again, and I'm not able to understand. *Does it
mean I have to include this start offset in my formula??????*
I kind of need a graph or picture. Is there somewhere like this in
documentation?
Thanks,
Ronald Barrios
Arvid Norberg
2017-03-19 00:54:40 UTC
Permalink
Post by Ronald Degmar
OK I didn't understand clearly all the field concepts of the peer request
object, but the code worked successfully.
That code isn't quite correct. It will set the piece priority to 0 even if
a file you want to download overlaps with it. Keep in mind that files
aren't necessarily aligned to piece boundaries.

For this reason there's also the concept of file priorities in libtorrent.
I would suggest you just set the file priorities to 0 for the files you
don't want, but you shouldn't really mix setting piece- and file priorities
though, as file priorities boil down to setting piece priorities under the
hood.
--
Arvid Norberg
Ronald Degmar
2017-03-19 01:01:05 UTC
Permalink
Thanks so much for the clarification Arvid.
Yes, I noticed that.
I'm using the following now:

*file_priority() prioritize_files() file_priorities()*
void file_priority(int index, int priority) const;
int file_priority(int index) const;
void prioritize_files(std::vector<int> const& files) const;
std::vector<int> file_priorities() const;

However, when testing with picture files, I see that some pictures I chose
not to download, libtorrent actually downloads a little bit.
It may be due to the overlapping you mentioned, right?

Ronald
Post by Arvid Norberg
Post by Ronald Degmar
OK I didn't understand clearly all the field concepts of the peer request
object, but the code worked successfully.
That code isn't quite correct. It will set the piece priority to 0 even if
a file you want to download overlaps with it. Keep in mind that files
aren't necessarily aligned to piece boundaries.
For this reason there's also the concept of file priorities in libtorrent.
I would suggest you just set the file priorities to 0 for the files you
don't want, but you shouldn't really mix setting piece- and file priorities
though, as file priorities boil down to setting piece priorities under the
hood.
--
Arvid Norberg
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Libtorrent-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/libtorrent-discuss
Arvid Norberg
2017-03-19 01:03:55 UTC
Permalink
Post by Ronald Degmar
[...]
However, when testing with picture files, I see that some pictures I chose
not to download, libtorrent actually downloads a little bit.
It may be due to the overlapping you mentioned, right?
That's right. Those files aren't completely downloaded though. they should
be sparse, just to hold the edge pieces. If you prefer, you can enable the
part-file to store those edge pieces instead. (I believe this is libtorrent
1.1.0 and later)
--
Arvid Norberg
Loading...