【问题标题】:How to set active downloads in session with libtorrent/Python如何在与 libtorrent/Python 的会话中设置活动下载
【发布时间】:2020-02-05 07:25:32
【问题描述】:

我正在尝试制作一个脚本来在 python 中下载文件。到目前为止,会话的默认设置非常好。但是当我尝试设置“活动下载”时,它只是不下载。我确定我做错了,但我不知道在哪里。 libtorrent 中活动下载的默认值为 3。我应该如何更改会话设置?我真的是python的新手。

代码如下:


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 = []

这里是我想放洪流的地方。文档说我必须将 auto_managed 设置为 false 才能更改活动下载。

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

代码在这里被执行。

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)

在我尝试在第一部分更改设置并更改 auto_managed 之前,它工作得很好。 所以我想也许这不是办法。我已经阅读了所有文档,但我不知道如何应用它。有人可以帮我吗?

我很抱歉我的英语不好

【问题讨论】:

  • 为了清楚起见,您要做的是设置 libtorrent active_downloads 配置。此处记录的libtorrent.org/reference-Settings.html#active_limit 对吗?
  • 是的。确实如此。其实我已经可以找到方法了。我把它放在其他评论中。文档真的很大。

标签: python-3.x ubuntu download settings libtorrent


【解决方案1】:

以下是会话应该如何开始以下载多个种子。设置会话,设置设置并将这些设置应用于会话。

ses = lt.session()
ses.listen_on(6881, 6891)
sett = lt.session_settings()
sett = {'allow_multiple_connections_per_ip': True,
  'dont_count_slow_torrents': True,
  'active_downloads': -1,
  'active_seeds': 7,
  'active_checking': 3,}

ses.set_settings(sett)

downloads = []

是的。 auto_managed 不需要设置为 False。感谢您的帮助-。

【讨论】:

    【解决方案2】:

    种子限制设置,如documentation 所述,适用于“自动管理”的种子。对于 torrent,将 auto_managed 设置为 false 是一种选择退出 libtorrent 内置的自动启动/停止/队列逻辑的方法。默认情况下是 true,并且 libtorrent 会限制同时下载的 torrent 的数量。

    【讨论】:

    • 感谢您的澄清。是的。我对此有点困惑,我不需要设置它。谢谢。到目前为止工作得很好。如此可爱的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多