Peach: Local-first video metadata scraper and media manager.
fix: 用站点自报的出处做跨站分组,别再拿哈希文件名当标题
Peach local maintenance4f962c5e633d
diff --git a/docs/STATUS.md b/docs/STATUS.mdindex 30adf485c..dc88b5e9b 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -261,8 +261,10 @@(`peach migrate upgrade --yes`,无 `--yes` 会拒绝改动真实 ledger),Mac 之后走「同步 Ledger」拉取;Mac 只作 reader 浏览时也可以本地先 apply,它换来的只是`/follow` 页面能渲染——写入端点在 reader 上照旧 409;- (b) 用户提供 rule34.xxx 的 user_id + api_key,把 rule34.xxx 这一路打通并核对- `parent_id` 的真实响应字段(当前实现按公开文档写成,**未取得**真实响应验证);+ (b) ~~核对 rule34.xxx 的真实响应~~ **2026-08-26 已完成**:用账号 key 实测,字段名与+ 文档一致,但内容推翻了两个按文档写下的判断——`image` 15/15 是哈希、`parent_id` 15/15+ 是 0,而 `source` 13/15 有值。分组键因此改为优先取 `source` 归一出的跨站键+ (`fanbox:12304831`,与 kemono 的 post id 同一命名空间),详见 ADR-0019;(c) 再接 APScheduler 做定时轮询。媒体下载能力已在设计里留位(`media_url` + `media_needs_credential`),但没有实现下载器,也没有定流量与磁盘预算。lazyp 的四个来源已在临时库跑通端到端:kemono 50 条、rule34video 24 条、f95 9 条动态,diff --git a/docs/adr/0019-site-follow-connectors-and-variant-grouping.md b/docs/adr/0019-site-follow-connectors-and-variant-grouping.mdindex 44a46a55b..cee06e89b 100644--- a/docs/adr/0019-site-follow-connectors-and-variant-grouping.md+++ b/docs/adr/0019-site-follow-connectors-and-variant-grouping.md@@ -44,8 +44,13 @@ rule34.xxx 上。不区分这三种关系,界面就只是一堆重复条目。- `semantics` 区分两类来源:`work`(rule34、kemono——每条是独立作品,`v2` 判为 alt)与 `release`(f95、simpcity——每条是同一作品的一次发布,版本从标题摘出并排除在分组键外)。-- 来源自己声明的关系优先于标题判据:booru 的 `parent_id` 用并查集把父子帖连成一个分量,- 统一取分量内最小的 `release_key`,**不会被标题判据拆散**。+- 来源自己声明的关系优先于标题判据。`group_hint` 是一个**全局字符串**,同一个值的条目+ 归为一组,**跨站点成立**:rule34.xxx 从 `source` 归一出的 `fanbox:12304831`,与 kemono+ 上同一帖子的键完全相同,同一个作品在两个站上因此精确合并,不必靠标题去猜。booru 的+ 父子帖也走这条——父帖用自己的 id、子帖用 `parent_id`,拼出来是同一个键。+- **booru 没有标题,标签拼出来的标签不是名字。** 这类候选带 `title_is_name=False`,+ `release_key` 附上 `external_id` 使其各自成组,只允许 `group_hint` 合并——否则同一作者+ 标签相似的两个作品会被并掉。- 判据保守,宁可少合并:括号只在命中已知标记、创作者别名或版本模式时才剥离;标题末尾的裸数字算作品序号而不是版本;`work` 语义下同一来源出现两个都没有变体标记的 main 就整组按 `external_id` 拆开。@@ -73,10 +78,29 @@ rule34.xxx 上。不区分这三种关系,界面就只是一堆重复条目。| --- | --- | --- | --- || kemono.cr / coomer.st / pawchive.pw | `/api/v1/{service}/user/{id}/posts` | 无 | 默认 `Accept` 回 403,响应体写明抓取应带 `Accept: text/css`;kemono 回 `{"posts": […]}`,pawchive 回裸列表 || rule34video.com | `/models/{slug}/` | 无 | KVS 引擎无公开 API;`.time` 是时长、`.added` 是相对提交时间、`[data-preview]` 是预览片 |-| rule34.xxx | `https://api.rule34.xxx/index.php?page=dapi&s=post&q=index` | user_id + api_key | 网页版挂 Turnstile;无 key 时 API 返回 `Missing authentication`;booru 帖子无标题,`parent_id` 是站点维护的变体关系 |+| rule34.xxx | `https://api.rule34.xxx/index.php?page=dapi&s=post&q=index` | user_id + api_key | 网页版挂 Turnstile;无 key 时 API 返回 `Missing authentication`。**2026-08-26 用真实 key 复核**(见下) || f95zone.to | `/threads/{id}/latest` + `latest_alpha/latest_data.php` | 发现不需要,取媒体需要 | 主贴版本号滞后于回复;`index.rss` 返回「无法以该格式呈现」;`h1.p-title-value` 去掉 `.label` 才是线程标题 || simpcity.cr | — | — | DDoS-Guard 浏览器质询,**未取得**可用入口 |+### rule34.xxx 的真实响应(2026-08-26,用账号 API key 实测)++这一段推翻了先前按公开文档写下的两个判断。文档只列了参数,没列响应,当时标为**未取得**,+拿到 key 之后逐条核对,字段名全部对上(顶层是裸列表,不是 `{"post": […]}`),但内容不是+文档能看出来的:++| 实测 | 原实现的错误 |+| --- | --- |+| `image` **15/15 都是 32 位十六进制哈希** | 拿文件名当标题 → 标题是乱码,且每条 `release_key` 唯一,永远分不了组 |+| `parent_id` **15/15 都是 0** | 指望它承担变体分组 → 这个创作者下拿不到任何信号 |+| `source` **13/15 有值**,其中 6 条指向同一个 fanbox 帖 | 只存进 `extra` 没有使用 |++因此改为:哈希文件名退回用标签拼可读标签并声明 `title_is_name=False`;分组键优先取+`source` 归一后的跨站键,取不到才退回站内父帖链。同一个 fanbox 帖在 `source` 里有两种+写法(`lazyprocrast.fanbox.cc/posts/12304831` 与 `www.fanbox.cc/@lazyprocrast/posts/12304831`),+必须归一到同一个键;而那串数字正是 kemono 上同一帖子的 post id,两侧因此落在同一个+命名空间里。实测 12 条候选中 6 条收敛成 `fanbox:12304831`——一个 fanbox 帖在 rule34.xxx+上被切成了 6 段。+lazyp 的跨站身份链已核实:ledger `entity` 6405 `LazyProcrast` ← pixiv 用户 30917150← kemono `fanbox/30917150` `LazyProcrastinator`;rule34video `/models/lazyprocrastinator/`;f95zone 线程 50685,`creator` 字段写作 `LazyProcrastinator/LazyProcrast`。diff --git a/src/peach/follow_sources.py b/src/peach/follow_sources.pyindex c826bd5f1..29f6e7995 100644--- a/src/peach/follow_sources.py+++ b/src/peach/follow_sources.py@@ -45,8 +45,12 @@ class FollowCandidate:duration: float | None = Noneauthor: str | None = Nonesummary: str | None = None- #: 来源自带的分组标识(如 booru 的 `parent_id`)。有它就不必靠标题猜同一作品的变体。+ #: 来源自带的分组标识。可能是站内的父帖,也可能是归一化后的跨站出处键+ #: (`fanbox:12304831` 这种)。有它就不必靠标题猜同一作品的变体。group_hint: str | None = None+ #: 标题是不是一个真正的名字。booru 没有标题,只能拿标签凑一个可读标签——+ #: 那种「标题」不能参与按标题分组,否则同一作者的两个作品会因标签相似被并掉。+ title_is_name: bool = Trueextra: Mapping[str, object] = field(default_factory=dict)@@ -135,6 +139,59 @@ def _duration_seconds(text: str | None) -> float | None:return float(int(hours or 0) * 3600 + int(minutes) * 60 + int(seconds))+#: 站点自报出处时能认出来的原始平台。键是主机名后缀,值是分组键的前缀。+#: 这些前缀是**跨站**的:rule34.xxx 的 `source` 指向某个 fanbox 帖时,产生的键和+#: kemono 上同一个帖子的键完全相同,跨站重复因此不必靠标题去猜。+_ORIGIN_HOSTS: tuple[tuple[str, str], ...] = (+ ("fanbox.cc", "fanbox"),+ ("patreon.com", "patreon"),+ ("pixiv.net", "pixiv"),+ ("x.com", "x"),+ ("twitter.com", "x"),+ ("subscribestar.adult", "subscribestar"),+ ("gumroad.com", "gumroad"),+)++_ORIGIN_ID_RE = re.compile(r"/(?:posts?|status(?:es)?|artworks)/(\d{4,})")+++def origin_group_key(source_url: str | None) -> str | None:+ """把站点自报的出处 URL 归一成跨站可比的分组键。++ 实测(2026-08-25)同一个 fanbox 帖在 rule34.xxx 上有两种写法——+ `lazyprocrast.fanbox.cc/posts/12304831` 和+ `www.fanbox.cc/@lazyprocrast/posts/12304831`——必须归一到同一个键,+ 而那串数字正是 kemono 上同一帖子的 post id。+ """+ if not source_url or not isinstance(source_url, str):+ return None+ try:+ parsed = urllib.parse.urlsplit(source_url.strip())+ except ValueError:+ return None+ host = (parsed.hostname or "").lower()+ if not host:+ return None+ platform = next(+ (name for suffix, name in _ORIGIN_HOSTS+ if host == suffix or host.endswith("." + suffix)),+ None,+ )+ if platform is None:+ return None+ matched = _ORIGIN_ID_RE.search(parsed.path)+ return f"{platform}:{matched.group(1)}" if matched else None+++def _is_opaque_filename(stem: str) -> bool:+ """文件名是不是哈希。++ rule34.xxx 实测 15/15 的 `image` 都是 32 位十六进制哈希——拿它当标题既不可读,+ 又会让每条帖子各自成组,跨站去重永远不可能命中。+ """+ return bool(re.fullmatch(r"[0-9a-f]{16,}", stem.strip().lower()))++class _BaseConnector:provider = ""semantics = "work"@@ -265,6 +322,9 @@ class KemonoConnector(_BaseConnector):published_at=_iso_from_text(post.get("published")),author=None,summary=_plain_text(post.get("substring")),+ # kemono 系的 post id 就是原平台的 post id,所以这个键和别的站点从+ # `source` 归一出来的键是同一个命名空间——跨站重复因此能精确命中。+ group_hint=f"{service}:{post_id}" if post_id else None,extra={"service": service, "user": user,"edited": post.get("edited"),"attachment_count": len(attachments)},@@ -399,15 +459,35 @@ class Rule34XxxConnector(_BaseConnector):)return SourceFetch(candidates=candidates, raw_body=response.body, **common)+ #: 拼可读标签时跳过的词:作者手柄、媒体类型和评级,留下的才是内容。+ _TITLE_TAG_STOPWORDS = frozenset({+ "video", "sound", "animated", "mp4", "webm", "3d", "hd", "60fps",+ "tagme", "highres", "absurdres",+ })+def _candidate(self, post: dict, tag: str) -> FollowCandidate:post_id = str(post.get("id") or "")- # booru 帖子没有标题。用原始文件名当标题,跨站比对时它比标签串靠谱得多;- # 没有文件名就退回标签串,并在 extra 里留下判据。+ tags = str(post.get("tags") or "")image = str(post.get("image") or "")stem = re.sub(r"\.[a-z0-9]{2,5}$", "", image, flags=re.IGNORECASE)- tags = str(post.get("tags") or "")- title = _plain_text(stem.replace("_", " ")) or _plain_text(tags) or f"post {post_id}"+ # booru 帖子没有标题。实测 rule34.xxx 的 `image` 全是 32 位十六进制哈希,+ # 拿它当标题既不可读,又会让每条帖子各自成组。哈希就退回标签拼一个可读标签,+ # 并声明这不是名字——标签相似的两个作品不能因此被并成一个。+ opaque = _is_opaque_filename(stem)+ if stem and not opaque:+ title, title_from, title_is_name = (+ _plain_text(stem.replace("_", " ")) or f"post {post_id}", "image", True)+ else:+ title = self._tag_label(tags, tag) or f"post {post_id}"+ title_from, title_is_name = "tags", False+ # 出处比站内父帖强得多:实测 15 条 parent_id 全是 0,而 13 条有 source,+ # 其中 4 条指向同一个 fanbox 帖——那才是真正的同组信号,而且跨站可比。+ source = post.get("source")parent = post.get("parent_id")+ hint = origin_group_key(str(source) if source else None)+ if hint is None:+ anchor = parent if parent not in (None, 0, "0", "") else post_id+ hint = f"{self.provider}:post:{anchor}" if anchor else Nonereturn FollowCandidate(provider=self.provider,external_id=post_id or _stable_id(image, tags),@@ -417,11 +497,20 @@ class Rule34XxxConnector(_BaseConnector):media_url=str(post.get("file_url")) if post.get("file_url") else None,thumb_url=str(post.get("preview_url")) if post.get("preview_url") else None,published_at=_iso_from_epoch(post.get("change")),- group_hint=str(parent) if parent not in (None, 0, "0", "") else None,+ group_hint=hint,+ title_is_name=title_is_name,extra={"tag": tag, "tags": tags, "score": post.get("score"),- "source": post.get("source"), "title_from": "image" if stem else "tags"},+ "source": source, "title_from": title_from},)+ @classmethod+ def _tag_label(cls, tags: str, subject: str) -> str:+ """用标签拼一个可读标签。只作展示,不参与按标题分组。"""+ skip = cls._TITLE_TAG_STOPWORDS | {subject.strip().lower()}+ words = [word.replace("_", " ") for word in tags.split()+ if word.lower() not in skip and not word.startswith("rating:")]+ return " · ".join(words[:5])+class F95ZoneConnector(_BaseConnector):"""f95zone.to 的线程追更。diff --git a/src/peach/follow_store.py b/src/peach/follow_store.pyindex 96ae50900..71665008e 100644--- a/src/peach/follow_store.py+++ b/src/peach/follow_store.py@@ -171,6 +171,11 @@ class FollowStore:for candidate in fetch.candidates:verdict = classify(candidate.title, creator_aliases=creator_aliases,version=candidate.version, semantics=fetch.semantics)+ release_key = verdict.release_key+ if not candidate.title_is_name:+ # booru 的「标题」是标签拼出来的,不是名字。让它各自成组,只靠+ # `group_hint` 合并;否则同一作者标签相似的两个作品会被并掉。+ release_key = f"{release_key}\u0000{candidate.external_id}"precision = str(candidate.extra.get("published_precision") or("exact" if candidate.published_at else "unknown"))if precision not in ("exact", "approximate", "unknown"):@@ -178,7 +183,7 @@ class FollowStore:values = (source_id, candidate.external_id, candidate.title, candidate.url,candidate.media_url, candidate.thumb_url, candidate.published_at,- precision, verdict.version, candidate.duration, verdict.release_key,+ precision, verdict.version, candidate.duration, release_key,verdict.variant_kind, verdict.variant_label, candidate.group_hint,evidence,# author 单独并进来:连接器把它放在 DTO 的具名字段上,而不是 extra 里,@@ -438,15 +443,20 @@ def _align_by_group_hint(items: tuple[FollowItemRow, ...]) -> tuple[FollowItemRodef _hint_linked(items: tuple[FollowItemRow, ...]) -> frozenset[tuple[str, str]]:- """来源已经声明为同一作品的条目:父帖与它在本批里出现的全部子帖。"""- present = {(item.provider, item.external_id) for item in items}- linked: set[tuple[str, str]] = set()+ """来源已经声明为同组的条目。++ `group_hint` 是一个全局字符串(`fanbox:12304831`、`rule34xxx:post:998877`),+ 只要两条以上共用它,来源就已经把它们认成同一个作品了。+ """+ counts: dict[str, int] = {}for item in items:- parent = (item.provider, item.group_hint or "")- if item.group_hint and parent in present:- linked.add(parent)- linked.add((item.provider, item.external_id))- return frozenset(linked)+ if item.group_hint:+ counts[item.group_hint] = counts.get(item.group_hint, 0) + 1+ shared = {hint for hint, count in counts.items() if count > 1}+ return frozenset(+ (item.provider, item.external_id) for item in items+ if item.group_hint in shared+ )def _split_ambiguous_works(items: tuple[FollowItemRow, ...],@@ -482,3 +492,30 @@ def _split_ambiguous_works(items: tuple[FollowItemRow, ...],and (item.provider, item.external_id) not in linked else itemfor item in items)+++def _align_by_group_hint(items: tuple[FollowItemRow, ...]) -> tuple[FollowItemRow, ...]:+ """让来源声明为同组的条目共用一个 `release_key`。++ 判据是「`group_hint` 字符串相同」,**跨站点成立**:rule34.xxx 从 `source` 归一出的+ `fanbox:12304831` 与 kemono 上同一帖子的键完全相同,同一个作品在两个站上因此+ 精确合并,不必靠标题去猜。booru 的父子帖也走这条——父帖用自己的 id、子帖用+ `parent_id`,拼出来是同一个键。++ 组键取组内最小的 `release_key`,保证结果与条目顺序无关。+ """+ keys: dict[str, str] = {}+ for item in items:+ if not item.group_hint or not item.release_key:+ continue+ current = keys.get(item.group_hint)+ if current is None or item.release_key < current:+ keys[item.group_hint] = item.release_key+ if not keys:+ return items+ return tuple(+ FollowItemRow(**{**item.__dict__, "release_key": keys[item.group_hint]})+ if item.group_hint and item.group_hint in keys+ and keys[item.group_hint] != item.release_key else item+ for item in items+ )diff --git a/tests/test_follow_sources.py b/tests/test_follow_sources.pyindex 5ef28e0db..8a49d3591 100644--- a/tests/test_follow_sources.py+++ b/tests/test_follow_sources.py@@ -17,6 +17,7 @@ from peach.follow_secrets import Credential, CredentialError, CredentialStorefrom peach.follow_sources import (USER_AGENT, F95ZoneConnector, KemonoConnector, Rule34VideoConnector,Rule34XxxConnector, SimpCityConnector, build_connector, _iso_from_relative,+ origin_group_key,)from peach.http import HttpResponse@@ -75,15 +76,24 @@ Lazy Procrastinator Collection [2026-06-28] [LazyProcrastinator/LazyProcrast]</h</article></body></html>"""+# 形状取自 2026-08-25 对 api.rule34.xxx 的实测响应:顶层是裸列表,`image` 是 32 位+# 十六进制哈希(15/15),`parent_id` 全是 0(15/15),`source` 13/15 有值。RULE34XXX_JSON = json.dumps([- {"id": 9988776, "image": "fiona_paizuri_nude.mp4", "parent_id": 9988770,- "tags": "lazyprocrastinator fiona nude", "change": 1787000000,- "file_url": "https://api-cdn.rule34.xxx/images/1/abc.mp4",- "preview_url": "https://api-cdn.rule34.xxx/thumbnails/1/abc.jpg",- "score": 42, "source": "https://rule34video.com/video/4542721/"},- {"id": 9988770, "image": "fiona_paizuri.mp4", "parent_id": 0,- "tags": "lazyprocrastinator fiona", "change": 1786990000,- "file_url": "https://api-cdn.rule34.xxx/images/1/def.mp4", "score": 40},+ {"id": 18534395, "image": "3df1cbc67e072d6144588d6c80e490ea.mp4", "parent_id": 0,+ "tags": "lazyprocrastinator fiona blush video sound", "change": 1787445373,+ "file_url": "https://api-cdn-mp4.rule34.xxx/images/1232/3df1.mp4",+ "preview_url": "https://api-cdn.rule34.xxx/thumbnails/1232/t_3df1.jpg",+ "score": 72, "source": "https://lazyprocrast.fanbox.cc/posts/12304831"},+ {"id": 18534396, "image": "3bda1572c365b223d8b287c538a38956.mp4", "parent_id": 0,+ "tags": "lazyprocrastinator fiona video", "change": 1787445300,+ "file_url": "https://api-cdn-mp4.rule34.xxx/images/1232/3bda.mp4",+ "score": 70, "source": "https://www.fanbox.cc/@lazyprocrast/posts/12304831"},+ {"id": 18534397, "image": "93eaeadff5effabe078c738aab85b3bc.mp4", "parent_id": 0,+ "tags": "lazyprocrastinator sayuri video", "change": 1787445200,+ "file_url": "https://api-cdn-mp4.rule34.xxx/images/1232/93ea.mp4", "score": 12},+ {"id": 18534398, "image": "fiona_paizuri_nude.mp4", "parent_id": 18534397,+ "tags": "lazyprocrastinator fiona nude", "change": 1787445100,+ "file_url": "https://api-cdn-mp4.rule34.xxx/images/1232/fp.mp4", "score": 9},]).encode()@@ -108,6 +118,8 @@ class KemonoConnectorTests(unittest.TestCase):"https://kemono.cr/fanbox/user/30917150/post/11406814")self.assertEqual(first.media_url, "https://kemono.cr/1c/fa/1cfae7.png")self.assertEqual(first.extra["attachment_count"], 1)+ # post id 就是原平台的 post id,和别的站点从 source 归一出的键同一个命名空间。+ self.assertEqual(first.group_hint, "fanbox:11406814")def test_pawchive_returns_a_bare_list_and_uses_its_own_host(self):seen = []@@ -278,16 +290,39 @@ class Rule34XxxConnectorTests(unittest.TestCase):connector.fetch("lazyprocrastinator")self.assertEqual(seen, [])- def test_parent_id_becomes_the_group_hint(self):+ def test_the_declared_origin_becomes_a_cross_site_group_key(self):+ # 同一个 fanbox 帖在 source 里有两种写法,必须归一到同一个键——而那串数字+ # 正是 kemono 上同一帖子的 post id,跨站重复因此能精确命中。candidates = self._connector().fetch("lazyprocrastinator").candidates- self.assertEqual(candidates[0].group_hint, "9988770")- self.assertIsNone(candidates[1].group_hint)+ self.assertEqual(candidates[0].group_hint, "fanbox:12304831")+ self.assertEqual(candidates[1].group_hint, "fanbox:12304831")- def test_filename_is_preferred_over_the_tag_string_as_a_title(self):+ def test_posts_without_an_origin_fall_back_to_the_booru_parent_chain(self):+ candidates = self._connector().fetch("lazyprocrastinator").candidates+ # 父帖用自己的 id,子帖用 parent_id,拼出来是同一个键。+ self.assertEqual(candidates[2].group_hint, "rule34xxx:post:18534397")+ self.assertEqual(candidates[3].group_hint, "rule34xxx:post:18534397")++ def test_a_hash_filename_is_not_used_as_a_title(self):+ # 实测 15/15 的 image 都是哈希。拿它当标题既不可读,又会让每条帖子各自成组。first = self._connector().fetch("lazyprocrastinator").candidates[0]- self.assertEqual(first.title, "fiona paizuri nude")- self.assertEqual(first.extra["title_from"], "image")- self.assertEqual(first.published_at, "2026-08-17T20:53:20Z")+ self.assertNotIn("3df1cbc6", first.title)+ self.assertEqual(first.extra["title_from"], "tags")+ self.assertFalse(first.title_is_name)+ self.assertIn("fiona", first.title)+ self.assertEqual(first.published_at, "2026-08-23T00:36:13Z")++ def test_a_readable_filename_is_still_preferred_and_counts_as_a_name(self):+ last = self._connector().fetch("lazyprocrastinator").candidates[3]+ self.assertEqual(last.title, "fiona paizuri nude")+ self.assertEqual(last.extra["title_from"], "image")+ self.assertTrue(last.title_is_name)++ def test_the_tag_label_drops_the_subject_and_media_words(self):+ first = self._connector().fetch("lazyprocrastinator").candidates[0]+ for noise in ("lazyprocrastinator", "video", "sound"):+ self.assertNotIn(noise, first.title)+def test_authentication_rejection_is_reported_as_a_credential_error(self):connector = self._connector(@@ -303,6 +338,25 @@ class SimpCityConnectorTests(unittest.TestCase):self.assertIn("DDoS-Guard", str(caught.exception))+class OriginGroupKeyTests(unittest.TestCase):+ def test_the_two_fanbox_url_shapes_normalize_together(self):+ self.assertEqual(origin_group_key("https://lazyprocrast.fanbox.cc/posts/12304831"),+ origin_group_key("https://www.fanbox.cc/@lazyprocrast/posts/12304831"))++ def test_known_platforms_get_their_own_prefix(self):+ self.assertEqual(origin_group_key("https://x.com/a/status/20861277667730761"),+ "x:20861277667730761")+ self.assertEqual(origin_group_key("https://twitter.com/a/status/12345678"),+ "x:12345678")+ self.assertEqual(origin_group_key("https://www.patreon.com/posts/98765432"),+ "patreon:98765432")++ def test_unknown_hosts_and_junk_yield_nothing(self):+ for value in ("https://rule34video.com/video/4542721/", "https://fanbox.cc/",+ "not a url", "", None, 12345):+ self.assertIsNone(origin_group_key(value))++class BuildConnectorTests(unittest.TestCase):def test_registry_maps_the_three_kemono_hosts_to_distinct_providers(self):for provider in ("kemono", "coomer", "pawchive"):diff --git a/tests/test_follow_store.py b/tests/test_follow_store.pyindex 0bd5d6974..720ff6cae 100644--- a/tests/test_follow_store.py+++ b/tests/test_follow_store.py@@ -203,10 +203,12 @@ class GroupingTests(_StoreCase):]), moment=MOMENT)self.store.record(booru, _fetch([FollowCandidate(provider="rule34xxx", external_id="9988770",- title="fiona paizuri"),+ title="fiona paizuri",+ group_hint="rule34xxx:post:9988770"),FollowCandidate(provider="rule34xxx", external_id="9988776",title="totally different filename",- group_hint="9988770"),+ title_is_name=False,+ group_hint="rule34xxx:post:9988770"),], provider="rule34xxx"), moment=MOMENT)def test_alt_folds_under_its_main_and_other_works_stay_apart(self):@@ -226,12 +228,41 @@ class GroupingTests(_StoreCase):self.assertTrue(all(d.provider == "rule34xxx" for d in paizuri.duplicates))def test_group_hint_beats_an_unrelated_title(self):- # booru 子帖的文件名和父帖毫无关系,只有 parent_id 能把它们连起来。+ # booru 子帖的「标题」是标签拼的,和父帖毫无关系,只有来源声明的键能连起来。self._populate()groups = self.store.group(self.store.items())stray = [g for g in groups if g.primary.title == "totally different filename"]self.assertEqual(stray, [])+ def test_a_shared_origin_key_merges_two_different_sites(self):+ # 这是跨站去重真正靠得住的那条路:rule34.xxx 从 source 归一出的键,+ # 和 kemono 上同一帖子的键完全相同,标题再不一样也能精确合并。+ booru = self._source(provider="rule34xxx", ref="lazyprocrastinator")+ kemono = self._source(provider="kemono", ref="fanbox/30917150")+ self.store.record(booru, _fetch([+ FollowCandidate(provider="rule34xxx", external_id="18534395",+ title="fiona · blush", title_is_name=False,+ group_hint="fanbox:12304831"),+ ], provider="rule34xxx", ref="lazyprocrastinator"), moment=MOMENT)+ self.store.record(kemono, _fetch([+ FollowCandidate(provider="kemono", external_id="12304831",+ title="Fiona - Paizuri", group_hint="fanbox:12304831"),+ ], provider="kemono", ref="fanbox/30917150"), moment=MOMENT)+ groups = self.store.group(self.store.items())+ self.assertEqual(len(groups), 1)+ self.assertEqual(sorted(groups[0].providers), ["kemono", "rule34xxx"])++ def test_a_tag_derived_title_never_merges_two_works_on_its_own(self):+ # 标签拼出来的「标题」不是名字:同一作者标签相似的两条不能因此被并掉。+ source_id = self._source(provider="rule34xxx", ref="lazyprocrastinator")+ self.store.record(source_id, _fetch([+ FollowCandidate(provider="rule34xxx", external_id="1",+ title="fiona · blush", title_is_name=False),+ FollowCandidate(provider="rule34xxx", external_id="2",+ title="fiona · blush", title_is_name=False),+ ], provider="rule34xxx", ref="lazyprocrastinator"), moment=MOMENT)+ self.assertEqual(len(self.store.group(self.store.items())), 2)+def test_wip_is_surfaced_on_the_group(self):source_id = self._source()self.store.record(source_id, _fetch([