我有个问题。我不是 C/C++ 程序员,libtorrent 文档对我来说并不是很清楚。没有像 libtorrent 的 python 文档那样可以找到的文档。
此刻,我尝试在 stackoverflow 中搜索代码示例,以了解如何将 save_state 和 load_state 用于会话。
谁能给我一个例子或解释我如何保存会话状态并稍后加载?
目标是在进程重新启动时恢复所有种子。
ses = libtorrent.session()
ses.listen_on(6881, 6891)
if os.path.isfile('./tempfile'):
with open('./tempfile', 'wb+') as temp_file:
ses.load_state(
libtorrent.bdecode(temp_file.read())
)
params = {
'save_path': '/home/downloads/',
'storage_mode': libtorrent.storage_mode_t(2),
'paused': False,
'auto_managed': True,
'duplicate_is_error': True
}
link = "magnet:?xt=urn:btih:4MR6HU7SIHXAXQQFXFJTNLTYSREDR5EI&tr=http://tracker.vodo.net:6970/announce"
handle = libtorrent.add_magnet_uri(ses, link, params)
while not handle.has_metadata():
time.sleep(1)
with open('./tempfile', 'wb+') as temp_file:
temp_file.write(libtorrent.bencode(ses.save_state()))
更新 当在 torrent 句柄上使用 save_state_resume() 时它也没有返回?我发现执行“pydoc libtorrent > libtorrentDoc.txt”给了我一个有用的文档来浏览和搜索。此时我将磁铁重新添加到会话中并使用上面的代码。
也许有人有更有效的方法?