Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(performers): 女优页头读 performer_profile,给出五项资料与按名义分组的别名

longmeidaoeb9fe70e2611
diff --git a/docs/REUSE.md b/docs/REUSE.md
index b339dec20..7dc8355e6 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -106,6 +106,8 @@ JAV 默认封面(官方封面/预览图)与默认大小(大图/小图
minnano-av 读资料表,avwikidb 读 JSON-LD。不采用的候选:`kanojo-db/scrapers` 的 Minna no AV
爬虫与 `stashapp/CommunityScrapers` 的 Minnano-AV 规则都不是可安装的库,后者是 Stash 的 XPath 配置
(Stash 适配器已关,ADR-0021);站点入口与名字核对 Peach 已有一份,只补资料表逐格规整。
+ 女优页头(ADR-0069)只读这张表:`performer_header` 出五项与别名分组,別名栏的渠道注记从 `raw_json`
+ 原文里由 `minnano_av.name_entries` 拆,拆名字复用 `sources.seesaa.split_names`,不另存。
测试与集成复用 `test_runner.py`、`agent_worktree.py`;进程互斥采用开发依赖
`filelock==3.32.4` 的 `FileLock`([官方用法](https://py-filelock.readthedocs.io/en/stable/tutorials.html))。
diff --git a/docs/adr/0069-performer-page-header-shows-five-facts-and-grouped-names.md b/docs/adr/0069-performer-page-header-shows-five-facts-and-grouped-names.md
new file mode 100644
index 000000000..2240e6263
--- /dev/null
+++ b/docs/adr/0069-performer-page-header-shows-five-facts-and-grouped-names.md
@@ -0,0 +1,41 @@
+# ADR-0069:女优页头展示五项资料,别名按名义分组
+
+- 状态:Accepted
+- 日期:2026-09-25
+- 沿用:ADR-0067「女优资料落 `performer_profile` 单表」
+
+## 背景
+
+ADR-0067 把 minnano-av 资料表落进了 `performer_profile`,当时写明「界面暂不展示这些资料」。
+女优页头只有名字、别名和外链;生日、身材、出道作、出演期间这些认人用的资料,账本里有了,页上看不到。
+
+资料页「別名」一栏的写法带着渠道注记与读音,例如 `橋本真紀(舞ワイフ)`、`篠崎ゆう子 (しのざきゆうこ / …)`。
+页头把别名排成一串,分不出哪些是旧名义、哪些是某个渠道起的名字。
+
+## 决策
+
+**一、页头只展示五项**:生日与年龄、身材(身高、三围、罩杯)、出道(日期与片名)、出演期间、站上的标签。
+它们放在页头右侧的资料表里,宽屏下和身份信息之间隔一道竖线;900px 以下排到身份信息下面。
+血型、出身地、趣味、博客都在账本里,但不上页头。页头是用来认人的,这五项回答「她是谁、什么体型、
+什么时候出道、还拍不拍」;再多几项,资料表会比身份信息高出一截,头像两侧留空。
+取不到的项服务端不下发,页面也就不画那一格,不写「未取得」。
+
+**二、别名按名义分组。** 名字下面那一行是读音加前三个名字,其余收进「+N」浮层,分组如下:
+现名(资料页主名)、旧名义(没有注记的别名)、各渠道名义(按人数从多到少)、其它(账本里有、页上没列的写法)。
+注记不另存:`performer_profile.raw_json` 的「別名」原文里就有,读的时候用 `minnano_av.name_entries` 拆。
+页面主名不在资料表里,`minnano_av.profile` 把它记在原文的「名前」下。
+
+- `r18:performer` 的条目是读音与罗马字,不是艺名;`javinizer:planning-alias` 是作品给她起的一次性称呼
+ (ADR-0038 有意登记,检索要用)。两种都不上页头,账本里照留。
+- 规范名是中日文写法时,纯拉丁写法不列,与 `display_aliases` 同一条规则。
+- 读音只出一次,排在最前:优先取资料页上的读音;没有资料时,取别名里纯平假名的那条。
+
+**三、只读,不新增写入方。** 页头的视图在 `performer_header`,只读 `performer_profile` 与 `entity_alias`;
+资料照旧只由补女优资料后继写,撤回照旧走 `revert_auto_landing.py`。
+
+## 后果
+
+- 迁移 `0036` 应用之前账本里没有这张表,女优页照常打开,页头只是没有资料表,名字行只用账本别名。
+- 补女优资料后继取到一位,她的页头就多出右侧资料表和分组别名;没取到的只有名字行和图标外链。
+- `performer_profile` 只存一段出演期间(`debut_year` 到 `active_until`)。站上写了几段的(`2015年〜2018年、2019年〜`),
+ 规整规则只读第一段,页头会显示成已结束;要改得改 `minnano_av.profile`,原文在 `raw_json` 里,可以就地重算。
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
index dcbc204ee..224abecc0 100644
--- a/scripts/test_runner.py
+++ b/scripts/test_runner.py
@@ -183,6 +183,9 @@ AUTO_SCOPE_FILES: dict[str, tuple[str, ...]] = {
# 补女优资料后继的解析与读写层,测试都在 `test_performer_profile_followup.py`。
"src/peach/avwikidb.py": ("metadata",),
"src/peach/performer_profiles.py": ("metadata",),
+ # 女优页头的视图:主体测试在 `test_performer_header.py`(metadata),资料接口与骨架
+ # 形状的用例在 catalog 与 web 两个域里经 `q_entity` 读它。
+ "src/peach/performer_header.py": ("metadata", "catalog", "web"),
# 推送发现横跨扫描登记(tooling)与 HTTP 端点(catalog),按名字只推得出一个域。
"src/peach/push_discovery.py": ("tooling", "catalog"),
# 入口页共用件的测试住在首启与配置来源那两份 tooling 测试里。
diff --git a/src/peach/minnano_av.py b/src/peach/minnano_av.py
index b5481ac0b..659d5c0fe 100644
--- a/src/peach/minnano_av.py
+++ b/src/peach/minnano_av.py
@@ -180,7 +180,7 @@ def profile(html: str) -> dict | None:
"""资料页 → 结构化资料;不是资料页返回 None。
固定列见 `PROFILE_COLUMNS`,另有 `actress_id`、`name`、`tags`(站上的标签,按页上顺序)
- 与 `raw`(资料表每一格的原文,`別名` 那几行是列表)。只读 `act-profile` 那一块,作品与
+ 与 `raw`(资料表每一格的原文,`別名` 那几行是列表,`名前` 是 `<h1>` 里的主名)。只读 `act-profile` 那一块,作品与
评论里的同名格子不算。逐格的规则:
- 读音与罗马字取 `<h1>` 里 `<span>` 那段 `かな / Romaji`,缺哪半就留空。
@@ -211,8 +211,10 @@ def profile(html: str) -> dict | None:
continue
cells.setdefault(label, value)
raw.setdefault(label, _text(value))
- result: dict = {"actress_id": found_id,
- "name": _text(_SPAN.sub("", heading.group(1))) if heading else "",
+ name = _text(_SPAN.sub("", heading.group(1))) if heading else ""
+ if name:
+ raw["名前"] = name
+ result: dict = {"actress_id": found_id, "name": name,
"kana": kana or None, "romaji": romaji or None}
result["birth_date"] = _iso_date(_text(cells.get("生年月日", "")))
result.update(dict.fromkeys(("height_cm", "bust_cm", "cup", "waist_cm", "hip_cm")))
@@ -243,6 +245,70 @@ def profile_text(html: str, label: str) -> str:
return ""
+#: 资料表里一格名字后面的括号:读音(`(しのざきゆうこ / Shinozaki Yuuko)`)或注记
+#: (`(舞ワイフ)`、`(東京熱)`)。站上全半角括号混着写,`(ラグジュTV)` 这种一半一半的也有。
+_PAREN = re.compile(r"[((【]([^(())【】]*)[))】]")
+_KANA_READING = re.compile(r"^[぀-ゟ゠-ヿ\s]*$")
+#: 这些注记说的是「这是她的旧名字」,不是哪个渠道:归到旧名义,不单列一组。
+_FORMER_NOTES = {"旧名", "旧名義", "旧芸名", "旧"}
+
+
+def _note(text: str) -> str:
+ note = re.sub(r"\s+", " ", text).strip().removesuffix("名義").strip()
+ return "" if note in _FORMER_NOTES else note
+
+
+def name_entries(cell: str) -> list[dict]:
+ """「別名」一格的原文 → [{name, reading, romaji, note}],一个写法一项。
+
+ 格子的形状是 `写法(注记) (读音 / 罗马字)`:带斜杠的那组括号是读音,其余括号是注记,
+ 说的是这个名字挂在哪个渠道(`舞ワイフ`、`ラグジュTV`)或哪家店。注记本身是边界:
+ `橋本真紀&桧山彩音(舞ワイフ名義)` 里两个名字共用一条注记,拆名字的规则与 av_neme
+ 同一套(`sources.seesaa.split_names`:`&`、`、`、`/`,片假名外国人名里的 `・` 不拆)。
+
+ 读音那组括号里左半不是假名时(`あいな (吉原ソープ 薔薇の園 / Aina)`),站上把店名填进了
+ 读音栏,按注记收。一格里拆出不止一个名字时读音不知道归谁,都不挂。
+ """
+ from .sources.seesaa import split_names
+
+ text = _text(cell)
+ groups = list(_PAREN.finditer(text))
+ reading_at = next((index for index in range(len(groups) - 1, -1, -1)
+ if "/" in groups[index].group(1)), -1)
+ reading = romaji = reading_note = ""
+ if reading_at >= 0:
+ left, _, right = groups[reading_at].group(1).partition("/")
+ romaji = right.strip()
+ if _KANA_READING.match(left):
+ reading = re.sub(r"\s+", "", left)
+ else:
+ reading_note = _note(left)
+ entries: list[dict] = []
+ pending: list[dict] = []
+ cursor = 0
+ for index, group in enumerate([*groups, None]):
+ end = group.start() if group else len(text)
+ for name in split_names(text[cursor:end]):
+ entry = {"name": name, "reading": "", "romaji": "", "note": ""}
+ entries.append(entry)
+ pending.append(entry)
+ if group is None:
+ break
+ cursor = group.end()
+ if index == reading_at:
+ continue
+ note = _note(group.group(1))
+ for entry in pending:
+ entry["note"] = note
+ pending = []
+ if reading_note:
+ for entry in entries:
+ entry["note"] = entry["note"] or reading_note
+ if len(entries) == 1:
+ entries[0].update(reading=reading, romaji=romaji)
+ return entries
+
+
def production_ref(html: str) -> tuple[str, str]:
"""女优页的「所属事務所」→ (站内编号, 站上写的事务所名);这一格没有链接就是 ("", "")。
diff --git a/src/peach/performer_header.py b/src/peach/performer_header.py
new file mode 100644
index 000000000..5758b61b8
--- /dev/null
+++ b/src/peach/performer_header.py
@@ -0,0 +1,193 @@
+"""女优页头要的两样东西:五项资料(`profile`)与按名义分组的别名(`name_groups`)(ADR-0069)。
+
+资料取自 `performer_profile`(ADR-0067),这里只读不写。页头只给五项:生日与年龄、身材、
+出道、出演期间、站上的标签。血型、出身地、趣味这些在账本里,不上页头:页头是认人用的,
+一行放不下的东西放进去只会把这五项挤成两行。取不到的项不给,前端也就不画那一格,
+不写「未取得」。
+
+别名分组的口径:
+
+- `r18:performer` 的条目是读音与罗马字,不是艺名;`javinizer:planning-alias` 是作品给她起的
+ 一次性称呼(ADR-0038 有意登记,检索要用)。两种都不上页头,账本里照留。
+- 规范名是中日文写法时,纯拉丁写法不列(与 `display_aliases` 同一条)。
+- 读音只出一次:资料页的读音优先,没有资料时取别名里那条纯平假名的写法。与读音、
+ 与规范名同键的写法都不再列。
+- 有资料时按页上的名义分组:现名(资料页主名)、旧名义(没有渠道注记的别名)、各渠道
+ 名义(按人数从多到少)、其它(账本里有、页上没列的写法)。没有资料时只有一组,不带标题。
+ 页上的注记在 `raw_json` 的「別名」原文里,读的时候用 `minnano_av.name_entries` 拆。
+"""
+from __future__ import annotations
+
+import re
+import sqlite3
+from datetime import date
+
+from .entities import normalize_entity_name
+from .kanji import fold_glyphs
+from .metadata_alias_resolve import PLANNING_ALIAS_SOURCE
+from .minnano_av import name_entries
+from .performer_profiles import TABLE, read_profile
+from .social_links import name_key
+
+#: 不上页头的别名来源。
+HIDDEN_SOURCES = frozenset({"r18:performer", PLANNING_ALIAS_SOURCE})
+#: 名字那一行在读音之后先列几个。
+SHOWN = 3
+CURRENT, FORMER, OTHER = "现名", "旧名义", "其它"
+#: 身材一格的列 → 页头的键。
+_BODY = (("height_cm", "height"), ("bust_cm", "bust"), ("waist_cm", "waist"),
+ ("hip_cm", "hip"), ("cup", "cup"))
+
+_EAST_ASIAN = re.compile(r"[぀-ヿ㐀-鿿]")
+_LATIN = re.compile(r"[A-Za-z]")
+_HIRAGANA = re.compile(r"^[ぁ-ゟー\s]+$")
+
+
+def _key(name: str) -> str:
+ return fold_glyphs(name_key(name))
+
+
+def age_on(birth: str, today: date) -> int | None:
+ try:
+ born = date.fromisoformat(birth)
+ except (TypeError, ValueError):
+ return None
+ return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
+
+
+def facts(row: dict | None, today: date) -> dict:
+ """页头那五项要的值,只放有的。`row` 是 `read_profile` 交回的一行。"""
+ row = row or {}
+ found: dict = {}
+ birth = str(row.get("birth_date") or "")
+ age = age_on(birth, today) if birth else None
+ if age is not None:
+ found.update(birth_date=birth, age=age)
+ found.update({key: row[column] for column, key in _BODY if row.get(column)})
+ for key in ("debut_date", "debut_title"):
+ if row.get(key):
+ found[key] = row[key]
+ if row.get("debut_year"):
+ until = row.get("active_until")
+ found["active"] = {"from": row["debut_year"],
+ **({"to": until} if until else {"ongoing": True})}
+ tags = [str(tag) for tag in row.get("tags") or [] if str(tag).strip()]
+ if tags:
+ found["tags"] = tags
+ return found
+
+
+def page_names(row: dict | None) -> dict:
+ """资料页上的名字:{name, reading, aliases};`aliases` 一个写法一项,带着渠道注记。"""
+ if not row:
+ return {"name": "", "reading": "", "aliases": []}
+ raw = row.get("raw") or {}
+ cells = raw.get("別名") or []
+ return {"name": str(raw.get("名前") or ""),
+ "reading": re.sub(r"\s+", "", str(row.get("kana") or "")),
+ "aliases": [entry for cell in cells for entry in name_entries(str(cell))]}
+
+
+def _alias_sources(connection: sqlite3.Connection, entity_id: int) -> dict[str, tuple[str, set]]:
+ """归一键 → (写法, 这个写法登记过的全部来源)。同一个写法按来源分行,这里并回一条。"""
+ found: dict[str, tuple[str, set]] = {}
+ for alias, source in connection.execute(
+ "SELECT alias,source FROM entity_alias WHERE entity_id=? ORDER BY confidence DESC,alias",
+ (int(entity_id),)):
+ entry = found.setdefault(normalize_entity_name(str(alias)), (str(alias), set()))
+ entry[1].add(str(source).partition("@")[0])
+ return found
+
+
+def _reading(page: dict, ledger: dict[str, tuple[str, set]]) -> str:
+ """读音:资料页上的那个;没有资料时取别名里纯平假名的那条,`r18:performer` 的在前。"""
+ if page["reading"]:
+ return page["reading"]
+ kana = sorted((name for name, _sources in ledger.values() if _HIRAGANA.match(name)),
+ key=lambda name: "r18:performer" not in ledger[normalize_entity_name(name)][1])
+ return kana[0] if kana else ""
+
+
+def page_sections(page: dict, reading: str) -> list[tuple[str, list[dict]]]:
+ """资料页上的名义,按页头的组排好:现名、旧名义、各渠道名义(人多的在前)。"""
+ aliases = page["aliases"]
+ notes: dict[str, list[dict]] = {}
+ for entry in aliases:
+ if entry.get("note"):
+ notes.setdefault(entry["note"], []).append({"name": entry["name"]})
+ return [(CURRENT, [{"name": page["name"], "reading": reading}]),
+ (FORMER, [{"name": entry["name"], "reading": entry.get("reading", "")}
+ for entry in aliases if not entry.get("note")]),
+ *sorted(notes.items(), key=lambda item: -len(item[1]))]
+
+
+class _Groups:
+ """往页头的组里一个个放名字:同键的只放一次,中日文规范名下不放纯拉丁写法。"""
+
+ def __init__(self, canonical: str, reading: str):
+ self.east_asian = bool(_EAST_ASIAN.search(canonical or ""))
+ self.taken = {_key(canonical), _key(reading)} - {""}
+ self.groups: list[dict] = []
+
+ def keep(self, name: str) -> bool:
+ key = _key(name)
+ if not name or key in self.taken:
+ return False
+ if self.east_asian and _LATIN.search(name) and not _EAST_ASIAN.search(name):
+ return False
+ self.taken.add(key)
+ return True
+
+ def add(self, label: str, entries: list[dict]) -> None:
+ names = [entry for entry in entries if self.keep(entry["name"])]
+ if names:
+ self.groups.append({"label": label, "names": names})
+
+
+def name_groups(connection: sqlite3.Connection, entity_id: int, canonical: str,
+ page: dict) -> dict | None:
+ """名字那一行与「+N」浮层要的 {reading, shown, total, groups};一个名字都没有返回 None。
+
+ `shown` 是名字那一行在读音之后列的几个:先按资料页上的顺序(主名、别名栏自上而下),
+ 再接账本里另有的写法。
+ """
+ ledger = _alias_sources(connection, entity_id)
+ reading = _reading(page, ledger)
+ sorter = _Groups(canonical, reading)
+ for label, entries in page_sections(page, reading) if page["name"] or page["aliases"] else []:
+ sorter.add(label, entries)
+ order = {name: index for index, name in enumerate(
+ [page["name"], *(entry["name"] for entry in page["aliases"])])}
+ on_page = sorted((entry["name"] for group in sorter.groups for entry in group["names"]),
+ key=lambda name: order.get(name, len(order)))
+ sorter.add(OTHER if sorter.groups else "",
+ [{"name": name} for name, sources in ledger.values() if not sources <= HIDDEN_SOURCES])
+ if not sorter.groups and not reading:
+ return None
+ everyone = on_page + [entry["name"] for group in sorter.groups
+ if group["label"] in (OTHER, "") for entry in group["names"]]
+ return {"reading": reading, "shown": everyone[:SHOWN], "total": len(everyone),
+ "groups": sorter.groups}
+
+
+def _has_table(connection: sqlite3.Connection) -> bool:
+ """迁移 `0036` 应用之前账本里没有这张表:页头照常出,只是没有资料。"""
+ return connection.execute("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?",
+ (TABLE,)).fetchone() is not None
+
+
+def profiled(connection: sqlite3.Connection) -> set[int]:
+ """有资料行的女优;骨架据此给页头右侧留出资料表的位置。"""
+ if not _has_table(connection):
+ return set()
+ return {int(row[0]) for row in connection.execute(
+ f"SELECT p.entity_id FROM {TABLE} p JOIN entity e ON e.id=p.entity_id"
+ " AND e.kind='performer'")}
+
+
+def header(connection: sqlite3.Connection, entity_id: int, canonical: str,
+ today: date | None = None) -> dict:
+ """`q_entity` 给女优页并进去的两项。"""
+ row = read_profile(connection, entity_id) if _has_table(connection) else None
+ return {"profile": facts(row, today or date.today()),
+ "name_groups": name_groups(connection, entity_id, canonical, page_names(row))}
diff --git a/src/peach/web_entity.py b/src/peach/web_entity.py
index 468e3c114..f55eeb3dc 100644
--- a/src/peach/web_entity.py
+++ b/src/peach/web_entity.py
@@ -14,7 +14,7 @@ import time
from urllib.parse import urlsplit
-from . import entry_links, feeds, web_feeds
+from . import entry_links, feeds, performer_header, web_feeds
from .catalog_rules import LENGTH_TAGS, dir_expr, photo_set_title, solo_performer_clause, tag_cat
from .entities import normalize_entity_name, resolve_entity, rewrite_flat_projection
from .social_links import ARCHIVE_HOSTS, is_archive
@@ -165,6 +165,9 @@ def q_entity(contract: WebContract, args):
)]
d.update(_performer_entries(contract, c, d, alias_rows) if kind == "performer"
else {"entry_links": []})
+ # 页头的五项资料与按名义分组的别名(ADR-0069):只有女优有。
+ if kind == "performer":
+ d.update(performer_header.header(c, d["id"], d["canonical_name"]))
scope = scope_predicate(kind, "ae.entity_id")
count, rep = c.execute(
"SELECT count(DISTINCT ae.asset_id),"
@@ -274,7 +277,8 @@ def agency_mark_link(links: list[dict]) -> int | None:
def q_entity_shapes(contract, args) -> dict:
- """资料页上可有可无的那几块,哪些实体有:新作那一行(`feed`)、卡底的同台艺人(`costars`)。
+ """资料页上可有可无的那几块,哪些实体有:新作那一行(`feed`)、卡底的同台艺人(`costars`)、
+ 页头右侧那张资料表(`facts`,ADR-0069)。
骨架在资料到达之前就要照最终形状画:不留位,那一块画出来时从中间顶进来;每页都
留,没有的那一页又得在画出来时收掉。两块各有一半上下的页面有,猜哪一边都有一半在
@@ -290,6 +294,8 @@ def q_entity_shapes(contract, args) -> dict:
" JOIN asset_entity co ON co.asset_id=scope.asset_id AND co.entity_id<>scope.entity_id"
" JOIN entity person ON person.id=co.entity_id AND person.kind='performer'"):
parts.setdefault(int(row[0]), []).append("costars")
+ for entity_id in performer_header.profiled(connection):
+ parts.setdefault(entity_id, []).append("facts")
entities = {int(row["id"]): {"id": int(row["id"]), "kind": row["kind"],
"names": [row["canonical_name"]], "parts": parts[int(row["id"])]}
for row in connection.execute("SELECT id, kind, canonical_name FROM entity ORDER BY id")
diff --git a/tests/test_performer_header.py b/tests/test_performer_header.py
new file mode 100644
index 000000000..bc45b44ed
--- /dev/null
+++ b/tests/test_performer_header.py
@@ -0,0 +1,181 @@
+"""女优页头:五项资料与按名义分组的别名(ADR-0069),读的是 `performer_profile`(ADR-0067)。
+
+全程临时账本,不联网。资料行由补女优资料后继的写入函数写下,页面是 minnano-av 504478
+(篠田ゆう)与 494354(釈アリス)的真实页面裁剪而成,只留解析会读到的 canonical、`<h1>`
+与资料表。
+"""
+import sqlite3
+import tempfile
+import unittest
+from datetime import date
+from pathlib import Path
+
+from peach import minnano_av, performer_header
+from peach import web_contract as rm_web
+from peach.entities import normalize_entity_name
+from peach.performer_profiles import write_profile
+from peach.web_entity import q_entity_shapes
+from support.ledger import fresh_ledger
+
+STAMP = "2026-09-24T00:00:00.000Z"
+TODAY = date(2026, 9, 25)
+
+SHINODA = """<!doctype html><html lang="ja"><head>
+<link rel="canonical" href="https://www.minnano-av.com/actress504478.html">
+</head><body>
+<h1>篠田ゆう<span>しのだゆう / Shinoda Yu</span></h1>
+<div class="act-profile">
+<table width="100%" cellspacing="0" cellpadding="0" border="0">
+<tr><td><h2>篠田ゆう (しのだゆう / Shinoda Yu)</h2></td></tr>
+<tr><td><span>別名</span><p>篠崎ゆう子 (しのざきゆうこ / Shinozaki Yuuko)</p></td></tr>
+<tr><td><span>別名</span><p>高木早希(ラグジュTV) (たかぎさき / Takagi Saki)</p></td></tr>
+<tr><td><span>別名</span><p>桧山彩音(舞ワイフ) (ひやまあやね / Hiyama Ayane)</p></td></tr>
+<tr><td><span>別名</span><p>橋本真紀(舞ワイフ) (はしもとまき / Hashimoto Maki)</p></td></tr>
+<tr><td><span>別名</span><p>篠田杏奈(舞ワイフ) (しのだあんな / Shinoda Anna)</p></td></tr>
+<tr><td><span>生年月日</span><p>1991年07月21日
+ (現在 <a href="actress_list.php?birthday=1991-07-21">35歳</a>)かに座</td> </p></td></tr>
+<tr><td><span>サイズ</span><p>T155 / B86(<a href="actress_list.php?cup=F">Fカップ</a>) / W60 / H87 / S22</p></td></tr>
+<tr><td><span>血液型</span><p><a href="actress_list.php?blood_type=O">O型</a></p></td></tr>
+<tr><td><span>AV出演期間</span><p>2010年~2023年</p></td></tr>
+<tr><td><span>デビュー作品</span><p>セキララ 〜今どき世代のゆるい性事情〜 03(2010年12月 02日)</p></td></tr>
+<tr valign="top"><td><span>タグ</span><div class="tagarea">
+<a href="actress_list.php?tag_a_id=28">美乳</a>
+<a href="actress_list.php?tag_a_id=43">美尻</a>
+<a href="actress_list.php?tag_a_id=238">レズ</a>
+</td></tr>
+</table></div></body></html>"""
+
+ALICE = """<!doctype html><html lang="ja"><head>
+<link rel="canonical" href="https://www.minnano-av.com/actress494354.html">
+</head><body>
+<h1>釈アリス<span>しゃくありす / Shaku Alice</span></h1>
+<div class="act-profile">
+<table width="100%" cellspacing="0" cellpadding="0" border="0">
+<tr><td><span>サイズ</span><p>T169 / B88(<a href="actress_list.php?cup=E">Eカップ</a>) / W57 / H95 / S</p></td></tr>
+<tr><td><span>AV出演期間</span><p>2024年-</p></td></tr>
+</table></div></body></html>"""
+
+
+class NameEntryTests(unittest.TestCase):
+ def test_alias_cells_split_names_and_carry_their_channel_note(self):
+ self.assertEqual(
+ [(entry["name"], entry["note"], entry["reading"]) for entry in
+ minnano_av.name_entries("<p>橋本真紀&amp;桧山彩音(舞ワイフ名義)</p>")],
+ [("橋本真紀", "舞ワイフ", ""), ("桧山彩音", "舞ワイフ", "")])
+ # 读音栏里填的是店名:按注记收,不当读音。
+ self.assertEqual(minnano_av.name_entries("<p>あいな (吉原ソープ 薔薇の園 / Aina)</p>"),
+ [{"name": "あいな", "reading": "", "romaji": "Aina",
+ "note": "吉原ソープ 薔薇の園"}])
+ self.assertEqual(minnano_av.name_entries("美雲そら【旧名】 (みくもそら / Mikumo Sora)")[0]
+ ["note"], "")
+
+ def test_the_raw_cells_keep_the_main_name_of_the_page(self):
+ """现名那一组要页面主名;它不在资料表里,另记在原文的「名前」下。"""
+ self.assertEqual(minnano_av.profile(SHINODA)["raw"]["名前"], "篠田ゆう")
+
+
+class Case(unittest.TestCase):
+ def setUp(self):
+ temporary = tempfile.TemporaryDirectory()
+ self.addCleanup(temporary.cleanup)
+ self.root = Path(temporary.name).resolve()
+ self.db = fresh_ledger(self.root)
+ self.connection = sqlite3.connect(self.db)
+ self.addCleanup(self.connection.close)
+
+ def entity(self, name: str, *aliases) -> int:
+ with self.connection:
+ cursor = self.connection.execute(
+ "INSERT INTO entity(kind,canonical_name,normalized_name,created_at,updated_at)"
+ " VALUES('performer',?,?,?,?)", (name, normalize_entity_name(name), STAMP, STAMP))
+ entity_id = int(cursor.lastrowid)
+ for written, source in aliases:
+ self.connection.execute(
+ "INSERT INTO entity_alias(entity_id,alias,normalized_alias,source)"
+ " VALUES(?,?,?,?)", (entity_id, written, normalize_entity_name(written), source))
+ return entity_id
+
+ def land(self, entity_id: int, page: str) -> None:
+ with self.connection:
+ write_profile(self.connection, entity_id, minnano_av.profile(page),
+ source="auto:performer-profile@1", source_url="https://example.invalid/",
+ fetched_at=STAMP)
+
+ def header(self, entity_id: int, canonical: str) -> dict:
+ return performer_header.header(self.connection, entity_id, canonical, today=TODAY)
+
+
+class HeaderTests(Case):
+ def test_five_facts_and_the_name_groups_of_the_header(self):
+ shinoda = self.entity(
+ "篠田优", ("篠田ゆう", "avdb"), ("Yu Shinoda", "r18:performer"),
+ ("しのだゆう", "r18:performer"), ("篠田杏奈", "user:alias"), ("城田優子", "auto:x@1"),
+ ("ゆうちゃん企画", "javinizer:planning-alias"))
+ self.land(shinoda, SHINODA)
+ head = self.header(shinoda, "篠田优")
+ self.assertEqual(head["profile"], {
+ "birth_date": "1991-07-21", "age": 35, "height": 155, "bust": 86, "waist": 60,
+ "hip": 87, "cup": "F", "debut_date": "2010-12-02",
+ "debut_title": "セキララ 〜今どき世代のゆるい性事情〜 03",
+ "active": {"from": 2010, "to": 2023}, "tags": ["美乳", "美尻", "レズ"]})
+ groups = head["name_groups"]
+ self.assertEqual(groups["reading"], "しのだゆう")
+ self.assertEqual(groups["shown"], ["篠田ゆう", "篠崎ゆう子", "高木早希"])
+ self.assertEqual(groups["total"], 7)
+ self.assertEqual([(group["label"], [entry["name"] for entry in group["names"]])
+ for group in groups["groups"]],
+ [("现名", ["篠田ゆう"]), ("旧名义", ["篠崎ゆう子"]),
+ ("舞ワイフ", ["桧山彩音", "橋本真紀", "篠田杏奈"]),
+ ("ラグジュTV", ["高木早希"]), ("其它", ["城田優子"])])
+ self.assertEqual(groups["groups"][0]["names"][0]["reading"], "しのだゆう")
+
+ def test_an_open_ended_period_is_still_active(self):
+ alice = self.entity("释爱丽丝")
+ self.land(alice, ALICE)
+ profile = self.header(alice, "释爱丽丝")["profile"]
+ self.assertEqual(profile["active"], {"from": 2024, "ongoing": True})
+ self.assertEqual((profile["height"], profile["cup"]), (169, "E"))
+ self.assertNotIn("birth_date", profile)
+
+ def test_without_a_profile_the_ledger_aliases_form_one_untitled_group(self):
+ alice = self.entity("释爱丽丝", ("Alice Shaku", "avdb"), ("しゃくありす", "avdb"),
+ ("釈アリス", "avdb"))
+ head = self.header(alice, "释爱丽丝")
+ self.assertEqual(head["profile"], {})
+ self.assertEqual(head["name_groups"], {
+ "reading": "しゃくありす", "shown": ["釈アリス"], "total": 1,
+ "groups": [{"label": "", "names": [{"name": "釈アリス"}]}]})
+
+ def test_age_turns_on_the_birthday(self):
+ self.assertEqual(performer_header.age_on("1991-07-21", date(2026, 7, 20)), 34)
+ self.assertEqual(performer_header.age_on("1991-07-21", date(2026, 7, 21)), 35)
+ self.assertIsNone(performer_header.age_on("1991-07", date(2026, 7, 21)))
+
+ def test_a_ledger_before_migration_0036_still_serves_the_header(self):
+ shinoda = self.entity("篠田优", ("篠田ゆう", "avdb"))
+ with self.connection:
+ self.connection.execute("DROP TABLE performer_profile")
+ head = self.header(shinoda, "篠田优")
+ self.assertEqual(head["profile"], {})
+ self.assertEqual(head["name_groups"]["shown"], ["篠田ゆう"])
+ self.assertEqual(performer_header.profiled(self.connection), set())
+
+
+class ApiTests(Case):
+ def test_the_entity_api_and_the_skeleton_shapes_carry_the_profile(self):
+ shinoda = self.entity("篠田优", ("篠田ゆう", "avdb"))
+ self.land(shinoda, SHINODA)
+ (self.root / "logos").mkdir()
+ (self.root / "avatars").mkdir()
+ contract = rm_web.WebContract(self.db, avatar_root=self.root / "avatars",
+ logo_root=self.root / "logos")
+ page = rm_web.q_entity(contract, {"kind": "performer", "name": "篠田优"})
+ self.assertEqual(page["profile"]["cup"], "F")
+ self.assertEqual(page["name_groups"]["shown"][0], "篠田ゆう")
+ shapes = q_entity_shapes(contract, {})
+ parts = {item["id"]: item["parts"] for item in shapes["entities"]}
+ self.assertIn("facts", parts[shinoda])
+
+
+if __name__ == "__main__":
+ unittest.main()