Peach: Local-first video metadata scraper and media manager.
feat(follow): 卡片与详情标出配音版和无声版
longmeidao5fef56db9f2d
diff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex 49e9cd812..8b8e804b0 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -171,6 +171,24 @@ def _item_tag_types(item, tags: list[str]) -> dict[str, str]:if (tag_type := _recorded_tag_type(item, tag))}+#: 声音标签按下划线、空格归一后比对。配音版包括后期加声音的 `sound_edit`:同一段动画+#: 常由配音者配上人声或音效后另发一帖。只写呻吟、音效的帖子不算,那是原片自带的声音。+_VOICED_TAGS = frozenset((+ "voice acted", "voice acting", "english voice acting", "japanese voice acting",+ "ai voice acted", "voice actress", "english voice", "voice",+ "dialogue", "english dialogue", "japanese dialogue", "sound edit",+))+_SILENT_TAGS = frozenset(("no sound", "no audio"))+++def _item_audio(item) -> str | None:+ """条目的声音版本:`voiced` 配音版、`silent` 无声版,来源没标就是 None。"""+ tags = {re.sub(r"[\s_]+", " ", tag).strip().casefold() for tag in _item_all_tags(item)}+ if tags & _VOICED_TAGS:+ return "voiced"+ return "silent" if tags & _SILENT_TAGS else None++#: 路径首段就是账号名的出处站。bsky 的账号在第二段(`/profile/<handle>`),fanbox#: 的账号是子域名,各自在 `_source_handle` 里单独取。_HANDLE_HOSTS = frozenset((@@ -957,6 +975,7 @@ def _item_payload(item, credential_providers: frozenset[str] = frozenset()) -> d"title": html.unescape(item.title) if item.title else item.title,"author": item.metadata.get("author") or None,"credit": _item_credit(item),+ "audio": _item_audio(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 eae287b65..9eff7cb41 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -525,6 +525,23 @@ class FollowContractTests(unittest.TestCase):"1": None, "2": None, "3": None, "4": None,})+ def test_items_say_whether_they_are_the_voiced_or_the_silent_version(self):+ """配音与无声两种写法都认,下划线和空格是同一个标签;只有呻吟、音效不算配音。"""+ def post(external_id, tags):+ 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={"tags": tags})+ self._seed(candidates=(+ post("1", "animated voice_acted sound"), post("2", "animated sound_edit"),+ post("3", "animated no_sound"), post("4", "animated moaning sound_effects"),+ post("5", "animated no_sound english_dialogue"),+ ), provider="rule34xxx", ref="billyhhyb", label="billyhhyb")+ audio = {group["primary"]["external_id"]: group["primary"]["audio"]+ for group in self._get()["groups"]}+ self.assertEqual(audio, {"1": "voiced", "2": "voiced", "3": "silent", "4": None,+ "5": "voiced"})+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",diff --git a/web/app.js b/web/app.jsindex 08a3d1b48..c187b64c0 100644--- a/web/app.js+++ b/web/app.js@@ -6109,6 +6109,9 @@ function followBadges(group,shown=group.primary){if(group.primary.variant_kind==='wip')badges.push('<span class="fbadge wip">WIP</span>');else if(group.has_wip)badges.push('<span class="fbadge wip partial">含 WIP</span>');if(group.primary.version)badges.push(`<span class="fbadge ver">${esc(group.primary.version)}</span>`);+ // 声音版本说的是卡面这一条:同一段动画的无声原片与配音重发常在同一个流里前后出现。+ const audio={voiced:'配音版',silent:'无声版'}[shown.audio];+ if(audio)badges.push(`<span class="fbadge audio">${audio}</span>`);/* 另见的站用站点图标列出,站名落在图标的 alt 与徽章的 title 上;没登记图标的站写站名。「另见」相对卡面这一条(`shown`)说:主条目没有当前视图的媒体时,卡面换成组里别的站那条,这时主条目的站才是另见,卡面自己的站不再列。 */