Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(entity): 复核表改了链接 label 重跑即对齐,只剩存档的事务所能按指定字标取标识

longmeidao6dd16e38476e
diff --git a/docs/SOURCING.md b/docs/SOURCING.md
index 4f79c4d35..47f2d5a40 100644
--- a/docs/SOURCING.md
+++ b/docs/SOURCING.md
@@ -569,8 +569,10 @@ av911.tv,三条候选已进复核队列。
- 官网取成员 official 链接里标签等于本家名字的那些,用它们的域名根地址,不用某位女优的个人页:
那是她的页面,不是这家公司的首页。名字拆过之后要按原文再查一次,否则 `ACT(アクト)` 这类明明有站却查不到。
- 现站打不开的公司,官网可以登记 Wayback 快照:link_kind 仍是 `official`,url 写完整的
- `web.archive.org/web/<时间戳>/<原址>`,label 写 `<公司名> 官网存档(YYYY-MM)`,优先所属名单页。
- `peach.social_links.ARCHIVE_HOSTS` 让域名归属、事务所门面圆标和厂牌标识采集都跳过它。
+ `web.archive.org/web/<时间戳>/<原址>`,label 写 `官网存档(YYYY-MM)`,优先所属名单页。label 不带
+ 公司名:这条链接只挂在这家自己的资料页上,页头就是名字。`peach.social_links.ARCHIVE_HOSTS` 让域名
+ 归属、事务所门面圆标和厂牌标识采集都跳过它;标识要从快照取,把快照里那张图的 `id_` 原件地址登记
+ 进 `harvest_studio_icons.py` 的指定来源表。复核表改了 label 重跑 `install_entity_links.py` 即对齐。
- 判词四种:`ok` 进装入队列、`已有`(同平台同 handle,不分主机写法与大小写)、`conflict`(账本同平台是
另一个 handle)、`未取得`(页面失败或没有社媒)。
- 来源本身可能是过期数据:目录站抄的 X 账号很多已封停、本人早换新号,所以 X 的 `ok`/`conflict` 行都用
diff --git a/scripts/harvest_studio_icons.py b/scripts/harvest_studio_icons.py
index 7004552d6..2fb460823 100644
--- a/scripts/harvest_studio_icons.py
+++ b/scripts/harvest_studio_icons.py
@@ -290,9 +290,14 @@ ICON_SOURCES: dict[str, str] = {
#: `Luminous Promotion`:2022 年由 BELLTECH 改屋号,账本 official 里旧站
#: `belltech-pro.com` 排在前面,自动发现取到的是旧屋号字标。新站 header 是 1741×532
#: 的透明底字标(2026-09-23 实测)。
+#:
+#: `ONE'S DOUBLE`:现站 SSL 连不上,官网只剩 Wayback 快照。字标是快照页脚那张 216×30
+#: 的黑色 SVG,取 `id_` 原件,不带存档站注入的工具栏(2026-09-24 实测)。
AGENCY_WORDMARK_SOURCES: dict[str, str] = {
"Diaz Group": "https://diaz-g.com/assets/img/diaz_logo.svg",
"Luminous Promotion": "https://luminous-pro.tokyo/img/logo.png",
+ "ONE'S DOUBLE": "https://web.archive.org/web/20220130000436id_/"
+ "https://ones-double.com/wp/assets/img/footer-logo.svg",
}
@@ -477,10 +482,12 @@ def studio_links(connection: sqlite3.Connection,
" ORDER BY e.canonical_name, l.id", (kind, *kinds)).fetchall()
grouped: dict[str, list[dict[str, str]]] = {}
for row in rows:
- # 存档快照上取到的是存档站自己的图标。
+ entries = grouped.setdefault(safe_name(row["canonical_name"]), [])
+ # 存档快照上取到的是存档站自己的图标,这条链接不当图源;公司照样留在名单里,
+ # 关门的公司官网只剩这一份,指定字标还要按名字去取。
if is_archive(row["url"]):
continue
- grouped.setdefault(safe_name(row["canonical_name"]), []).append(
+ entries.append(
{"entity_id": row["id"], "studio": row["canonical_name"],
"link_kind": row["link_kind"], "url": row["url"]})
return {safe: [entry for entry in entries if entry["link_kind"] in ICON_LINK_KINDS]
@@ -885,7 +892,7 @@ def icon_row(safe: str, target: dict[str, str], entries: list[dict[str, str]],
"""
if not entries:
return _row(safe, target, None, ICON, SKIP,
- evidence="账本里这个厂牌一条链接都没有"), None
+ evidence="账本里这个厂牌没有能取图的链接(存档快照不算)"), None
attempts: list[str] = []
reachable = False
policy = SquareMark(faces)
diff --git a/scripts/install_entity_links.py b/scripts/install_entity_links.py
index 8c5831520..a2be3b262 100644
--- a/scripts/install_entity_links.py
+++ b/scripts/install_entity_links.py
@@ -37,6 +37,8 @@ from peach.scripting import ( # noqa: E402
LINK_KINDS = {"official", "social", "catalog", "source_reference"}
FIELDS = ("entity_id", "kind", "name", "link_kind", "label", "url", "evidence")
+#: 计划清单每行开头那一格:`+` 新写入,`~` 改 label,空格是跳过。
+ACTION_MARKS = {"insert": "+", "relabel": "~"}
def normalise_url(url: str) -> str:
@@ -84,6 +86,9 @@ def plan(connection: sqlite3.Connection, rows: list[dict]) -> list[dict]:
不合法的行不会被悄悄跳过——它们照样出现在计划里,动作写成 skip 并说明原因。
静默丢行会让「装了 40 条」和「表里有 40 条」这两个数字对不上,而没人知道差在哪。
+
+ 已在库里的链接按复核表的 label 对齐(`relabel`):label 是资料页上的链接文字,
+ 复核表是它唯一的出处,表里改了字重跑就该生效,而不是报「已存在」后原样留着。
"""
planned: list[dict] = []
for row in rows:
@@ -95,23 +100,36 @@ def plan(connection: sqlite3.Connection, rows: list[dict]) -> list[dict]:
entity_id, note = resolve_entity(connection, row)
item.update(entity_id=entity_id, link_kind=link_kind, url=url,
label=str(row.get("label") or "").strip())
- if entity_id is None:
- item["reason"] = note
- elif link_kind not in LINK_KINDS:
- item["reason"] = f"link_kind 「{link_kind}」不在 {sorted(LINK_KINDS)} 内"
- elif not url or urlsplit(url).scheme not in {"http", "https"}:
- item["reason"] = f"URL 不可用:{url or '空'}"
- elif not item["label"]:
- item["reason"] = "没有 label;资料页要拿它当链接文字"
- elif connection.execute("SELECT 1 FROM entity_link WHERE entity_id=? AND url=?",
- (entity_id, url)).fetchone():
- item["reason"] = "已存在,跳过"
- else:
+ invalid = row_problem(entity_id, note, link_kind, url, item["label"])
+ stored = None if invalid else connection.execute(
+ "SELECT label FROM entity_link WHERE entity_id=? AND url=?",
+ (entity_id, url)).fetchone()
+ if invalid:
+ item["reason"] = invalid
+ elif stored is None:
item.update(action="insert", reason=note)
+ elif stored[0] != item["label"]:
+ item.update(action="relabel", reason=f"已存在,label 对齐复核表(库内「{stored[0]}」)")
+ else:
+ item["reason"] = "已存在,跳过"
planned.append(item)
return planned
+def row_problem(entity_id: int | None, note: str, link_kind: str, url: str,
+ label: str) -> str:
+ """这一行写不进库的原因;能写就是空串。"""
+ if entity_id is None:
+ return note
+ if link_kind not in LINK_KINDS:
+ return f"link_kind 「{link_kind}」不在 {sorted(LINK_KINDS)} 内"
+ if not url or urlsplit(url).scheme not in {"http", "https"}:
+ return f"URL 不可用:{url or '空'}"
+ if not label:
+ return "没有 label;资料页要拿它当链接文字"
+ return ""
+
+
#: 「这个页面没了」——上游明确这么说了,才算确证。
GONE_STATUSES = {404, 410}
@@ -226,6 +244,20 @@ def install(connection: sqlite3.Connection, planned: list[dict], source: str) ->
return written
+def relabel(connection: sqlite3.Connection, planned: list[dict]) -> int:
+ """把 `relabel` 那几行的链接文字写成复核表里的 label,返回改了几条。"""
+ now = datetime.now(timezone.utc).isoformat()
+ changed = 0
+ for item in planned:
+ if item["action"] != "relabel":
+ continue
+ connection.execute(
+ "UPDATE entity_link SET label=?,updated_at=? WHERE entity_id=? AND url=?",
+ (item["label"], now, item["entity_id"], item["url"]))
+ changed += connection.execute("SELECT changes()").fetchone()[0]
+ return changed
+
+
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=__doc__)
add_ledger_write_args(parser)
@@ -303,23 +335,27 @@ def main(argv: list[str] | None = None) -> int:
else:
check_links(planned)
for item in planned:
- mark = "+" if item["action"] == "insert" else " "
+ mark = ACTION_MARKS.get(item["action"], " ")
print(f" {mark} {str(item['studio'])[:18]:<18} {item['link_kind']:<8} "
f"{str(item['url'])[:44]:<44} {item['reason']}")
inserts = [item for item in planned if item["action"] == "insert"]
- print({"输入": len(rows), "将写入": len(inserts),
- "跳过": len(planned) - len(inserts), "写入前 entity_link": before})
+ relabels = [item for item in planned if item["action"] == "relabel"]
+ print({"输入": len(rows), "将写入": len(inserts), "将改 label": len(relabels),
+ "跳过": len(planned) - len(inserts) - len(relabels),
+ "写入前 entity_link": before})
if not args.apply:
print("dry-run;确认无误后加 --apply --backup <路径>")
return 0
with connection:
written = install(connection, planned, source=args.input.name)
+ renamed = relabel(connection, planned)
after = connection.execute("SELECT count(*) FROM entity_link").fetchone()[0]
integrity, orphans = verify_after_write(connection)
- print({"实际写入": written, "写入后 entity_link": after, "差值": after - before,
- "integrity_check": integrity, "foreign_key_check": orphans})
- if after - before != written or integrity != "ok" or orphans:
+ print({"实际写入": written, "实际改 label": renamed, "写入后 entity_link": after,
+ "差值": after - before, "integrity_check": integrity,
+ "foreign_key_check": orphans})
+ if after - before != written or renamed != len(relabels) or integrity != "ok" or orphans:
print("[warn] 前后差值、完整性或外键与预期不符,请人工核对")
return 1
finally:
diff --git a/tests/test_agency_entity.py b/tests/test_agency_entity.py
index 1b45c0fb7..aa5ce7f9f 100644
--- a/tests/test_agency_entity.py
+++ b/tests/test_agency_entity.py
@@ -315,7 +315,7 @@ class AgencyLedgerTests(unittest.TestCase):
self.con.execute("DELETE FROM entity_link WHERE entity_id=?", (agency_id,))
self.con.execute(
"INSERT INTO entity_link(entity_id,link_kind,label,url,hostname,created_at,updated_at)"
- " VALUES(?,'official','Capsule Agency 官网存档(2020-01)',"
+ " VALUES(?,'official','官网存档(2020-01)',"
"'https://web.archive.org/web/20200101000000/https://capsule.bz/','web.archive.org',"
"'t','t')", (agency_id,))
self.con.commit()
diff --git a/tests/test_entity_link_install.py b/tests/test_entity_link_install.py
index 99d279aa3..665199205 100644
--- a/tests/test_entity_link_install.py
+++ b/tests/test_entity_link_install.py
@@ -85,6 +85,17 @@ class InstallTests(unittest.TestCase):
self.assertEqual(
self.connection.execute("SELECT count(*) FROM entity_link").fetchone()[0], 1)
+ def test_a_label_edited_in_the_review_table_reaches_the_ledger_on_rerun(self):
+ """label 是资料页上的链接文字,复核表是它的出处:表里改了字,重跑就对齐,不另建一行。"""
+ self.module.install(self.connection, self.module.plan(self.connection, [self.row()]),
+ "review.csv")
+ again = self.module.plan(self.connection, [self.row(label="官网存档(2022-05)")])
+ self.assertEqual([p["action"] for p in again], ["relabel"])
+ self.assertEqual(self.module.install(self.connection, again, "review.csv"), 0)
+ self.assertEqual(self.module.relabel(self.connection, again), 1)
+ self.assertEqual(self.connection.execute("SELECT label FROM entity_link").fetchall(),
+ [("官网存档(2022-05)",)])
+
def test_a_url_without_scheme_does_not_become_a_second_row(self):
"""复核表是人和脚本混写的,`moodyz.com` 和 `https://moodyz.com/` 都会出现。
diff --git a/tests/test_link_label_owner.py b/tests/test_link_label_owner.py
index 89e78caad..b81a5044e 100644
--- a/tests/test_link_label_owner.py
+++ b/tests/test_link_label_owner.py
@@ -76,7 +76,7 @@ class HostOwnerTests(LedgerFixture):
def test_an_archived_official_site_does_not_hand_the_archive_to_a_studio(self):
"""关门厂牌的官网只剩存档快照,存档站本身不归任何一家。"""
- self.link(1, "official", "Prestige 官网存档(2015-01)",
+ self.link(1, "official", "官网存档(2015-01)",
"https://web.archive.org/web/20150101000000/http://www.prestige-av.com/")
self.assertNotIn("web.archive.org", host_owners(self.con))
diff --git a/tests/test_studio_icon_variants.py b/tests/test_studio_icon_variants.py
index 05a253333..f4c34de87 100644
--- a/tests/test_studio_icon_variants.py
+++ b/tests/test_studio_icon_variants.py
@@ -1709,12 +1709,20 @@ class StudioLinkTests(unittest.TestCase):
"""存档快照上取到的是存档站的图标;只剩存档时照样轮到社媒顶上。"""
self.connection.executemany(
"INSERT INTO entity_link(entity_id, link_kind, label, url) VALUES(?,?,?,?)",
- [(2, "official", "Fitch 官网存档(2015-01)",
+ [(2, "official", "官网存档(2015-01)",
"https://web.archive.org/web/20150101000000/http://www.fitch-av.com/"),
(2, "social", "X", "https://x.com/fitch_av")])
links = MODULE.studio_links(self.connection)
self.assertEqual([item["url"] for item in links["Fitch"]], ["https://x.com/fitch_av"])
+ def test_a_company_left_with_only_an_archive_stays_on_the_list(self):
+ """关门的公司官网只剩存档快照:链接不当图源,公司照样在名单里,指定字标按名字取。"""
+ self.connection.execute(
+ "INSERT INTO entity_link(entity_id, link_kind, label, url) VALUES(?,?,?,?)",
+ (2, "official", "官网存档(2015-01)",
+ "https://web.archive.org/web/20150101000000/http://www.fitch-av.com/"))
+ self.assertEqual(MODULE.studio_links(self.connection)["Fitch"], [])
+
def test_a_platform_keeps_its_catalog_link_as_an_icon_source(self):
"""发行平台按 `docs/SOURCING.md` 不登记 official——它不是厂牌,没有厂牌官网。
diff --git a/tests/test_web_js.py b/tests/test_web_js.py
index 16380aeaf..4127f358f 100644
--- a/tests/test_web_js.py
+++ b/tests/test_web_js.py
@@ -394,8 +394,8 @@ class WebJsBehaviourTests(unittest.TestCase):
# 存档快照照写 label,厂牌页上也不改写成「官方网站」。
("core.js", "officialLinkText",
[{"url": "https://web.archive.org/web/20220512171503/https://ones-double.com/people/",
- "label": "ONE'S DOUBLE 官网存档(2022-05)"}, "studio", ["ONE'S DOUBLE"]],
- "ONE'S DOUBLE 官网存档(2022-05)"),
+ "label": "官网存档(2022-05)"}, "studio", ["ONE'S DOUBLE"]],
+ "官网存档(2022-05)"),
])
def test_a_site_mark_carries_a_key_and_never_a_url(self):