Peach: Local-first video metadata scraper and media manager.
fix(follow): 查找进度按计划的来源数走满,手柄型 id 不分大小写
longmeidaoc288d6f76d01
diff --git a/src/peach/follow_discovery.py b/src/peach/follow_discovery.pyindex ee95de945..caaedc2c1 100644--- a/src/peach/follow_discovery.py+++ b/src/peach/follow_discovery.py@@ -152,7 +152,9 @@ def _kemono_candidates(provider: str, term: str, index: CreatorIndex) -> list[Cafolded = term.casefold()# id 的形状跟服务走:fanbox 的 id 是数字,patreon、switch 这些直接拿创作者# 手柄当 id。精确比对把两种都收进来,只认数字会把手柄当 id 的来源整个排除。- exact_id = [row for row in rows if row["id"] == term]+ # 手柄的大小写只是显示形态,`SuzuTaro3D` 和 `suzutaro3d` 是同一个创作者,+ # 所以按 casefold 比;数字 id 过一遍 casefold 也还是它自己。+ exact_id = [row for row in rows if row["id"].casefold() == folded]by_name = [row for row in rows if row["name"].casefold() == folded]partial = [row for row in rowsif folded in row["name"].casefold() and row not in by_name]diff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex 0ff510c41..0339d4ee4 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -1107,24 +1107,21 @@ def w_follow_resolve(contract, body, *, progress=None) -> dict:return note- results = []- for index, line in enumerate(lines):+ def resolve_line(index: int, line: str) -> dict:try:parsed = parse_source_url(line)except FollowSourceError as url_error:if "://" in line or "/" in line:# 看着就是链接,那就照链接的错误报,不要再拿去当名字查一遍。- results.append({"line": line, "kind": "error", "error": str(url_error)})- continue+ return {"line": line, "kind": "error", "error": str(url_error)}try:found = discover(line, secrets_root=contract.follow_secrets_root,shared_root=contract.follow_shared_root,state_root=contract.follow_state_root,on_progress=source_progress(index))except (FollowSourceError, CredentialError) as term_error:- results.append({"line": line, "kind": "error", "error": str(term_error)})- continue- results.append({+ return {"line": line, "kind": "error", "error": str(term_error)}+ return {"line": line, "kind": "term","candidates": [{**_candidate_payload(c, author=line),"known": (c.provider, canonical_source_ref(@@ -1133,14 +1130,22 @@ def w_follow_resolve(contract, body, *, progress=None) -> dict:"failures": found.failures,"external_searches": [_external_search_payload(search)for search in found.external_searches],- })- done_units += len(discovery_plan(line))- continue- results.append({"line": line, "kind": "url",- "candidates": [{**_candidate_payload(parsed),- "known": (parsed.provider, canonical_source_ref(- parsed.provider, parsed.ref)) in known}]})- done_units += 1+ }+ return {"line": line, "kind": "url",+ "candidates": [{**_candidate_payload(parsed),+ "known": (parsed.provider, canonical_source_ref(+ parsed.provider, parsed.ref)) in known}]}++ results = []+ for index, line in enumerate(lines):+ # 分母是 plan_units 算出来的,分子就照同一把尺子加:一行查失败也占掉了它那+ # 几个来源,不加进去的话后面每一行都低这么多,环最后停在半路。+ results.append(resolve_line(index, line))+ done_units += plan_units(line)+ if progress is not None and total_units:+ # 每个来源是开查前报一次自己的序号,最后一个报的是 total-1;收尾这一下才走满。+ progress(checked=total_units, total=total_units,+ message=f"查找关注来源:{total_units} 个来源已查完")return {"ok": True, "results": results}diff --git a/tests/test_follow_discovery.py b/tests/test_follow_discovery.pyindex cf1c299aa..b39b95f65 100644--- a/tests/test_follow_discovery.py+++ b/tests/test_follow_discovery.py@@ -210,6 +210,14 @@ class DiscoverTests(_DiscoveryCase):["patreon/suzutaro3d"])self.assertEqual(found.candidates[0].evidence, "站内 id 精确匹配")+ def test_a_handle_id_matches_whatever_case_it_was_copied_in(self):+ # 手柄的大小写只是显示形态:从主页标题复制来的 `SuzuTaro3D` 和索引里的+ # `suzutaro3d` 是同一个创作者。按名字比对已经这么判,按 id 也要一样。+ found = self._discover("SuzuTaro3D", self.ROUTES, providers=("kemono",))+ self.assertEqual([c.ref for c in found.candidates],+ ["patreon/suzutaro3d"])+ self.assertEqual(found.candidates[0].evidence, "站内 id 精确匹配")+def test_a_numeric_term_probes_the_thread_id(self):routes = {**self.ROUTES, "f95zone.to/threads/50685/": HttpResponse(200, {}, b"<html/>")}found = self._discover("50685", routes, providers=("f95zone",))diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 1da1f67af..d92c40505 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -1287,11 +1287,32 @@ class FollowSourceAddTests(FollowContractTests):web_follow.w_follow_resolve(self.contract, {"lines": ["suzutaro3d", "https://kemono.cr/fanbox/user/30917150"],}, progress=lambda **fields: ticks.append(fields))- self.assertEqual([tick["checked"] for tick in ticks], [0, 7])+ self.assertEqual([tick["checked"] for tick in ticks], [0, 7, 9])self.assertTrue(all(tick["total"] == 9 for tick in ticks))self.assertIn("Kemono", ticks[0]["message"])self.assertIn("F95zone", ticks[1]["message"])+ def test_a_line_that_fails_still_advances_the_ring_by_its_own_sources(self):+ """来源是开查前报一次,报的是 `position`,所以查完最后一个来源分子停在 total-1;+ 查失败的行一个来源都不报。两样都不补,环就走不满,后面的行还一路偏低。+ """+ ticks = []++ def fake_discover(line, **kwargs):+ if line == "suzutaro3d":+ raise FollowSourceError("索引下不来")+ kwargs["on_progress"]("kemono", 0, 8)+ return Discovery(line, external_searches=())++ with mock.patch.object(web_follow, "discover", side_effect=fake_discover):+ result = web_follow.w_follow_resolve(self.contract, {+ "lines": ["suzutaro3d", "lazyprocrastinator"],+ }, progress=lambda **fields: ticks.append(fields))+ self.assertEqual(result["results"][0]["kind"], "error")+ # 两行各 8 个来源:第二行开查时分子已经是第一行的 8,收尾走满 16。+ self.assertEqual([tick["checked"] for tick in ticks], [8, 16])+ self.assertTrue(all(tick["total"] == 16 for tick in ticks))+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/")