How to add set_sequential_download() to this code using libtorrent?

432 views Asked by At

How can I add set_sequential_download(True) to the below python code?

I have tried several ways to add the handle; but it's not working. sequential_download is also mentioned as both a torrent flag and torrent handle. I went through the documentation on the Libtorrent website and it's unclear, plus my experience with python is extremely limited.

import libtorrent as lt
import time
import datetime

ses = lt.session()
ses.listen_on(6881, 6891)
params = {
    'save_path': '/content/drive/Shared drives/Dakar files/Torrent',
    'storage_mode': lt.storage_mode_t(2),
    'paused': False,
    'auto_managed': True,
    'duplicate_is_error': True)

link = "??" # PASTE TORRENT/MAGNET LINK HERE
print(link)


h = ses.add_torrent({'ti': info, 'save_path': './'})
handle = lt.add_magnet_uri(ses, link, params)
ses.start_dht()

begin = time.time()
print(datetime.datetime.now())

print ('Downloading Metadata...')
while (not handle.has_metadata()):
    time.sleep(1)
print ('Got Metadata, Starting Torrent Download...')

print("Starting", handle.name())

while (handle.status().state != lt.torrent_status.seeding):
    s = handle.status()
            state_str = ['queued', 'checking', 'downloading metadata', \
            'downloading', 'finished', 'seeding', 'allocating']
    print ('%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s ' % \
            (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
            s.num_peers, state_str[s.state]))
    time.sleep(5)

end = time.time()
print(handle.name(), "COMPLETE")

print("Elapsed Time: ",int((end-begin)//60),"min :", int((end-begin)%60), "sec")

print(datetime.datetime.now())
1

There are 1 answers

0
Arvid On

To enable and disable certain features for a torrent, you use set_flags() and unset_flags() (docs).

The flags you can set and clear are documented here.

Please file a github ticket for any part of the documentation that's unclear. There are links in the documentation itself to do this.