Peach: Local-first video metadata scraper and media manager.
feat(follow): booru 帖子按出处账号署名真正的发布者
longmeidao3ae52036bae2
diff --git a/docs/adr/0078-follow-booru-posts-credit-the-source-account.md b/docs/adr/0078-follow-booru-posts-credit-the-source-account.mdnew file mode 100644index 000000000..9e2f1bddf--- /dev/null+++ b/docs/adr/0078-follow-booru-posts-credit-the-source-account.md@@ -0,0 +1,42 @@+# ADR-0078:booru 帖子按出处账号署名发布者++- 状态:Accepted+- 日期:2026-09-26++## 背景++rule34.xxx 把动画、模型、场景、配音的作者都标成 artist。按 artist 标签关注一位创作者时,+流里会混进别人用他的模型做的作品,卡片却署着被关注者的名字。例如 17070008 挂着+2hour2、billyhhyb、madruga3d 等五位 artist,出处是 `x.com/2hour2hour`,实际作者是+2hour2,billyhhyb 只提供了模型。++按出处把这类帖子隐藏的做法被否决:LazyProcrastinator 与 InitialA 的配音版同样由配音者+发布,会一起被藏掉。用户选择保留,只把署名改对。++## 决策++`web_follow._item_credit` 在读时计算,不写 ledger。rule34xxx、rule34paheal 的帖子同时满足+以下条件时,条目 payload 带 `credit: {poster, credited}`:++1. 出处第一个网址能认出账号:X、Twitter、Patreon、SubscribeStar、Pixiv、Ko-fi 取路径首段,+ Bluesky 取第二段,fanbox 取子域名。+2. 被关注者本人也在 artist 标签里。+3. 账号对上一个 artist 标签,而且对上的不是被关注者。只比字母数字;四个字符以上的前缀+ 也算同一人(`2hour2hour` 对 `2hour2`)。同一人挂了几个写法时,取与账号完全一致的,+ 其次取最长的。++卡片与详情的作者名换成 `poster`。也关注了这位就用他的来源名和头像,否则只显示首字母,+不借用被关注者的头像。下面多一行「署名含 `credited`」,说明这条为什么出现在这个流里。+认不出账号、对不上标签的帖子照常署被关注者,不猜。++## 依据++2026-09-26 在真实 ledger 上只读试算,4826 帖里 201 帖改署名。最多的是配音版:+LazyProcrastinator ← ecchiwaffle 38 帖、InitialA ← evilaudio 27 帖。17070008 算出+`{poster: 2hour2, credited: billyhhyb}`。++## 后果++- 筛选、分组、关注来源都不变:这些帖子仍在被关注者的流里,按作者筛照旧能筛到。+- 出处没写或写的是站内链接的帖子无法区分,多位 artist 的帖子里约一半属于这种情况。+- 配音者发布的版本同样署配音者,与动画作者本人发布的版本分别署名。diff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex 81ab69866..49e9cd812 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -171,6 +171,71 @@ def _item_tag_types(item, tags: list[str]) -> dict[str, str]:if (tag_type := _recorded_tag_type(item, tag))}+#: 路径首段就是账号名的出处站。bsky 的账号在第二段(`/profile/<handle>`),fanbox+#: 的账号是子域名,各自在 `_source_handle` 里单独取。+_HANDLE_HOSTS = frozenset((+ "x.com", "twitter.com", "patreon.com", "www.patreon.com", "subscribestar.adult",+ "www.subscribestar.adult", "bsky.app", "www.pixiv.net", "ko-fi.com",+))+++def _handle_key(text: str) -> str:+ return re.sub(r"[^a-z0-9]", "", html.unescape(str(text or "")).casefold())+++def _source_handle(url) -> str:+ first = str(url or "").split()+ try:+ parts = urllib.parse.urlsplit(first[0] if first else "")+ except ValueError:+ return ""+ host = (parts.hostname or "").casefold()+ segments = [segment for segment in parts.path.split("/") if segment]+ if host.endswith(".fanbox.cc"):+ return host.split(".")[0]+ if host not in _HANDLE_HOSTS or not segments:+ return ""+ return segments[1] if host == "bsky.app" and len(segments) > 1 else segments[0]+++def _same_handle(handle: str, tag: str) -> bool:+ """账号名与 artist 标签是不是同一个人。++ 账号常比标签多个后缀(`2hour2hour` 对 `2hour2`),所以四个字符以上的前缀也算。+ """+ a, b = _handle_key(handle), _handle_key(tag)+ return bool(a and b) and (a == b or (+ min(len(a), len(b)) >= 4 and (a.startswith(b) or b.startswith(a))))+++def _item_credit(item) -> dict | None:+ """booru 帖子真正的发布者,被关注的这位只是素材署名时才有值。++ rule34 把动画、模型、场景的作者都标成 artist。帖子出处多半指向发布者自己的+ X/Patreon 帖子:账号名对上一个 artist 标签、而那一位不是被关注者时,卡片署名+ 改成发布者,被关注者退成「署名含」。认不出账号、对不上标签,或对上的就是被关注者+ 本人,照常显示被关注者(ADR-0078)。+ """+ if item.provider not in {"rule34xxx", "rule34paheal"}:+ return None+ followed = html.unescape(str(item.metadata.get("tag") or "")).strip()+ handle = _source_handle(item.metadata.get("source"))+ raw = item.metadata.get("tag_types")+ if not followed or not handle or not isinstance(raw, dict):+ return None+ artists = [html.unescape(str(tag)) for tag, kind in raw.items()+ if str(kind).casefold() == "artist"]+ if not any(_handle_key(tag) == _handle_key(followed) for tag in artists):+ return None+ owners = [tag for tag in artists if _same_handle(handle, tag)]+ if not owners or any(_same_handle(followed, tag) for tag in owners):+ return None+ # 同一人挂了几个写法(`madruga3d`、`madrugasfm`)时取和账号完全一致的,其次取最长的。+ poster = max(owners, key=lambda tag: (_handle_key(tag) == _handle_key(handle),+ len(_handle_key(tag))))+ return {"poster": poster, "credited": followed}++#: 作品名里的罗马数字。写成名单而不是通用式:通用式会把 `mix`、`did` 这类英文词#: 也判成数字,而作品名里实际用到的就这十几个。_ROMAN_NUMERALS = frozenset((@@ -891,6 +956,7 @@ def _item_payload(item, credential_providers: frozenset[str] = frozenset()) -> d# 出口统一反转义,与 _item_tags 同一处理,unescape 幂等。"title": html.unescape(item.title) if item.title else item.title,"author": item.metadata.get("author") or None,+ "credit": _item_credit(item),"summary": item.metadata.get("summary") or None,"url": item.url,"thumb_url": _thumb_url(item),diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 9a9c43f9e..eae287b65 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -495,6 +495,36 @@ class FollowContractTests(unittest.TestCase):["miqo'te", "y'shtola", "barnabas'_mother"])self.assertEqual(item["title"], "barnabas' mother · biting lip")+ def _credited_post(self, external_id, source, artists, followed="billyhhyb"):+ tag_types = {tag: "artist" for tag in artists} | {"blowjob": "general"}+ return FollowCandidate(+ provider="rule34xxx", external_id=external_id, title=f"post {external_id}",+ url=f"https://rule34.xxx/index.php?page=post&s=view&id={external_id}",+ extra={"tag": followed, "tags": " ".join(tag_types), "source": source,+ "tag_types": tag_types})++ def test_booru_posts_credit_the_poster_whose_account_is_the_source(self):+ """出处账号对上另一位 artist 时,那位是作者,被关注者只是素材署名。++ 17070008 挂着 2hour2、billyhhyb、madruga3d 三位 artist,出处是+ `x.com/2hour2hour`:账号比标签多个后缀,前缀相同也算同一人。+ """+ self._seed(candidates=(+ self._credited_post("17070008", "https://x.com/2hour2hour/status/2039951989975494723",+ ["2hour2", "billyhhyb", "madruga3d"]),+ self._credited_post("1", "https://x.com/billyhhyb/status/1", ["billyhhyb", "madruga3d"]),+ self._credited_post("2", "https://pixiv.net/artworks/2", ["2hour2", "billyhhyb"]),+ self._credited_post("3", "https://x.com/someoneelse/status/3", ["2hour2", "billyhhyb"]),+ self._credited_post("4", "https://x.com/2hour2hour/status/4", ["2hour2"]),+ ), provider="rule34xxx", ref="billyhhyb", label="billyhhyb")+ credits = {group["primary"]["external_id"]: group["primary"]["credit"]+ for group in self._get()["groups"]}+ self.assertEqual(credits, {+ "17070008": {"poster": "2hour2", "credited": "billyhhyb"},+ # 本人发的、出处认不出账号的、账号对不上任何 artist 的、被关注者不在 artist 里的:照常署名。+ "1": None, "2": None, "3": None, "4": None,+ })+def test_external_file_pages_are_exposed_without_leaking_raw_media_urls(self):self._seed(candidates=(FollowCandidate(provider="f95zone", external_id="21435166", title="InitialA Collection",@@ -3120,7 +3150,7 @@ class FollowWebSourceTests(unittest.TestCase):def test_follow_cards_use_author_avatars_and_open_details_inside_peach(self):self.assertPageContains("return followCard(group,siblings)")- self.assertPageContains('title="创作者头像">${followAuthorAvatar(authorSources)}')+ self.assertPageContains('title="创作者头像">${avatar}')self.assertNotIn('class="mav fsourceavatar" title="${esc(item.provider_label)}">${sourceIcon(item.provider)}',self.page,@@ -3145,7 +3175,7 @@ class FollowWebSourceTests(unittest.TestCase):".followdetailtags .tg:hover{border-color:color-mix(in srgb,var(--r34-tag) 68%,transparent)")self.assertPageContains("background:color-mix(in srgb,var(--r34-tag) 18%,transparent);color:var(--ink)}")- self.assertPageContains("const postedBy=item.author&&foldName(item.author)!==foldName(author)")+ self.assertPageContains("const postedBy=credited?'':item.author&&foldName(item.author)!==foldName(author)")self.assertPageContains("openFollowDetail(id);")self.assertNotIn('class="cardopenhit" href=', self.page)self.assertNotIn('class="t cardtitle" href=', self.page)diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 474a32973..225104e44 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -9165,6 +9165,8 @@ class WebUiSourceTests(unittest.TestCase):".entityfacts .clip",# 作者是展示名,尾部省略;完整身份保留在 title。".followbyline .followauthor",+ # 署名行同属展示名,尾部省略;完整一行保留在 title。+ ".followitem .meta .followcredit",".followpageaction .fmeta",".fsechead .fmeta",".frow>b",diff --git a/web/app.js b/web/app.jsindex 158abb5bb..08a3d1b48 100644--- a/web/app.js+++ b/web/app.js@@ -6328,8 +6328,8 @@ async function openFollowDetail(id,push=true,mediaIndex=null,preserveReturn=falsconst badges=followBadges({primary:item,variants:[],duplicates:[],has_wip:item.variant_kind==='wip'});// 卡片只消费 general 内容投影;详情保留来源记录的全部类型,并按类型着色。const tags=followDetailTags(item).map(tag=>followTagChip(item,tag,'button')).join('');- const author=followAuthorName(authorSources)||item.author||item.source_label||'创作者未取得';- const postedBy=item.author&&foldName(item.author)!==foldName(author)?item.author:'';+ const {author,avatar,credited}=followIdentity(item,authorSources);+ const postedBy=credited?'':item.author&&foldName(item.author)!==foldName(author)?item.author:'';const mediaIssue=followMediaIssue(item);// 被隐藏的图退到这条恢复带上:缩略图加一枚撤销键,点了就回到轮播。// 不占媒体队列,也不进角标数——它们已经是「不在看」的那部分。@@ -6343,8 +6343,8 @@ async function openFollowDetail(id,push=true,mediaIndex=null,preserveReturn=fals${embeddedQueue?followEmbeddedQueueHtml(item,selectedMedia.index):(collection?followQueueHtml(collection,item.id):'')}<div class="side followdetailside"><div class="sidecontent"><div class="followdetailtitle"><div class="stitle" data-reveal-line>${esc(item.title)}</div>${item.url?`<a class="followorigin externallink" href="${esc(item.url)}" target="_blank" rel="noreferrer noopener" title="打开来源页面" aria-label="打开来源页面">${icon('external-link','externalmark')}</a>`:''}</div>- <div class="followdetailidentity"><span class="mav fsourceavatar">${followAuthorAvatar(authorSources)}</span>- <div><b>${esc(author)}</b>${postedBy?`<span>发布者 ${esc(postedBy)}</span>`:''}</div></div>+ <div class="followdetailidentity"><span class="mav fsourceavatar">${avatar}</span>+ <div><b>${esc(author)}</b>${postedBy?`<span>发布者 ${esc(postedBy)}</span>`:''}${credited?`<span>署名含 ${esc(credited)}</span>`:''}</div></div><div class="smeta mono" data-reveal-line><span>${followWhen(item)}</span>${realDuration(item.duration)?`<span>${fmtDur(item.duration)}</span>`:''}${badges?`<span class="fbadges">${badges}</span>`:''}</div>${item.summary?`<p class="followdetailsummary">${esc(item.summary)}</p>`:''}${mediaIssue?`<p class="fnote followmediaissue">${esc(mediaIssue)}</p>`:''}@@ -6545,7 +6545,7 @@ function followCard(group,authorSources=[]){const {isMix,label:mixLabel,glyph:mixGlyph,faces:faceUrls}=followStack({cover:thumbUrl,coverFace:(selectedMedia?.thumb_url?selectedMedia:item).face,stack:group.stack,imageView,limit:MIX_FLIP_FACES});const badges=followBadges(group,item);- const author=followAuthorName(authorSources)||item.author||item.source_label||'创作者未取得';+ const {author,avatar,credited}=followIdentity(item,authorSources);const when=followWhen(item),compactWhen=/^\d{4}-/.test(when)?(when.startsWith(String(new Date().getFullYear()))?when.slice(5,10):when.slice(0,10)):when;const tags=followCardTags(item).slice(0,3).map(tag=>followTagChip(item,tag)).join('');@@ -6563,9 +6563,10 @@ function followCard(group,authorSources=[]){<button data-follow-status="${item.id}" data-to="ignored" title="忽略" aria-label="忽略"${item.status==='ignored'?' disabled':''}>${icon('eye-off')}</button>${item.status==='seen'||item.status==='ignored'?`<button data-follow-status="${item.id}" data-to="new" title="恢复未看" aria-label="恢复未看">${icon('rotate-ccw')}</button>`:''}</div></div></div></div>- <div class="meta"><span class="mav fsourceavatar" title="创作者头像">${followAuthorAvatar(authorSources)}</span>+ <div class="meta"><span class="mav fsourceavatar" title="创作者头像">${avatar}</span><div class="mtext"><button class="t cardtitle" data-follow-detail="${item.id}">${esc(item.title)}</button><div class="s followbyline"><span class="followauthor" title="${esc(author)}">${esc(author)}</span><time class="mono" datetime="${esc(item.published_at||'')}" title="${esc(when)}">${esc(compactWhen)}</time></div>+ ${credited?`<div class="s followcredit" title="署名含 ${esc(credited)}">署名含 ${esc(credited)}</div>`:''}${badges?`<div class="fbadges">${badges}</div>`:''}${tags?`<div class="ctags">${tags}</div>`:''}${mediaIssue?`<span class="fnote followmediaissue">${esc(mediaIssue)}</span>`:''}</div></div><span class="fstate" aria-live="polite"></span></article>`;@@ -7046,26 +7047,41 @@ function sourceIcon(provider,label=''){return SOURCE_ICON_PROVIDERS.has(provider? `<img class="ficon" src="/source-icon?provider=${encodeURIComponent(provider)}" alt="${esc(label)}"${label?` title="${esc(label)}"`:''} loading="lazy" data-drop="self">`: ''}-function followAvatarInitial(group){- const name=followAuthorName(group).trim();+function followAvatarInitial(name){+ name=String(name||'').trim();const ascii=name.match(/[A-Za-z0-9]/);return (ascii?ascii[0]:Array.from(name)[0]||'?').toUpperCase();}/* 同一创作者的官方来源优先提供头像,归档来源只回退。都取不到时明确用创作者首字母,不再从某条来源的中文显示标签切出“初”“一”之类与创作者无关的字。 */-function followAuthorAvatar(group){+function followAuthorAvatar(group,name=followAuthorName(group)){const official=group.find(source=>source.official_avatar_url);const mirror=group.find(source=>source.avatar_url);const src=official?.official_avatar_url||mirror?.avatar_url;const fallback=official&&mirror&&mirror.avatar_url!==src?mirror.avatar_url:'';- const initial=followAvatarInitial(group);+ const initial=followAvatarInitial(name);if(src)return `<img class="favatar" src="${esc(src)}" alt=""loading="lazy" referrerpolicy="no-referrer" ${imageFallbackAttrs({drop:'initial',dropClass:'favatar none',initial,fallbacks:[fallback]})}>`;return `<span class="favatar none" title="没有可用头像">${esc(initial)}</span>`;}+/* 卡片与详情的署名。booru 帖子由服务端认出真正的发布者时(`item.credit`),名字和头像+ 都换成发布者:也关注了这位就用那位的来源,否则只出首字母,不借被关注者的头像;+ 被关注者退成一行「署名含」,说明这条为什么出现在这里。认不出的照常署被关注者。 */+function followIdentity(item,authorSources){+ const poster=item.credit?.poster;+ if(!poster)return {author:followAuthorName(authorSources)||item.author||item.source_label||'创作者未取得',+ avatar:followAuthorAvatar(authorSources),credited:''};+ const key=value=>String(value||'').toLowerCase().replace(/[^a-z0-9]/g,'');+ const sources=followData?.sources||[];+ const own=sources.find(row=>key(row.ref)===key(poster));+ const group=own?.author_key?sources.filter(row=>row.author_key===own.author_key):own?[own]:[];+ const author=group.length&&followAuthorName(group)||poster;+ return {author,avatar:followAuthorAvatar(group,author),credited:item.credit.credited||''};+}+/* 题材那一枚跟首页的厂牌药丸同形:28px 圆标识加作品名。圆里装的是这个题材下最热的那几条里第一张看得见脸的封面,服务端按 `work` 这个身份自己去挑再存在本机,页面递不进地址。挑不出图的题材(facet 那一行的第四位说了算)直接出两个字母,不出diff --git a/web/css/21-online.css b/web/css/21-online.cssindex 6aa399cd5..179f2e4c0 100644--- a/web/css/21-online.css+++ b/web/css/21-online.css@@ -55,6 +55,9 @@.followitem .meta .followbyline{display:flex;flex-wrap:nowrap;gap:6px;min-width:0;overflow:hidden}.followbyline .followauthor{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.followbyline time{flex:none;white-space:nowrap}+/* 署名行只在作者换成发布者时出现,弱于作者名,一行放不下就截断。 */+.followitem .meta .followcredit{min-height:0;font-size:var(--fs-xs);color:var(--muted);overflow:hidden;+ text-overflow:ellipsis;white-space:nowrap}.fbadge{padding:2px 8px;border:1px solid var(--border-15);border-radius:var(--badge-radius);font-size:var(--fs-xs);color:var(--ink-2)}.fbadge.wip{border-color:var(--meter);color:var(--meter)}/* 「含 WIP」说的是同组里还有一条半成品,这一条本身不是;配色要弱于 WIP 本体。 */