fix: avoid cnsub matching file size unit

This commit is contained in:
jxxghp
2026-07-06 11:58:03 +08:00
parent db9960d9b9
commit 1b12d7664e
3 changed files with 54 additions and 5 deletions

View File

@@ -61,6 +61,10 @@ def _parse_publish_time(publish_time: str) -> Tuple[float, ...]:
class FilterModule(_ModuleBase):
"""
过滤器模块,负责按内置和自定义规则筛选种子资源。
"""
CONFIG_WATCH = {
SystemConfigKey.CustomFilterRules.value,
SystemConfigKey.CustomIdentifiers.value,
@@ -73,16 +77,22 @@ class FilterModule(_ModuleBase):
# 运行期规则集 = 内置规则 + 自定义规则覆盖。
rule_set: Dict[str, dict] = {}
def __init__(self):
def __init__(self) -> None:
"""
初始化过滤器模块依赖的规则仓库。
"""
super().__init__()
self.rulehelper = RuleHelper()
def init_module(self) -> None:
"""
初始化过滤规则集,合并内置规则和用户自定义规则。
"""
# 每次重载都先恢复为纯内置规则,避免旧的自定义规则残留在内存里。
self.rule_set = deepcopy(self.builtin_rule_set)
self.__init_custom_rules()
def on_config_changed(self):
def on_config_changed(self) -> None:
"""
自定义过滤或 Meta 识别配置变更后重建规则集并刷新 Rust Meta 配置缓存。
"""
@@ -100,6 +110,9 @@ class FilterModule(_ModuleBase):
@staticmethod
def get_name() -> str:
"""
获取模块名称。
"""
return "过滤器"
@staticmethod
@@ -123,13 +136,22 @@ class FilterModule(_ModuleBase):
"""
return 4
def stop(self):
def stop(self) -> None:
"""
停止过滤器模块。
"""
pass
def test(self):
def test(self) -> None:
"""
测试过滤器模块状态。
"""
pass
def init_setting(self) -> Tuple[str, Union[str, bool]]:
"""
返回过滤器模块启用配置。
"""
pass
def filter_torrents(self, rule_groups: List[str],

View File

@@ -34,7 +34,7 @@ BUILTIN_RULE_SET: Dict[str, dict] = {
r"[中国國繁简](/|\s|\\|\|)?[繁简英粤]|[英简繁](/|\s|\\|\|)?[中繁简]"
r"|繁體|简体|[中国國][字配]|国语|國語|中文|中字|简日|繁日|简繁|繁体"
r"|([\s,.-\[])(chs|cht)(|[\s,.-\]])"
r"|(?<![a-z0-9])(gb|big5)(?![a-z0-9])"
r"|(?<![a-z0-9])(?<!\d\s)(gb|big5)(?![a-z0-9])"
],
"exclude": [],
"tmdb": {

View File

@@ -82,6 +82,33 @@ def test_builtin_hdr_rule_matches_hdr_vivid_release():
assert torrent.pri_order == 100
def test_builtin_cnsub_rule_ignores_trailing_file_size_unit():
"""
内置 CNSUB 规则不应把标题末尾文件大小单位 GB 当成字幕标记。
"""
module = _build_filter_module(
rule_string="CNSUB",
rule_set=BUILTIN_RULE_SET,
)
file_size_only = TorrentInfo(
title="Movie 2026 1080p WEB-DL H264 AAC 39.23 GB",
description="",
)
explicit_gb_subtitle = TorrentInfo(
title="Movie 2026 1080p WEB-DL H264 AAC [GB]",
description="",
)
with patch("app.modules.filter.rust_accel.is_enabled", return_value=False):
filtered = module.filter_torrents(
rule_groups=["test"],
torrent_list=[file_size_only, explicit_gb_subtitle],
)
assert [explicit_gb_subtitle] == filtered
assert explicit_gb_subtitle.pri_order == 100
def test_filter_torrents_keeps_lazy_priority_level_parsing():
"""
命中高优先级规则后不应解析低优先级坏规则。