How to set active downloads in session with libtorrent/Python

by Jhonny Setnom   Last Updated October 08, 2019 01:26 AM - source

I'm trying to made a script to download files in python. So far so good with the default settings for the session. but when i'm trying to set 'active downloads' it just doesn't download. I'm sure i'm doing it wrong but i dont know where. The default for active downloads in libtorrent is 3. How am I suposse to change session settings? I'm really newbie in python.

Heres the code:

!apt install python3-libtorrent

import libtorrent as lt
sett = lt.session_settings()
sett = {'allow_multiple_connections_per_ip': True,
  'active_downloads': -1,
  'active_checking': -1,
  'active_seeds': 7,
  'active_limit': -1}

ses = lt.session()
ses.listen_on(6881, 6891)
ses.set_settings(sett)
downloads = []

Here's where i suposse to put the torrent. The documentation says that I have to set auto_managed to false in order to change the active downloads.

source = files.upload()
params = {
    "save_path": "/content/test1",
    "ti": lt.torrent_info(list(source.keys())[0]),
    'auto_managed': False,
}
downloads.append(ses.add_torrent(params))

and here the code is executed.

import time
from IPython.display import display
import ipywidgets as widgets

state_str = [
    "queued",
    "checking",
    "downloading metadata",
    "downloading",
    "finished",
    "seeding",
    "allocating",
    "checking fastresume",
]

layout = widgets.Layout(width="auto")
style = {"description_width": "initial"}
download_bars = [
    widgets.FloatSlider(
        step=0.01, disabled=True, layout=layout, style=style
    )
    for _ in downloads
]
display(*download_bars)

while downloads:
    next_shift = 0
    for index, download in enumerate(downloads[:]):
        bar = download_bars[index + next_shift]
        if not download.is_seed():
            s = download.status()

            bar.description = " ".join(
                [
                    download.name(),
                    str(s.download_rate / 1000),
                    "kB/s down,",
                    str(s.upload_rate / 1000),
                    "kB/s Up,",                 
                    str(s.num_peers),
                    "Peers",
                    state_str[s.state],
                ]
            )
            bar.value = s.progress * 100

        else:
            next_shift -= 1
            ses.remove_torrent(download)
            downloads.remove(download)
            bar.close()
            download_bars.remove(bar)
            print(download.name(), "done")
        time.sleep(5)

It was working great Before I tried to change settings in the first part and changing auto_managed. So i supposse maybe that's not the way. I've readt like all the documentation but I dont know how to apply it. can someone help me?

I'm sorry for my bad englisg



Related Questions


Complete Download control in python

Updated February 22, 2017 05:26 AM


compiling libtorrent Rasterbar for mavericks

Updated June 13, 2015 14:11 PM

Unable find printf.c on Ubuntu 16.04

Updated October 04, 2018 15:26 PM

Low download speed

Updated August 18, 2017 02:26 AM