Peach: Local-first video metadata scraper and media manager.
refactor(follow): 作者身份判定移到 follow_identity
longmeidao49fa13aa639a
diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 4cbca7664..3e0883e95 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -22,7 +22,7 @@ Babepedia 资料采集复用 `babepedia_page` 的主名与别名交叉核对、`FC2 卖家名册复用 `sources/fc2.py` 的 `label`、`seller_url` 来源契约、`normalise_code_key`、`upsert_asset_entity`、职业断言和 SQLite 备份。`import_fc2_sellers.py` 读取已有作品快照,不发起采集;账号地址、来源作品号和馆藏作品号必须一致。同名不同账号、作品来源冲突保留在复核产物,既有身份和资料不覆盖;计划按摄取同一判据把集合名归到已有账号,摄取不收的作品记跳过,回收站作品不挂卖家。写入归属为 `script:fc2-seller@<批次>`,统一撤回入口 `revert_auto_landing.py` 同时处理账号链接、别名、外部编号、卖家断言及来源关系;有后续资料或引用的实体保留。导航复用 `BoardTabs`,动画作者保留 `creator` 身份与资料路由,通过艺人分类浏览。不新增依赖或外部解析器。-关注作者建档(`follow_creators`,ADR-0096)复用关注页的作者归组 `web_follow.name_key`/`author_name`、`canonicalize_entity_name` 的平台名闸、`follow_sources.profile_link_identity` 的名片识别和后继派发(ADR-0040)。链接与别名按 `auto:follow-creator@<批次>` 记归属,`revert_auto_landing.py` 统一撤回;实体有其他引用时保留。资料页的同名确认复用 `Note` 与 Board `Button`,不新增依赖。+关注作者建档(`follow_creators`,ADR-0096)复用关注页的作者归组 `follow_identity.name_key`/`author_name`、`canonicalize_entity_name` 的平台名闸、`follow_sources.profile_link_identity` 的名片识别和后继派发(ADR-0040)。链接与别名按 `auto:follow-creator@<批次>` 记归属,`revert_auto_landing.py` 统一撤回;实体有其他引用时保留。资料页的同名确认复用 `Note` 与 Board `Button`,不新增依赖。账号归属复用 `review_decision`、`creator_collection_base`、`write_owned_fields` 和全库归属审计。明确拒绝的资产与账号组合在自动摄取时跳过;用户写入保留复核入口。网黄博主只命中可信个人、内容创作者或发布账号断言,未分类账号保留全部名册入口。`attach_avatar_availability` 集中处理资料页、索引、搜索与统计的作品头像:发布账号缺少本人或出演职业证据时不提供作品帧兜底,已安装图片独立保留。来源核查清单、逐关系回执和备份存于 `peach-data/review/`。diff --git a/src/peach/follow_creators.py b/src/peach/follow_creators.pyindex 4efe77de9..3f9b6182a 100644--- a/src/peach/follow_creators.py+++ b/src/peach/follow_creators.py@@ -1,13 +1,13 @@"""关注作者建档:关注来源里的作者落成 `creator` 实体(ADR-0096)。-关注页把同一个人在几个站上的来源归成一组(`web_follow.author_key`),但那一组只活在+关注页把同一个人在几个站上的来源归成一组(`follow_identity.author_key`),但那一组只活在关注页里:没有资料页,名册上点开只能回关注页筛选。这条后继把每一组落成一条创作者实体,绑上它名下的来源,再把来源数据里已经有的正版发布渠道与社媒账号登记成实体链接。判据全是确定的,不联网:1. **建谁**:没绑实体、作者键是名字(`name:`)的每一组。名字取关注页那一份- (`web_follow.author_name`),过 `canonicalize_entity_name('creator')` 那道平台名、+ (`follow_identity.author_name`),过 `canonicalize_entity_name('creator')` 那道平台名、结构目录与转载站的闸,被挡的整组跳过。2. **不建、等人**:账本里已有同名或同别名的创作者,或两组归一成同一个名字。姓名相同不能自动建立关联(ADR-0095),这几组原样留着,摘要里列出来。@@ -15,7 +15,7 @@那是关注页自己的分组,不是新的同名推断,直接绑过去。4. **链接**:官方来源自己的地址;归档站上的原始账号(FANBOX 的数字 id 就是 pixiv 用户 id,Patreon 用户 id 拼 `user?u=`,OnlyFans 用户名);名片里可信的那几条- (`web_follow.trusted_profile_links`)。归档站与聚合站本身不登记,`follow_source`+ (`follow_identity.trusted_profile_links`)。归档站与聚合站本身不登记,`follow_source`的绑定就是它们的记录。链接只在绑定那一刻写:之后人删掉的一条不会在下一轮又长回来。每条写入都带归属串@@ -32,6 +32,9 @@ from datetime import datetime, timezonefrom urllib.parse import urlsplitfrom .entities import canonicalize_entity_name, normalize_entity_name+from .follow_identity import author_display_name, author_name, name_key, trusted_profile_links+from .follow_sources import KemonoConnector+from .follow_store import FollowStorefrom .followups import FollowupType, registerTASK_KEY = "follow-creator"@@ -78,7 +81,7 @@ _PROFILE_URLS = {_OFFICIAL_PROVIDERS = ("fanbox", "subscribestar", "patreon")#: 归档站上 `服务/用户` 还原成原站账号。只收核实过形状的:FANBOX 归档的数字 id 是-#: pixiv 用户 id(`web_follow._official_avatar_url` 靠它取官方头像),Patreon 的是用户 id,+#: pixiv 用户 id(`follow_identity.official_avatar_url` 靠它取官方头像),Patreon 的是用户 id,#: OnlyFans 的是用户名。Gumroad、Fantia 的归档 id 形状未核实,不还原。_ARCHIVE_ACCOUNTS = {"fanbox": ("pixiv", "https://www.pixiv.net/users/{}", str.isdigit),@@ -104,9 +107,6 @@ class Landing:def source_links(row) -> list[dict]:"""一条关注来源能证明的作者账号:`service`、`url` 与证据说明。"""- from .follow_sources import KemonoConnector- from .web_follow import trusted_profile_links-provider = str(row["provider"] or "")found: list[dict] = []if provider in _OFFICIAL_PROVIDERS and row["url"]:@@ -159,9 +159,6 @@ def _name_held(connection: sqlite3.Connection, normalized: str) -> int | None:def plan(connection: sqlite3.Connection) -> list[Landing]:"""这一轮每一位还没建档的关注作者怎么处理。只读,同样的账本给同样的结论。"""- from .follow_store import FollowStore- from .web_follow import _author_display_name, author_name, name_key-store = FollowStore(lambda: connection)rows = store.sources()alias_map, alias_groups = store.author_aliases()@@ -204,7 +201,7 @@ def plan(connection: sqlite3.Connection) -> list[Landing]:providers=providers, reason="账本里已有同名创作者"))continuenormalized = normalize_entity_name(name)- spellings = [_author_display_name(row) for row in group] + alias_names.get(key, [])+ spellings = [author_display_name(row) for row in group] + alias_names.get(key, [])aliases = tuple(dict.fromkeys(spelling for spelling in spellingsif spelling and normalize_entity_name(spelling) not in ("", normalized)diff --git a/src/peach/follow_identity.py b/src/peach/follow_identity.pynew file mode 100644index 000000000..3292c7848--- /dev/null+++ b/src/peach/follow_identity.py@@ -0,0 +1,162 @@+"""关注来源归到哪位作者、这位作者叫什么、名片里哪几条是本人账号。++关注页的作者分组(`web_follow`)和关注作者建档(`follow_creators`,ADR-0096)共用这一套判定,+所以它放在 web 层之外。+"""+from __future__ import annotations++import json+import urllib.parse++from .follow_avatar import MAX_PROFILE_IDENTITIES, profile_identities+from .follow_sources import KemonoConnector+from .follow_store import author_display_text, normalized_author_name+++def author_display_name(row) -> str:+ """一条追更来源上那个可读的作者拼写。++ 名字怎么算「同一个人」由 `follow_store` 定义(那是别名表的主键口径);+ 这里只决定「这一行显示哪个字段」。+ """+ if row["entity_id"] and row["entity_name"]:+ return str(row["entity_name"])+ return author_display_text(row["label"] or row["ref"] or "",+ provider=str(row["provider"] or ""))+++def source_metadata(row) -> dict:+ try:+ payload = json.loads(row["metadata_json"] or "{}")+ except (KeyError, TypeError, json.JSONDecodeError):+ return {}+ return payload if isinstance(payload, dict) else {}+++def author_key(row, aliases: dict[str, str] | None = None) -> str:+ """把一条来源归到「哪个作者」。++ 这跟 ADR-0019 的变体分组**不是同一个轴**:那个是同一条发布的多个变体,+ 这个是同一个作者在不同站点上的多条来源。用户在 Kemono 和 Pawchive 上关注的+ `LazyProcrastinator · fanbox`、在 Rule34Video 和 Rule34.xxx 上关注的+ `lazyprocrastinator`,是四条来源、一个人。++ 实体已经绑上就用实体 id——那是规范身份,比名字可靠。没绑才退回名字归一化:+ 去掉「· 服务名」后缀,再去掉大小写、空格、连字符这些不影响身份的噪声。+ 归一化只做到这一步,不做模糊匹配:把两个碰巧相似的名字并成一个人,+ 比让用户自己看到两行严重得多。+ """+ entity = row["entity_id"]+ if entity:+ return f"entity:{entity}"+ return name_key(row, aliases)+++def name_key(row, aliases: dict[str, str] | None = None) -> str:+ """这条来源不看实体绑定时归到哪个作者:`name:` 加归一化的名字,名字都没有就按来源。++ 关注作者建档(ADR-0096)靠它认出「新加的这条来源和已经建档的那几条本来就是同一组」。+ """+ recorded = str(source_metadata(row).get("author_key") or "").strip()+ if recorded:+ normalized = recorded+ else:+ label = str(row["label"] or row["ref"] or "")+ normalized = normalized_author_name(label, provider=str(row["provider"] or ""))+ if normalized:+ normalized = (aliases or {}).get(normalized, normalized)+ return f"name:{normalized}"+ return f"source:{row['id']}"+++def official_fanbox_identity(metadata: dict) -> str:+ """名片链接里的 FANBOX 创作者 id,没有就回空串。++ 它直接就是 `creator.get` 的参数,一个请求到头像,所以单独走一格。pixiv 的数字+ id 不在这里:有 pixiv 不等于开了 FANBOX,由 `official_profile_identities` 和+ X、Patreon 并排试。SubscribeStar 没有不带凭据就能读的头像接口,**未取得**,+ 只当身份证据用。+ """+ links = metadata.get("official_links")+ if not isinstance(links, list):+ return ""+ handles = {str(link.get("service") or ""): str(link.get("handle") or "")+ for link in links if isinstance(link, dict)}+ return handles.get("fanbox") or ""+++def official_profile_identities(metadata: dict) -> str:+ """名片上 X、Patreon 与 pixiv 的手柄,拼成 `/follow-avatar?service=profile` 的 id。++ 几家都交给服务端,由它各取最大一档再留像素最多的那张;形状不合法的那条直接略过。+ """+ links = metadata.get("official_links")+ pairs = [f"{link.get('service')}:{link.get('handle')}"+ for link in (links if isinstance(links, list) else ())+ if isinstance(link, dict)]+ usable = [pair for pair in dict.fromkeys(pairs) if profile_identities(pair)]+ return ",".join(usable[:MAX_PROFILE_IDENTITIES])+++def trusted_profile_links(row) -> list[dict]:+ """这条来源名片里能当作者本人账号的那几条。++ F95 的名片取自开楼正文,是作者自己贴的。booru 的 `official_links` 是作品出处,+ 合作作品会指向另一位作者,所以只留手柄就是这条来源作者名的那几条。+ """+ metadata = source_metadata(row)+ raw = metadata.get("official_links")+ links = [link for link in (raw if isinstance(raw, list) else ()) if isinstance(link, dict)]+ if str(row["provider"] or "") == "f95zone":+ return links+ expected = {+ normalized_author_name(str(row["ref"] or "")),+ normalized_author_name(str(metadata.get("author_key") or "")),+ }+ return [link for link in links+ if normalized_author_name(str(link.get("handle") or "")) in expected]+++def official_avatar_url(row) -> str | None:+ """Local resolver for an avatar from the creator's official profile.++ FANBOX archive refs carry the Pixiv user id, which is enough for Peach's fixed-host+ resolver to locate the public FANBOX profile and its official ``user.iconUrl``.+ A forum source has no such ref, so it goes through the profile links parsed out of+ the opening post instead. Services without a verified resolver keep the archive+ fallback, and sources with neither fall back to the author initial.+ """+ provider = str(row["provider"] or "")+ if provider in KemonoConnector.HOSTS:+ service, _, user = str(row["ref"] or "").partition("/")+ if service != "fanbox" or not user.isdigit():+ return None+ return "/follow-avatar?" + urllib.parse.urlencode(+ {"service": service, "id": user})+ metadata = {**source_metadata(row), "official_links": trusted_profile_links(row)}+ identity = official_fanbox_identity(metadata)+ if identity:+ return "/follow-avatar?" + urllib.parse.urlencode(+ {"service": "fanbox", "id": identity})+ profiles = official_profile_identities(metadata)+ if not profiles:+ return None+ return "/follow-avatar?" + urllib.parse.urlencode(+ {"service": "profile", "id": profiles})+++def author_name(rows, key: str, canonical: dict[str, str]) -> str:+ """一位作者(同一作者键下的几条来源)叫什么。++ 次序跟关注页那一份分组标题一致:实体名最可靠,其次是别名表定的规范名,再次是有+ 官方主页那条来源的写法;都没有才在各条标签里选大写最多的那个——+ `LazyProcrastinator` 比 `lazyprocrastinator` 更像作者自己写的名字。+ """+ entity = next((str(row["entity_name"]) for row in rows+ if row["entity_id"] and row["entity_name"]), "")+ labels = [(name, bool(official_avatar_url(row))) for row in rows+ if (name := author_display_name(row))]+ official = next((name for name, has_official in labels if has_official), "")+ best = max((name for name, _ in labels),+ key=lambda text: sum(ch.isupper() for ch in text), default="")+ return entity or canonical.get(key) or official or best or keydiff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex 297b7abf7..f5bc6410f 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -30,18 +30,20 @@ from .follow_discovery import (discovery_plan, no_backoff, suggest_term, tag_suggestions,)from .follow_image_dims import positive_dims+from .follow_identity import (+ author_display_name, author_key, author_name, name_key, official_avatar_url, source_metadata,+)from .follow_secrets import (CREDENTIAL_GUIDE, CredentialError, CredentialStore, credential_store_for,)from .follow_stream import proxyable-from .follow_avatar import MAX_PROFILE_IDENTITIES, profile_identitiesfrom .follow_sources import (CONNECTORS, KemonoConnector, Rule34VideoConnector, build_connector,canonical_source_ref, display_thumb_url, f95_attachment_media_items, f95_discussion_image,is_history_end_error, media_content_hash, parse_source_url, resource_links,)from .follow_store import (- FollowStore, ReleaseGroup, author_display_text, normalized_author_name,+ FollowStore, ReleaseGroup, normalized_author_name,)from .taste_history import read_creator_candidatesfrom .web_state import path_version@@ -1096,62 +1098,6 @@ def _content_hashes(group: ReleaseGroup) -> dict[tuple[int, int | None], str]:return hashes-def _author_display_name(row) -> str:- """一条追更来源上那个可读的作者拼写。-- 名字怎么算「同一个人」由 `follow_store` 定义(那是别名表的主键口径);- 这里只决定「这一行显示哪个字段」。- """- if row["entity_id"] and row["entity_name"]:- return str(row["entity_name"])- return author_display_text(row["label"] or row["ref"] or "",- provider=str(row["provider"] or ""))---def _source_metadata(row) -> dict:- try:- payload = json.loads(row["metadata_json"] or "{}")- except (KeyError, TypeError, json.JSONDecodeError):- return {}- return payload if isinstance(payload, dict) else {}---def author_key(row, aliases: dict[str, str] | None = None) -> str:- """把一条来源归到「哪个作者」。-- 这跟 ADR-0019 的变体分组**不是同一个轴**:那个是同一条发布的多个变体,- 这个是同一个作者在不同站点上的多条来源。用户在 Kemono 和 Pawchive 上关注的- `LazyProcrastinator · fanbox`、在 Rule34Video 和 Rule34.xxx 上关注的- `lazyprocrastinator`,是四条来源、一个人。-- 实体已经绑上就用实体 id——那是规范身份,比名字可靠。没绑才退回名字归一化:- 去掉「· 服务名」后缀,再去掉大小写、空格、连字符这些不影响身份的噪声。- 归一化只做到这一步,不做模糊匹配:把两个碰巧相似的名字并成一个人,- 比让用户自己看到两行严重得多。- """- entity = row["entity_id"]- if entity:- return f"entity:{entity}"- return name_key(row, aliases)---def name_key(row, aliases: dict[str, str] | None = None) -> str:- """这条来源不看实体绑定时归到哪个作者:`name:` 加归一化的名字,名字都没有就按来源。-- 关注作者建档(ADR-0096)靠它认出「新加的这条来源和已经建档的那几条本来就是同一组」。- """- recorded = str(_source_metadata(row).get("author_key") or "").strip()- if recorded:- normalized = recorded- else:- label = str(row["label"] or row["ref"] or "")- normalized = normalized_author_name(label, provider=str(row["provider"] or ""))- if normalized:- normalized = (aliases or {}).get(normalized, normalized)- return f"name:{normalized}"- return f"source:{row['id']}"--def group_authors(source_rows, aliases: dict[str, str] | None = None,) -> dict[int, tuple[str, frozenset[str]]]:"""每条来源的作者键,连同这位作者在各个来源上的全部名字写法。@@ -1167,7 +1113,7 @@ def group_authors(source_rows, aliases: dict[str, str] | None = None,spellings = names.setdefault(keys[int(row["id"])], set())for raw in (normalized_author_name(str(row["label"] or row["ref"] or ""),provider=str(row["provider"] or "")),- str(_source_metadata(row).get("author_key") or "").strip()):+ str(source_metadata(row).get("author_key") or "").strip()):if raw:spellings.update((raw, (aliases or {}).get(raw, raw)))for alias, canonical in (aliases or {}).items():@@ -1196,11 +1142,11 @@ def _profile_link_suggestions(rows, aliases: dict[str, str]) -> list[dict]:# 也不能再把它展示成身份合并建议。if row["entity_id"] or row["provider"] != "f95zone":continue- canonical = _author_display_name(row)+ canonical = author_display_name(row)canonical_key = normalized_author_name(canonical)if not canonical_key:continue- for link in _source_metadata(row).get("official_links") or ():+ for link in source_metadata(row).get("official_links") or ():if not isinstance(link, dict):continueservice = str(link.get("service") or "")@@ -1239,10 +1185,10 @@ def _follow_alias_suggestions(rows, aliases: dict[str, str]) -> list[dict]:if not raw_key or raw_key.startswith("source:"):continueidentity = identities.setdefault(raw_key, {- "key": raw_key, "name": _author_display_name(row), "providers": set(),+ "key": raw_key, "name": author_display_name(row), "providers": set(),})identity["providers"].add(str(row["provider"]))- candidate_name = _author_display_name(row)+ candidate_name = author_display_name(row)if candidate_name and len(candidate_name) < len(identity["name"]):identity["name"] = candidate_name@@ -1280,82 +1226,6 @@ def _avatar_url(provider: str, ref: str) -> str | None:return "/follow-avatar?" + urllib.parse.urlencode({"provider": provider, "ref": ref})-def _official_fanbox_identity(metadata: dict) -> str:- """名片链接里的 FANBOX 创作者 id,没有就回空串。-- 它直接就是 `creator.get` 的参数,一个请求到头像,所以单独走一格。pixiv 的数字- id 不在这里:有 pixiv 不等于开了 FANBOX,由 `_official_profile_identities` 和- X、Patreon 并排试。SubscribeStar 没有不带凭据就能读的头像接口,**未取得**,- 只当身份证据用。- """- links = metadata.get("official_links")- if not isinstance(links, list):- return ""- handles = {str(link.get("service") or ""): str(link.get("handle") or "")- for link in links if isinstance(link, dict)}- return handles.get("fanbox") or ""---def _official_profile_identities(metadata: dict) -> str:- """名片上 X、Patreon 与 pixiv 的手柄,拼成 `/follow-avatar?service=profile` 的 id。-- 几家都交给服务端,由它各取最大一档再留像素最多的那张;形状不合法的那条直接略过。- """- links = metadata.get("official_links")- pairs = [f"{link.get('service')}:{link.get('handle')}"- for link in (links if isinstance(links, list) else ())- if isinstance(link, dict)]- usable = [pair for pair in dict.fromkeys(pairs) if profile_identities(pair)]- return ",".join(usable[:MAX_PROFILE_IDENTITIES])---def trusted_profile_links(row) -> list[dict]:- """这条来源名片里能当作者本人账号的那几条。-- F95 的名片取自开楼正文,是作者自己贴的。booru 的 `official_links` 是作品出处,- 合作作品会指向另一位作者,所以只留手柄就是这条来源作者名的那几条。- """- metadata = _source_metadata(row)- raw = metadata.get("official_links")- links = [link for link in (raw if isinstance(raw, list) else ()) if isinstance(link, dict)]- if str(row["provider"] or "") == "f95zone":- return links- expected = {- normalized_author_name(str(row["ref"] or "")),- normalized_author_name(str(metadata.get("author_key") or "")),- }- return [link for link in links- if normalized_author_name(str(link.get("handle") or "")) in expected]---def _official_avatar_url(row) -> str | None:- """Local resolver for an avatar from the creator's official profile.-- FANBOX archive refs carry the Pixiv user id, which is enough for Peach's fixed-host- resolver to locate the public FANBOX profile and its official ``user.iconUrl``.- A forum source has no such ref, so it goes through the profile links parsed out of- the opening post instead. Services without a verified resolver keep the archive- fallback, and sources with neither fall back to the author initial.- """- provider = str(row["provider"] or "")- if provider in KemonoConnector.HOSTS:- service, _, user = str(row["ref"] or "").partition("/")- if service != "fanbox" or not user.isdigit():- return None- return "/follow-avatar?" + urllib.parse.urlencode(- {"service": service, "id": user})- metadata = {**_source_metadata(row), "official_links": trusted_profile_links(row)}- identity = _official_fanbox_identity(metadata)- if identity:- return "/follow-avatar?" + urllib.parse.urlencode(- {"service": "fanbox", "id": identity})- profiles = _official_profile_identities(metadata)- if not profiles:- return None- return "/follow-avatar?" + urllib.parse.urlencode(- {"service": "profile", "id": profiles})--def _source_payload(row, aliases: dict[str, str] | None = None) -> dict:history_exhausted = _legacy_history_end(row)return {@@ -1367,9 +1237,9 @@ def _source_payload(row, aliases: dict[str, str] | None = None) -> dict:# 标签是这条来源在站上的名字,作者名是从它推出来的人名。两者在论坛上差得# 很远(`Strauzek Collection [2026-09-04] [Mr_Strauz]` vs `Mr_Strauz`),# 而怎么推是站点知识,页面自己再推一遍迟早和这里漂移。- "author_name": _author_display_name(row),+ "author_name": author_display_name(row),"author_key": author_key(row, aliases),- "official_avatar_url": _official_avatar_url(row),+ "official_avatar_url": official_avatar_url(row),"avatar_url": _avatar_url(row["provider"], row["ref"]),"url": row["url"],"semantics": row["semantics"],@@ -1518,23 +1388,6 @@ def q_follow_tags(contract, args) -> dict:"categories": categories}-def author_name(rows, key: str, canonical: dict[str, str]) -> str:- """一位作者(同一作者键下的几条来源)叫什么。-- 次序跟关注页那一份分组标题一致:实体名最可靠,其次是别名表定的规范名,再次是有- 官方主页那条来源的写法;都没有才在各条标签里选大写最多的那个——- `LazyProcrastinator` 比 `lazyprocrastinator` 更像作者自己写的名字。- """- entity = next((str(row["entity_name"]) for row in rows- if row["entity_id"] and row["entity_name"]), "")- labels = [(name, bool(_official_avatar_url(row))) for row in rows- if (name := _author_display_name(row))]- official = next((name for name, has_official in labels if has_official), "")- best = max((name for name, _ in labels),- key=lambda text: sum(ch.isupper() for ch in text), default="")- return entity or canonical.get(key) or official or best or key--def q_follow_authors(contract, args) -> dict:"""在线作者索引,供艺人页那一档「在线」列出关注来源里的人。@@ -1586,7 +1439,7 @@ def q_follow_authors(contract, args) -> dict:entry["_rows"].append(row)if row["entity_id"]:entry["entity_id"] = int(row["entity_id"])- official = _official_avatar_url(row)+ official = official_avatar_url(row)mirror = _avatar_url(row["provider"], row["ref"])if official and not entry["avatar"]:entry["avatar"] = official@@ -1736,8 +1589,8 @@ def _followed_names(rows, alias_groups) -> dict[str, str]:for row in rows:add(row["entity_name"])- add(_author_display_name(row))- for link in _source_metadata(row).get("official_links") or ():+ add(author_display_name(row))+ for link in source_metadata(row).get("official_links") or ():if isinstance(link, dict):add(link.get("handle"))for group in alias_groups:@@ -2198,7 +2051,7 @@ def _backfill_profile_links(row, credentials, writer) -> None:但什么都没找到会写下空清单,那是「问过了,他没留主页」,不该每次检查再问一遍。"""provider = str(row["provider"] or "")- if provider != "f95zone" or "official_links" in _source_metadata(row):+ if provider != "f95zone" or "official_links" in source_metadata(row):returnlinks = _profile_links(provider, str(row["ref"] or ""),credentials.load(provider))@@ -2274,7 +2127,7 @@ def _run_follow_check(contract, body, job_id=None) -> dict:for row in rows:if job_id and contract.follow_job.snapshot() is None:break- current = {"source": row["id"], "label": _author_display_name(row),+ current = {"source": row["id"], "label": author_display_name(row),"provider": PROVIDER_LABELS.get(row["provider"], row["provider"])}def progress(*, current=current, **fields):if job_id:@@ -2306,7 +2159,7 @@ def _run_follow_check(contract, body, job_id=None) -> dict:connector_factory=build_connector, older=True, progress=progress,initial_days=initial_days, cooldown=cooldown))rounds += 1- result["author"] = _author_display_name(row)+ result["author"] = author_display_name(row)results.append(result)progress()# 还没建档的关注作者交给建档后继(ADR-0096)。后继由结果声明、调度端统一派@@ -2493,7 +2346,7 @@ def entity_follow(contract, connection, entity_id: int) -> dict | None:if not bound and not held:return Noneby_id = {int(row["id"]): row for row in sources}- official = next((url for row in bound if (url := _official_avatar_url(row))), "")+ official = next((url for row in bound if (url := official_avatar_url(row))), "")archive = next((url for row in bound if (url := _avatar_url(row["provider"], row["ref"]))), "")return {"key": f"entity:{int(entity_id)}" if bound else "",diff --git a/tests/test_complexity_ratchet.py b/tests/test_complexity_ratchet.pyindex f06f87968..7c9ce73b8 100644--- a/tests/test_complexity_ratchet.py+++ b/tests/test_complexity_ratchet.py@@ -49,7 +49,7 @@ BASELINE: dict[str, int] = {"scripts/harvest_social_avatars.py:run": 45,"scripts/fetch_studio_avatar_candidates.py:main": 44,"src/peach/web_catalog.py:q_item": 44,- "src/peach/web_follow.py:q_follow_authors": 44,+ "src/peach/web_follow.py:q_follow_authors": 40,"scripts/sheets.py:run": 40,"src/peach/taste_history.py:_taste_analysis": 40,"src/peach/web_catalog.py:catalog_filter": 40,diff --git a/tests/test_follow_creators.py b/tests/test_follow_creators.pyindex f16ca688c..f74ec7592 100644--- a/tests/test_follow_creators.py+++ b/tests/test_follow_creators.py@@ -13,7 +13,7 @@ from peach.follow_sources import FollowCandidate, SourceFetchfrom peach.follow_store import FollowStorefrom peach.web_contract import WebContract, dispatch_api_get, dispatch_api_postfrom peach.web_entity import q_entity-from peach.web_follow import author_key+from peach.follow_identity import author_keyfrom scripts import revert_auto_landingfrom support.ledger import fresh_ledgerdiff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 4bd73f585..36ecc20ee 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -16,8 +16,8 @@ from pathlib import Pathfrom types import SimpleNamespacefrom unittest import mock-from peach import (avatar_face, follow_assets, follow_discovery, follow_store,- web_follow, web_stats)+from peach import (avatar_face, follow_assets, follow_discovery, follow_identity,+ follow_store, web_follow, web_stats)from peach.follow import FollowHistoryEndfrom peach.follow import FollowSourceErrorfrom peach.follow_discovery import Discovery, ExternalSearch@@ -155,6 +155,10 @@ class FollowContractTests(unittest.TestCase):# 状态根同理:创作者清单在那里,不给就会读到这台机器上的 42 万个名字,# 快慢和结果都由本机状态决定。follow_state_root=self.root / "state")+ self.addCleanup(self.contract.stop_background_jobs)+ # 检查结算会声明关注作者建档后继(ADR-0096)。后台线程领走它就是和断言、和临时+ # 目录的删除赛跑,这里关掉自动领取,要跑后继的用例自己 `drain()`。+ self.contract.followups.stop()def _seed(self, candidates=None, provider="rule34video", ref="lazyprocrastinator",semantics="work", label="LazyProcrastinator"):@@ -3077,7 +3081,7 @@ class FollowItemProjectionTests(unittest.TestCase):"""row = {"entity_id": None, "entity_name": None, "provider": "f95zone","ref": "63802", "label": "Strauzek Collection [2026-09-04] [Mr_Strauz]"}- self.assertEqual(web_follow._author_display_name(row), "Mr_Strauz")+ self.assertEqual(follow_identity.author_display_name(row), "Mr_Strauz")# 页面不自己解析标签,只认服务端给的 `author_name`(`frontend/test/react/follow-marks.test.ts`)。def test_the_card_in_the_opening_post_suggests_the_other_spelling(self):@@ -3125,13 +3129,13 @@ class FollowItemProjectionTests(unittest.TestCase):return {"provider": provider, "ref": ref, "metadata_json": metadata}self.assertEqual(- web_follow._official_avatar_url(+ follow_identity.official_avatar_url(source_row("kemono", "fanbox/30917150")),"/follow-avatar?service=fanbox&id=30917150",)# 论坛来源没有这种 ref,身份只能来自首楼名片:FANBOX 的创作者 id 一步到位。self.assertEqual(- web_follow._official_avatar_url(source_row(+ follow_identity.official_avatar_url(source_row("f95zone", "87212",'{"official_links":[{"service":"patreon","handle":"jul3dnsfw"},''{"service":"fanbox","handle":"jul3dnsfw"}]}')),@@ -3140,7 +3144,7 @@ class FollowItemProjectionTests(unittest.TestCase):# 有 pixiv 不等于开了 FANBOX:flim13 名片上是 X 加 pixiv,pixiv 换不到头像,# 所以它和 X 并排递给服务端,不单独占住这一格把 X 挡在外面。self.assertEqual(- web_follow._official_avatar_url(source_row(+ follow_identity.official_avatar_url(source_row("f95zone", "155903",'{"official_links":[{"service":"twitter","handle":"Flim_13a"},''{"service":"pixiv","handle":"14934767"}]}')),@@ -3149,7 +3153,7 @@ class FollowItemProjectionTests(unittest.TestCase):# 没有 FANBOX 时交给 X、Patreon 与 pixiv:几家都递给服务端去比谁更清楚,# 取不到头像的 SubscribeStar 和形状不对的手柄不进这串。self.assertEqual(- web_follow._official_avatar_url(source_row(+ follow_identity.official_avatar_url(source_row("f95zone", "13899",'{"official_links":[{"service":"twitter","handle":"Rekin3D"},''{"service":"patreon","handle":"sharkarts"},'@@ -3157,7 +3161,7 @@ class FollowItemProjectionTests(unittest.TestCase):'{"service":"twitter","handle":"not a handle"}]}')),"/follow-avatar?service=profile&id=twitter%3ARekin3D%2Cpatreon%3Asharkarts",)- self.assertIsNone(web_follow._official_avatar_url(+ self.assertIsNone(follow_identity.official_avatar_url(source_row("f95zone", "63802")))for provider, ref in (("rule34video", "1290582"),("rule34xxx", "lazyprocrastinator"),