Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix: offer Google fallback for F95 discovery

longmeidao26a63b397bbc
diff --git a/README.md b/README.md
index 6c9a9effd..82a2dbd7a 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,7 @@ python3.14 -m venv .venv
## 关注与候选
关注管理支持粘贴链接、名称或 ID。联网只发生在显式查找和检查更新时;服务启动、健康检查和普通浏览不会联网。
+F95zone 站内索引没有命中名称时,结果区会给出对应的 Google 查询入口;Google 结果只供人核对真实线程链接,不会自动登记来源。
Rule34.xxx 标签身份不区分大小写。跨站来源按规范作者归组,F95 标题中的 `Collection(s)` 不属于作者名。作者头像优先从已验证的官方 FANBOX/Pixiv 页面取得,归档站只作回退。连接器设计与证据见 [`ADR-0019`](docs/adr/0019-site-follow-connectors-and-variant-grouping.md)。
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 3aab1a6c1..548fdb908 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -44,6 +44,7 @@
- `38dcc63`、`b3b028e` 已合入 `master`:关注筛选把「全部」放首位,来源只显示 favicon,作者和筛选横条支持鼠标拖动、滚轮与触摸横滚;卡片复用首页网格,操作按钮只在悬浮时出现,集合用 Mix 叠层和可滚动弹层,多选可批量保存、已看或忽略。批量接口兼容单项并在一个事务中处理所选条目。
- 更新后的正式 Windows 测试为 1051 项通过、13 项跳过。生产继续使用原 EXE,仅重启托盘加载源码;80/443、21 个迁移且 0 待处理、项目 CA 严格 HTTPS writer 均正常。桌面实测作者蓝框完整、筛选横滚从 0 到 640、悬浮操作与 Mix 不重叠、29 行集合弹层和单项多选正常;390×844 为 348px 单列且无页面横向溢出,手机截图捕获失败,视觉截图记为未取得。
- 浏览器验收在 Mix 入口尚被悬浮按钮覆盖时误触三次「标记已看」,`follow_item` 181、184、185 从 `new` 变为 `seen`;未保存到账本、未新增 asset。ledger SHA-256 从 `F8FBD87E...` 变为 `82D46DA2...`,需用户明确授权后才能恢复,当前不再写入。
+- 关注名称查找会把下划线和连字符形式同时按分词形式查询;F95zone 站内索引仍未命中时,结果区给出同名 Google 查询入口,供人核对真实线程链接,不自动登记来源。正式 Windows 测试 1056 项通过、13 项跳过。
## 下一批工作
diff --git a/src/peach/follow_discovery.py b/src/peach/follow_discovery.py
index 893e4394a..0b2d853bb 100644
--- a/src/peach/follow_discovery.py
+++ b/src/peach/follow_discovery.py
@@ -49,12 +49,25 @@ class Candidate:
evidence: str
+@dataclass(frozen=True)
+class ExternalSearch:
+ """站内索引没命中时,交给人继续核对的外部搜索入口。"""
+
+ provider: str
+ label: str
+ query: str
+ url: str
+ evidence: str
+
+
@dataclass(frozen=True)
class Discovery:
term: str
candidates: tuple[Candidate, ...] = ()
#: 逐来源的失败原因;界面要显示,否则「没查到」和「没查成」分不开。
failures: dict[str, str] = field(default_factory=dict)
+ #: 搜索引擎只提供继续核对的入口,不伪装成可直接登记的来源。
+ external_searches: tuple[ExternalSearch, ...] = ()
class CreatorIndex:
@@ -167,17 +180,32 @@ def search_variants(term: str) -> tuple[str, ...]:
"""一个词的几种写法。
f95 的全文搜索按词匹配,`lazyprocrastinator` 搜不到而 `lazy procrastinator` 能。
- 大小写边界是唯一可靠的切分信号——`LazyProcrastinator` 切得开,全小写的连写切不开,
+ 下划线、连字符和大小写边界都是明确的切分信号;全小写的连写仍然切不开,
那就只用原词,不去猜词典。
"""
text = term.strip()
variants = [text]
+ separated = re.sub(r"[_-]+", " ", text).strip()
+ if separated != text and separated not in variants:
+ variants.append(separated)
split = re.sub(r"(?<=[a-z0-9])(?=[A-Z])", " ", text).strip()
if split != text and split not in variants:
variants.append(split)
return tuple(variants)
+def _f95_external_search(term: str) -> ExternalSearch:
+ """Google 由浏览器打开;Peach 不抓结果页,也不绕验证码。"""
+ query = f"{term} f95zone"
+ return ExternalSearch(
+ provider="f95zone",
+ label="用 Google 继续查找 F95zone",
+ query=query,
+ url="https://www.google.com/search?" + urllib.parse.urlencode({"q": query}),
+ evidence="F95zone 站内索引未命中,请核对搜索结果里的真实线程链接",
+ )
+
+
def _f95_candidates(term: str, transport) -> list[Candidate]:
connector = F95ZoneConnector(transport=transport)
picked: list[Candidate] = []
@@ -230,6 +258,7 @@ def discover(term: str, *, secrets_root: Path, state_root: Path,
"rule34xxx", "f95zone")
found: list[Candidate] = []
failures: dict[str, str] = {}
+ external_searches: list[ExternalSearch] = []
def run(name: str, fn) -> None:
if name not in wanted:
@@ -247,4 +276,6 @@ def discover(term: str, *, secrets_root: Path, state_root: Path,
lambda: _rule34xxx_candidates(text, transport,
credentials.load("rule34xxx")))
run("f95zone", lambda: _f95_candidates(text, transport))
- return Discovery(text, tuple(found), failures)
+ if "f95zone" in wanted and not any(row.provider == "f95zone" for row in found):
+ external_searches.append(_f95_external_search(text))
+ return Discovery(text, tuple(found), failures, tuple(external_searches))
diff --git a/src/peach/web_follow.py b/src/peach/web_follow.py
index 2fa21604c..ad06af9d6 100644
--- a/src/peach/web_follow.py
+++ b/src/peach/web_follow.py
@@ -456,6 +456,13 @@ def _candidate_payload(candidate, *, author: str = "") -> dict:
"semantics": candidate.semantics, "evidence": candidate.evidence}
+def _external_search_payload(search) -> dict:
+ return {"provider": search.provider,
+ "provider_label": PROVIDER_LABELS.get(search.provider, search.provider),
+ "label": search.label, "query": search.query,
+ "url": search.url, "evidence": search.evidence}
+
+
def w_follow_resolve(contract, body) -> dict:
"""把粘进来的每一行解析成「可以添加什么」,但**不添加**。
@@ -498,6 +505,8 @@ def w_follow_resolve(contract, body) -> dict:
c.provider, c.ref)) in known}
for c in found.candidates],
"failures": found.failures,
+ "external_searches": [_external_search_payload(search)
+ for search in found.external_searches],
})
continue
results.append({"line": line, "kind": "url",
diff --git a/tests/test_follow_discovery.py b/tests/test_follow_discovery.py
index 2873597f2..e1e9e7d59 100644
--- a/tests/test_follow_discovery.py
+++ b/tests/test_follow_discovery.py
@@ -60,6 +60,9 @@ class SearchVariantTests(unittest.TestCase):
# 全小写连写没有切分信号,就只用原词,不去猜词典。
self.assertEqual(search_variants("lazyprocrastinator"), ("lazyprocrastinator",))
+ def test_an_underscored_name_is_also_tried_as_words(self):
+ self.assertEqual(search_variants("initial_a"), ("initial_a", "initial a"))
+
def test_a_spaced_term_is_left_alone(self):
self.assertEqual(search_variants("Lazy Procrastinator"), ("Lazy Procrastinator",))
@@ -132,6 +135,25 @@ class DiscoverTests(_DiscoveryCase):
found = self._discover("99999999", self.ROUTES, providers=("f95zone",))
self.assertEqual(found.candidates, ())
+ def test_an_f95_miss_offers_google_without_guessing_a_thread(self):
+ found = self._discover(
+ "initial_a", {"latest_data.php": HttpResponse(200, {}, F95_MISS)},
+ providers=("f95zone",))
+ self.assertEqual(found.candidates, ())
+ self.assertEqual(len(found.external_searches), 1)
+ search = found.external_searches[0]
+ self.assertEqual(search.provider, "f95zone")
+ self.assertEqual(search.query, "initial_a f95zone")
+ self.assertEqual(search.url,
+ "https://www.google.com/search?q=initial_a+f95zone")
+ self.assertIn("真实线程链接", search.evidence)
+
+ def test_an_f95_hit_does_not_add_a_redundant_google_link(self):
+ found = self._discover("LazyProcrastinator", self.ROUTES,
+ providers=("f95zone",))
+ self.assertTrue(found.candidates)
+ self.assertEqual(found.external_searches, ())
+
def test_a_partial_name_match_is_reported_as_partial(self):
found = self._discover("Lazy", self.ROUTES, providers=("kemono",))
evidence = {c.label: c.evidence for c in found.candidates}
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index 6dafc0abc..13f87150a 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -16,6 +16,7 @@ from unittest import mock
from peach import web_follow
from peach.follow import FollowSourceError
+from peach.follow_discovery import Discovery, ExternalSearch
from peach.follow_secrets import CredentialError
from peach.follow_sources import FollowCandidate, SourceFetch
from peach.follow_store import FollowStore
@@ -575,6 +576,27 @@ class FollowSourceAddTests(FollowContractTests):
source = self._get()["sources"][0]
self.assertEqual(source["author_key"], "name:lazyprocrastinator")
+ def test_a_name_miss_exposes_the_google_f95_fallback_without_adding_it(self):
+ fallback = ExternalSearch(
+ provider="f95zone", label="用 Google 继续查找 F95zone",
+ query="initial_a f95zone",
+ url="https://www.google.com/search?q=initial_a+f95zone",
+ evidence="F95zone 站内索引未命中,请核对搜索结果里的真实线程链接",
+ )
+ with mock.patch.object(web_follow, "discover", return_value=Discovery(
+ "initial_a", external_searches=(fallback,))):
+ result = self._post("/api/follow/resolve", {"lines": ["initial_a"]})
+ row = result["results"][0]
+ self.assertEqual(row["candidates"], [])
+ self.assertEqual(row["external_searches"], [{
+ "provider": "f95zone", "provider_label": "F95zone",
+ "label": "用 Google 继续查找 F95zone",
+ "query": "initial_a f95zone",
+ "url": "https://www.google.com/search?q=initial_a+f95zone",
+ "evidence": "F95zone 站内索引未命中,请核对搜索结果里的真实线程链接",
+ }])
+ self.assertEqual(self._get()["sources"], [], "查找入口不能自动登记来源")
+
def test_a_thread_link_is_registered_with_release_semantics(self):
self._add("https://f95zone.to/threads/"
"lazy-procrastinator-collection-2026-06-28-lazyprocrast.50685/")
@@ -733,10 +755,16 @@ class FollowWebSourceTests(unittest.TestCase):
self.assertNotIn('</section>\n <div id="followPicks">', manage)
self.assertPageContains(
'<div class="fpicks"><div class="fsechead"><h3>查找结果</h3>')
- self.assertPageContains('<p class="fpickempty">没有查到来源</p>')
+ self.assertPageContains('<p class="fpickempty">站内没有查到来源</p>')
self.assertNotIn(".fpicks h3{", page,
"查找结果不应另起一套标题字号")
+ def test_f95_misses_offer_a_clickable_google_query(self):
+ self.assertPageContains("row.external_searches||[]")
+ self.assertPageContains('class="fpicksearch" href="${esc(search.url)}"')
+ self.assertPageContains('target="_blank" rel="noreferrer noopener"')
+ self.assertPageContains("${esc(search.query)}")
+
def test_follow_author_groups_use_multiple_columns_and_link_to_the_original_page(self):
self.assertPageContains('class="frows fsources"')
grid = self.page[self.page.index(".fsources{"):]
diff --git a/web/app.css b/web/app.css
index 763091275..cc0508c13 100644
--- a/web/app.css
+++ b/web/app.css
@@ -1438,6 +1438,12 @@ details.fcred{display:block}
.fpickitem span{min-width:0;overflow-wrap:anywhere}
.fpickitem b{margin-right:6px}
.fpickitem i{display:block;font-style:normal;color:var(--muted);font-size:var(--fs-xs);margin-top:1px}
+.fpicksearch{display:grid;grid-template-columns:auto minmax(0,1fr);gap:2px 9px;
+ align-items:baseline;margin:6px 0;padding:8px 10px;border:1px dashed var(--border-15);
+ border-radius:8px;color:var(--ink-2);text-decoration:none;font-size:var(--fs-xs)}
+.fpicksearch:hover{border-color:var(--tungsten);color:var(--ink)}
+.fpicksearch span{min-width:0;overflow-wrap:anywhere;color:var(--tungsten)}
+.fpicksearch i{grid-column:1/-1;font-style:normal;color:var(--muted)}
.fpickfail{color:var(--drop)!important}
.fpickactions{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px}
.fpickactions button{border:1px solid var(--border-15);border-radius:8px;background:transparent;color:var(--ink-2);padding:6px 14px;font-size:var(--fs-xs);cursor:pointer}
diff --git a/web/app.js b/web/app.js
index 38ef3da11..e1f02a240 100644
--- a/web/app.js
+++ b/web/app.js
@@ -1945,8 +1945,13 @@ function renderFollowPicks(results){
data-label="${esc(c.label)}"${c.known?' disabled':' checked'}>
<span><b>${esc(c.provider_label)}</b> ${esc(c.label)}
<i>${esc(c.known?'已经在追':c.evidence)}</i></span></label>`).join('');
+ const searches=(row.external_searches||[]).map(search=>
+ `<a class="fpicksearch" href="${esc(search.url)}" target="_blank" rel="noreferrer noopener">
+ <b>${esc(search.label)}</b><span>${esc(search.query)}</span>
+ <i>${esc(search.evidence)}</i></a>`).join('');
return `<div class="fpick"><b>${esc(row.line)}</b>
- ${items||'<p class="fpickempty">没有查到来源</p>'}
+ ${items||'<p class="fpickempty">站内没有查到来源</p>'}
+ ${searches}
${failures.length?`<p class="fpickfail">${failures.map(([k,v])=>
`${esc(k)}:${esc(v)}`).join(';')}</p>`:''}</div>`;
}).join('');