Libtorrent: [python] Download a single file

Created on 6 Mar 2020  路  6Comments  路  Source: arvidn/libtorrent

libtorrent version (or branch): master
platform/architecture: Windows 64
compiler and compiler version: VS2015
Language :python

import libtorrent as lt
import libtorrent as lt

ses = lt.session()
ses.listen_on(6881, 6891)

e = lt.bdecode(open("test.torrent", 'rb').read())
info = lt.torrent_info(e)
h = ses.add_torrent(info, "d:\\torrent")

I see there is about 259 Files their by num_files I don't want to download all the files at a time.
I want to only download a single file which index number is 153.I mean download only 153 index file don't_download others.Actually i am not familiar with c++,for that i can not implement it by reading libtorrent api documentation.
I tried to find for python documentation but failed.I will be glad if someone can give me a piece code to solve the problem.

All 6 comments

listen_on() is deprecated, you should not use it.
That overload of add_torrent() is also deprecated. Instead, pass in a add_torrent_params object (in python, that's just a dict). In that dict, set the file priorities to 0 for all files and 1 for file 153.
That's an array of integers.

See: http://libtorrent.org/reference-Core.html#file_priorities

here's an example: https://github.com/arvidn/libtorrent/blob/RC_1_2/bindings/python/simple_client.py#L14

add file_priorities to the dictionary passed to add_torrent()

priority = []

for i in range(1,260):
    if i != 153:
        priority.append(0) #priority 0 to not download it
    else:
        priority.append(1) #priority 1 where index is 153
h = ses.add_torrent({'ti':info,
                      'save_path':'/singleFile',
                      'file_priorities':priority
                      })

Thanks for reply.
I tried as you told but seems its still downloading all the files.Problem still remain.
please check the params if their is any problem.

the file indices are 0-based. so your code picks a file off-by-one. Do you actually see all files be downloaded in full? or do you see the file you picked + parts of the two adjacent files?
the latter is expected unless you use a part-file

it should not download any parts of other videos except selected one.I am not able to keep open console for long time for large videos files...thats why i wanting to download a single file at a time.when i got time then i will download another file.I see it fully downloading the selected one + other video part(thos are broken) but selected one is fine to play.

bittorrent validates and shares data at piece granularity, so that data overlapping with other files has to be downloaded too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  12Comments

ctlaltdefeat picture ctlaltdefeat  路  15Comments

FranciscoPombal picture FranciscoPombal  路  5Comments

techtonik picture techtonik  路  12Comments

johang picture johang  路  10Comments