qBittorrent 分享率限制模式 share_limits_mode 怎么设置?
2026/9/10 8:21:22 网站建设 项目流程

qBittorrent 分享率限制模式 share_limits_mode 怎么设置?

【免费下载链接】qBittorrentqBittorrent BitTorrent client项目地址: https://gitcode.com/GitHub_Trending/qb/qBittorrent

qBittorrent 的分享率限制支持三个独立的限制项:最大分享率(max ratio)、种子时长(seeding time)、无活动种子时长(inactive seeding time)。当同时启用多项限制时,share_limits_mode决定这些限制之间是"任意一项达标就触发"还是"全部达标才触发"后续动作(停止、删除、超级做种等)。这篇文章说明三种设置入口:GUI 选项对话框、单个种子的属性对话框,以及 Web API(2.15.3 起支持)。

share_limits_mode 的取值与含义

模式定义在 sharelimits.h 中:

enum class ShareLimitsMode { Default = -1, // special value MatchAny = 0, MatchAll = 1 };
  • Default(-1):特殊值,表示"跟随上一层设置",主要用于单个种子的覆盖值。
  • MatchAny(0):任一已启用的限制条件达成即触发动作。
  • MatchAll(1):所有已启用的限制条件都达成才触发动作。

这个语义可以从种子剩余时间(ETA)的计算逻辑得到印证,见 torrentimpl.cpp:

if (etaList.isEmpty()) return MAX_ETA; return (shareLimits.mode == ShareLimitsMode::MatchAny) ? std::ranges::min(etaList) : std::ranges::max(etaList);

MatchAny取各限制 ETA 的最小值(最先达标的那项决定触发时间),MatchAll取最大值(所有项都达标才触发)。

限制项的具体数值约定(同样来自 sharelimits.h):

常量含义
DEFAULT_RATIO_LIMIT-2分享率未单独设置,跟随默认值
NO_RATIO_LIMIT-1不启用分享率限制
DEFAULT_SEEDING_TIME_LIMIT-2种子时长未单独设置
NO_SEEDING_TIME_LIMIT-1不启用种子时长限制

种子时长以分钟为单位(GUI 输入框后缀为min,ETA 计算中用seedingTimeLimit * 60换算为秒)。

触发的动作由另一个字段max_ratio_act指定,见 appcontroller.cpp:0停止、1删除、2启用超级做种、3删除并删除内容。

在 GUI 选项对话框中设置(全局模式)

全局的分享率限制在"选项"对话框的BitTorrent页的Share Ratio Limiting区块设置,界面定义见 optionsdialog.ui:

  1. 勾选要启用的限制项:最大分享率、种子时长达到(分钟)、无活动种子时长达到(分钟)。
  2. 在区块底部选择匹配模式,两个单选按钮:
    • Any of the above(对应MatchAny,默认选中):上述任一限制达成即触发动作;
    • All the above(对应MatchAll):上述所有限制都达成才触发动作。
  3. 保存设置。

保存逻辑见 optionsdialog.cpp:

.mode = (m_ui->radioButtonShareLimitsModeAll->isChecked() ? BitTorrent::ShareLimitsMode::MatchAll : BitTorrent::ShareLimitsMode::MatchAny),

即"选中 All 单选框就是MatchAll,否则一律按MatchAny处理"。

在单个种子上覆盖模式

每个种子可以在自己的选项对话框(分享限制部件,见 torrentsharelimitswidget.cpp)中单独设置分享率、种子时长和无活动种子时长,并选择该种子的匹配模式,下拉框两项文案为 "Match any limit" / "Match all the limits"。

种子的取值可以显式指定,也可以继承上层设置,界面上显示为 "Default(默认模式名)" 和 "From category(跟随分类)" 两种继承选项(见 torrentsharelimitswidget.cpp)。单个种子设置的模式会写入恢复数据,重启后保留(见 dbresumedatastorage.cpp 对share_limits_mode的持久化处理)。

通过 Web API 设置(qBittorrent 2.15.3 及以上)

WebAPI_Changelog.md 的 2.15.3 一节记录了三个与share_limits_mode相关的端点变更(PR #24043):

  • sync/maindata端点包含种子的share_limits_mode字段;
  • app/preferences端点包含share_limits_mode选项;
  • app/setPreferences端点允许设置share_limits_mode选项。

读取当前模式

请求GET /api/v2/app/preferences,响应中的share_limits_mode是枚举键名字符串,序列化方式见 appcontroller.cpp:

const BitTorrent::ShareLimits &shareLimits = session->shareLimits(); data[u"max_ratio_enabled"_s] = (shareLimits.ratioLimit >= 0.); data[u"max_ratio"_s] = shareLimits.ratioLimit; data[u"max_seeding_time_enabled"_s] = (shareLimits.seedingTimeLimit >= 0); data[u"max_seeding_time"_s] = shareLimits.seedingTimeLimit; data[u"max_inactive_seeding_time_enabled"_s] = (shareLimits.inactiveSeedingTimeLimit >= 0); data[u"max_inactive_seeding_time"_s] = shareLimits.inactiveSeedingTimeLimit; data[u"share_limits_mode"_s] = Utils::String::fromEnum(shareLimits.mode); data[u"max_ratio_act"_s] = static_cast<int>(shareLimits.action);

fromEnum通过QMetaEnum输出键名(见 string.h),所以取值是"Default""MatchAny""MatchAll"

设置模式

POST /api/v2/app/setPreferences,请求体是 JSON 对象,可以只传share_limits_mode

curl -X POST "http://<WebUI地址>/api/v2/app/setPreferences" \ --cookie "SID=<登录后的会话>" \ -H "Content-Type: application/json" \ -d '{"share_limits_mode":"MatchAll"}'

<WebUI地址>替换为你实际的 Web UI 地址,会话凭证来自 Web UI 的登录认证。服务端处理见 appcontroller.cpp:

BitTorrent::ShareLimits shareLimits = session->shareLimits(); if (hasKey(u"max_ratio_enabled"_s) && !it.value().toBool()) shareLimits.ratioLimit = BitTorrent::NO_RATIO_LIMIT; else if (hasKey(u"max_ratio"_s)) shareLimits.ratioLimit = it.value().toReal(); // ... seeding time 项同理 if (hasKey(u"share_limits_mode"_s)) shareLimits.mode = Utils::String::toEnum(it.value().toString(), BitTorrent::ShareLimitsMode::MatchAny);

两点需要注意:

  • 模式值按字符串解析枚举键名;传入无法识别的值时,toEnum回退到默认参数MatchAny(见 string.h),不会报错但也不会按你写的值生效。
  • setPreferences是增量设置,只提交要改的键即可;限制项的启用/禁用通过max_ratio_enabledmax_seeding_time_enabledmax_inactive_seeding_time_enabled控制,取消启用时服务端会把对应限制置为-1(不限制)。

单个种子的模式则用POST /api/v2/torrents/setShareLimits端点设置(路由注册见 webapplication.h)。设置后可通过sync/maindata响应中的种子share_limits_mode字段核对每个种子的当前模式。

验证设置是否生效

  1. 读回核对:再请求一次GET /api/v2/app/preferences,确认share_limits_mode返回"MatchAll""MatchAny"(GUI 中则检查选项对话框里对应单选按钮的选中状态)。
  2. 行为核对:等待种子达到限制条件,观察是否执行了max_ratio_act对应的动作(停止/删除/超级做种/删除并删内容)。用MatchAny时,最先达标的那项限制就触发动作;用MatchAll时,必须所有已启用限制都达标才触发。

边界与限制

  • Default(-1)是特殊值,表示继承上层设置,不要把它当作"第三种匹配模式"传给setPreferences——全局设置只有MatchAny/MatchAll两种有效选择。
  • 枚举值注释明确说明新增枚举项时不允许改动已有数值,以避免破坏现有用户设置(见 sharelimits.h),升级版本时已保存的模式值保持兼容。
  • Web API 的share_limits_mode支持从 2.15.3 开始,旧版本只能通过 GUI 设置。

【免费下载链接】qBittorrentqBittorrent BitTorrent client项目地址: https://gitcode.com/GitHub_Trending/qb/qBittorrent

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询