Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(follow): 发现阶段把手柄对应的非数字创作者 id 也按站内 id 精确命中

longmeidao352fc5a6bd4d
diff --git a/src/peach/follow_discovery.py b/src/peach/follow_discovery.py
index 3f755b8c0..0f8ad20a0 100644
--- a/src/peach/follow_discovery.py
+++ b/src/peach/follow_discovery.py
@@ -150,8 +150,9 @@ class CreatorIndex:
def _kemono_candidates(provider: str, term: str, index: CreatorIndex) -> list[Candidate]:
rows = index.load(provider)
folded = term.casefold()
- numeric = bool(_NUMERIC_RE.match(term))
- exact_id = [row for row in rows if numeric and row["id"] == term]
+ # id 的形状跟服务走:fanbox 的 id 是数字,patreon、switch 这些直接拿创作者
+ # 手柄当 id。精确比对把两种都收进来,只认数字会把手柄当 id 的来源整个排除。
+ exact_id = [row for row in rows if row["id"] == term]
by_name = [row for row in rows if row["name"].casefold() == folded]
partial = [row for row in rows
if folded in row["name"].casefold() and row not in by_name]
diff --git a/tests/test_follow_discovery.py b/tests/test_follow_discovery.py
index 5b8664d23..7ddea5a8e 100644
--- a/tests/test_follow_discovery.py
+++ b/tests/test_follow_discovery.py
@@ -18,6 +18,7 @@ CREATORS = json.dumps([
{"id": "30917150", "name": "LazyProcrastinator", "service": "fanbox"},
{"id": "109730638", "name": "EcchiWaffle", "service": "patreon"},
{"id": "25775753", "name": "LazyMazer", "service": "patreon"},
+ {"id": "suzutaro3d", "name": "鈴太郎3D", "service": "patreon"},
]).encode()
F95_HIT = json.dumps({"status": "ok", "msg": {"data": [
@@ -116,8 +117,8 @@ class CreatorIndexTests(_DiscoveryCase):
def test_the_index_is_downloaded_once_and_then_cached(self):
calls = []
index = self._index(calls)
- self.assertEqual(len(index.load("kemono")), 3)
- self.assertEqual(len(index.load("kemono")), 3)
+ self.assertEqual(len(index.load("kemono")), 4)
+ self.assertEqual(len(index.load("kemono")), 4)
self.assertEqual(len(calls), 1, "第二次不该再下载")
def test_a_stale_cache_is_refreshed(self):
@@ -177,6 +178,14 @@ class DiscoverTests(_DiscoveryCase):
# 纯数字不去 rule34video / rule34.xxx 碰运气——那两个都是按名字/标签查的。
self.assertFalse(any("/models/" in url for url in calls))
+ def test_a_handle_may_be_the_creator_id_itself(self):
+ # patreon 归档的 id 就是创作者手柄:`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",))