fix(eh): 标题不再带 " - Tags",并附批量改名脚本

meta description 的真实格式是
  "Free Hentai Misc Gallery:  <title> - Tags: a, b, c"
旧正则 `Gallery:\s*([^:]+):` 里的 [^:]+ 是贪婪的,
一路吃到标签段自己的冒号为止,把 " - Tags" 也吞进了标题,
导致下载目录/文件名结尾凭空多出 " - Tags"。

改为显式认 " - Tags:" 这个分隔符(Tags 段可选,无标签时认行尾),
reTitleSuffix 同时认 Tags 结尾,提取后再兜底剥一次。

线上实测(g/4239272):标题由
  "Hinata l Boruto (CriticalHAI) [AI Generated] - Tags"
变为
  "Hinata l Boruto (CriticalHAI) [AI Generated]"

附带 remove-tags-suffix.bat/.ps1:递归去掉已有压缩包文件名结尾的
" - Tags",覆盖 zip/rar/7z/cbz/cbr/cb7/tar/gz,幂等。
This commit is contained in:
2026-10-21 22:18:45 +08:00
parent 3d46640364
commit 1d7d261490
4 changed files with 150 additions and 3 deletions
+72
View File
@@ -0,0 +1,72 @@
package eh
// 回归测试:文件名尾巴多出 " - Tags"(2026-10 线上问题)
//
// 现象:下载下来的目录/压缩包名全是 "... - Tags",原本标题没有这个。
//
// 根因:meta description 的真实格式是
// "Free Hentai Misc Gallery: <title> - Tags: a, b, c"
// 旧正则 `Gallery:\s*([^:]+):` 里的 `[^:]+` 是贪婪的,它一路吃到
// 标签段自己的那个冒号为止,于是把 " - Tags" 也当成标题的一部分。
//
// 正确做法:标题的结束边界就是 " - Tags:",必须显式认这个分隔符。
import "testing"
func TestTitleFromDescStripsTags(t *testing.T) {
tests := []struct {
name string
desc string
want string
}{
{
name: "带 Tags 段(线上真实样本)",
desc: "Free Hentai Misc Gallery: Hinata l Boruto (CriticalHAI) [AI Generated] - Tags: boruto, hinata hyuga, sole female, ai generated",
want: "Hinata l Boruto (CriticalHAI) [AI Generated]",
},
{
name: "无 Tags 段",
desc: "Free Hentai Doujinshi Gallery: [Some Circle] Flagged Gallery",
want: "[Some Circle] Flagged Gallery",
},
{
name: "Tags 前多空格",
desc: "Free Hentai Manga Gallery: Some Title - Tags: a, b",
want: "Some Title",
},
{
name: "标题本身含冒号(竖线译名等)",
desc: "Free Hentai Misc Gallery: [A] Orig | 译名 - Tags: x",
want: "[A] Orig | 译名",
},
{
name: "标题本身以 Tags 结尾也不能被剥",
desc: "Free Hentai Misc Gallery: Study About Tags - Tags: a",
want: "Study About Tags",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := reTitleFromDesc.FindStringSubmatch(tt.desc)
if m == nil {
t.Fatalf("没匹配到标题: %q", tt.desc)
}
got := reTitleSuffix.ReplaceAllString(m[1], "")
if got != tt.want {
t.Errorf("标题不对:\n got %q\nwant %q", got, tt.want)
}
})
}
}
func TestTitleTagStripsTagsSuffix(t *testing.T) {
// <title> 一般是 "... - E-Hentai Galleries",但也可能直接是 "... - Tags"
m := reTitleTag.FindStringSubmatch("<title>Some Gallery - Tags</title>")
if m == nil {
t.Fatal("没取到 <title>")
}
if got := reTitleSuffix.ReplaceAllString(m[1], ""); got != "Some Gallery" {
t.Errorf("title 去 Tags 失败: %q", got)
}
}