【发布时间】: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