How to completely skip writing files to disk with libtorrent downloads? -


i have following code download torrent off of magnet uri.

#python #lt.storage_mode_t(0) ## tried this, didnt work ses = lt.session() params = { 'save_path': "/save/here"}  ses.listen_on(6881,6891) ses.add_dht_router("router.utorrent.com", 6881)  #ses = lt.session() link = "magnet:?xt=urn:btih:395603fa..hash..." handle = lt.add_magnet_uri(ses, link, params) while (not handle.has_metadata()):     time.sleep(1) handle.pause () # got meta data paused, , set priority handle.file_priority(0, 1) handle.file_priority(1,0) handle.file_priority(2,0) print handle.file_priorities() #output [1,0,0] #i checked no files written disk yet. handle.resume() while (not handle.is_finished()):     time.sleep(1) #wait until download  

it works, in specific torrent, there 3 files, file 0 - 2 kb, file 1 - 300mb, file 3 - 2kb.

as can seen code, file 0 has priority of 1, while rest has priority 0 (i.e. don't download).

the problem when 0 file finishes downloading, want stop , not download anymore. download 1 file -partially, 100mb, or 200mb, couple kb , entire file.

so question is: how can make sure file 0 downloaded, , not 1 , 2.

edit: added check whether got metadata, set priority , resume it, still downloads second file partially.

the reason happens because of race between adding torrent (which starts download) , setting file priorities.

to avoid can set file priorities along adding torrent, this:

p = parse_magnet_uri(link) p['file_priorities'] = [1, 0, 0] handle = ses.add_torrent(p) 

update:

you don't need know number of files, it's ok provide file priorities more files ends being in torrent file. remaining ones ignored. however, if don't want download (except metadata/.torrent) swarm, better way set flag_upload_mode flag. see documentation.

p = parse_magnet_uri(link) p['flags'] |= add_torrent_params_flags_t.flag_upload_mode handle = ses.add_torrent(p) 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -