Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(metadata): 名录来源加上 jae.tokyo 的女优资料页

longmeidao77a30eae7d7c
diff --git a/scripts/harvest_directory_links.py b/scripts/harvest_directory_links.py
index 2963e1343..97d63c86f 100644
--- a/scripts/harvest_directory_links.py
+++ b/scripts/harvest_directory_links.py
@@ -21,7 +21,12 @@ profile_images 才算活。Instagram / TikTok / YouTube 登出页给不出可靠
输出两份 CSV:`<output>` 只含可装的 ok 行,直接喂 install_entity_links.py;
`<stem>-review.csv` 含全部判定,是复核产物。
-laoshi.ink 与 bstar-pro.com 直连(经代理握手失败,站点本身可达);x.com 走代理。
+jae.tokyo 是第三个这样的来源:Japan Adult Expo 的参展女优名录,2014/2015/2017 三届
+各一套厂商自己交的资料,页面上写明本人的博客与官网(`公式ブログ`/`ツイッター`)。
+名录同时带一张人像,所以这个来源多产一份 `<stem>-portraits.csv`,由
+harvest_social_avatars.py 的 jae 路线接着走——头像与链接出自同一批页面、同一次名字判定。
+
+laoshi.ink 与 bstar-pro.com 直连(经代理握手失败,站点本身可达);x.com 与 jae.tokyo 走代理。
bstar-pro 的 models.html 有年龄门:同一会话先 `POST age_check=yes`,之后的 GET 才给列表。
"""
from __future__ import annotations
@@ -49,9 +54,15 @@ from peach.social_links import ( # noqa: E402
HREF = re.compile(r'href=["\']([^"\']+)["\']')
TAG = re.compile(r"<[^>]+>")
+COMMENT = re.compile(r"<!--.*?-->", re.S)
FIELDS = ("entity_id", "kind", "name", "link_kind", "label", "url", "evidence",
"source", "page", "matched_name", "verdict", "alive")
-SOURCES = ("laoshi", "bstar")
+#: 人像候选表:喂 harvest_social_avatars.py 的 jae 路线,不直接落盘头像。
+PORTRAIT_FIELDS = ("entity_id", "kind", "name", "matched_name", "portrait_url",
+ "source", "page", "verdict")
+SOURCES = ("laoshi", "bstar", "jae")
+#: 直连被对端重置(`WinError 10054`),这个来源走代理。
+PROXY_SOURCES = ("jae",)
ALIVE, GONE, UNVERIFIED, UNKNOWN = "活", "疑似失效", "未验", "未取得"
LAOSHI = "https://laoshi.ink/"
@@ -72,6 +83,35 @@ BSTAR_ALT = re.compile(r'alt="([^"]*)"')
BSTAR_SPAN = re.compile(r"<span[^>]*>(.*?)</span>", re.S)
BSTAR_GATE = re.compile(r'name=["\']age_check["\']')
+JAE = "http://www.jae.tokyo/"
+JAE_OWN = ("jae.tokyo",)
+#: 三届的女优名录,每届结构都不一样。2016 那届 `actress.html` 只剩导航,页面上没有人。
+JAE_2014_LISTS = ("jae2014/performer/",) + tuple(
+ f"jae2014/performer/index_{row}.html"
+ for row in ("k", "s", "t", "n", "h", "m", "y", "r"))
+JAE_2015_LIST = "jae2015/actress.html"
+JAE_2017_LIST = "jae2017/actress.html"
+JAE_2017_DETAIL = re.compile(r'href="(actress/[\w-]+\.html)"')
+JAE_2014_ENTRY = re.compile(r'<li id="([^"]+)">(.*?)</li>', re.S)
+JAE_2014_ROMAJI = re.compile(r'<p class="alignright">(.*?)</p>', re.S)
+JAE_2014_IMG = re.compile(r'<img src="(images/[^"]+)"')
+#: 每个女优是一个 `class="off"` 的隐藏层,下一个同类 div 或文末就是它的边界。
+JAE_2015_ENTRY = re.compile(
+ r'<div id="([^"]+)" class="off">(.*?)(?=<div id="[^"]+" class="off">|\Z)', re.S)
+JAE_2015_LINKS = re.compile(r'<div class="actLink[^"]*">(.*?)</div>', re.S)
+JAE_2015_IMG = re.compile(r'<img src="([^"]+)" class="textLeft"')
+JAE_2017_NAME = re.compile(r'<div class="name_area">(.*?)</div>', re.S)
+JAE_2017_LINKS = re.compile(r'<div class="girls_area_right">.*?<ul>(.*?)</ul>', re.S)
+JAE_2017_IMG = re.compile(r'<a class="group pop" href="([^"]+)"')
+JAE_H2 = re.compile(r"<h2[^>]*>(.*?)</h2>", re.S)
+JAE_H3 = re.compile(r"<h3[^>]*>(.*?)</h3>", re.S)
+JAE_H4 = re.compile(r"<h4[^>]*>(.*?)</h4>", re.S)
+JAE_P = re.compile(r"<p[^>]*>(.*?)</p>", re.S)
+JAE_ANCHOR = re.compile(r'<a[^>]+href="([^"]+)"[^>]*>(.*?)</a>', re.S)
+#: 没交照片的位置放的是占位图,不是这个人的像。
+JAE_PLACEHOLDER = ("nophoto", "noimage", "no_photo", "comingsoon")
+
+
X_PROFILE = "https://x.com/{}"
#: 对照账号:X 官方号,登出页永远有 og:image。用来区分「账号没了」和「我们被限流」。
X_CONTROL = "X"
@@ -189,9 +229,13 @@ def bstar_listing(html: str) -> list[tuple[str, list[str]]]:
# ---------------------------------------------------------------- 采集
def page_record(source: str, url: str, names: list[str], links: list[str], *,
- official: tuple[str, str] | None = None, note: str = "") -> dict:
+ official: tuple[str, str] | None = None,
+ owned: list[tuple[str, str]] | None = None,
+ portrait: str = "", note: str = "") -> dict:
+ """`links` 走平台账号那一路;`owned` 是资料页写明的本人博客与官网,带页面上的链接文字。"""
return {"source": source, "page": url, "names": names, "links": links,
- "official": official, "note": note}
+ "official": official, "owned": list(owned or ()), "portrait": portrait,
+ "note": note}
def failed(source: str, url: str, exc: Exception) -> dict:
@@ -247,7 +291,156 @@ def collect_bstar(site: Site, limit: int = 0) -> tuple[list[str], list[dict]]:
return site_links, pages
-COLLECTORS = {"laoshi": collect_laoshi, "bstar": collect_bstar}
+def strip_comments(html: str) -> str:
+ """注释里的东西不属于这一页。
+
+ jae 的女优页是同一份模板复制出来的,上一位的资料整段留在注释里:2017 那届
+ `actress/04.html` 是 AIKA,注释里躺着 `blog.livedoor.jp/sonoda_mion/` 和
+ `instagram.com/kamisaki_shiori/`——不先去注释,AIKA 名下会装上另外两个人的账号。
+ 2014 那届的 `<li id="AyamiShunka">` 是填好数据的模板样例,同样在注释里。
+ """
+ return COMMENT.sub(" ", html)
+
+
+def jae_anchors(fragment: str, base: str) -> list[tuple[str, str]]:
+ """片段里的站外链接 → [(URL, 链接文字)]。文字取页面上写的那行(`公式ブログ`)。"""
+ out: dict[str, str] = {}
+ for href, inner in JAE_ANCHOR.findall(fragment):
+ url = urljoin(base, html_lib.unescape(href).strip())
+ parts = urlsplit(url)
+ if parts.scheme not in {"http", "https"} or not parts.hostname:
+ continue
+ if under(parts.hostname.casefold(), JAE_OWN):
+ continue
+ out.setdefault(url, clean(inner))
+ return list(out.items())
+
+
+def jae_portrait(src: str, base: str) -> str:
+ if not src or any(mark in src.casefold() for mark in JAE_PLACEHOLDER):
+ return ""
+ return urljoin(base, html_lib.unescape(src).strip())
+
+
+def jae_entry(anchor: str, names: list[str], links: list[tuple[str, str]],
+ portrait: str) -> dict:
+ return {"anchor": anchor, "names": dedupe(names), "links": links,
+ "portrait": portrait}
+
+
+def jae_2014_entries(html: str, base: str) -> list[dict]:
+ """`<li id="…">` 一位一条:`h2` 是日文名,`alignright` 是罗马字,资料表末尾是本人的站。"""
+ out = []
+ for anchor, block in JAE_2014_ENTRY.findall(strip_comments(html)):
+ names = [clean(text) for text in JAE_H2.findall(block)]
+ names += [clean(text) for text in JAE_2014_ROMAJI.findall(block)]
+ image = JAE_2014_IMG.search(block)
+ out.append(jae_entry(anchor, names, jae_anchors(block, base),
+ jae_portrait(image.group(1) if image else "", base)))
+ return out
+
+
+def jae_2015_entries(html: str, base: str) -> list[dict]:
+ """`class="off"` 的隐藏层一位一条:`bigName` 日文名、`smallName` 罗马字。
+
+ 链接只取 `actLink*` 那一格。同一层的资料表里还有一条「おすすめの作品タイトル」,
+ 那是片商的商品页(`ec.sod.co.jp/detail/…`),不是本人的链接。
+ """
+ out = []
+ for anchor, block in JAE_2015_ENTRY.findall(strip_comments(html)):
+ names = [clean(text) for text in JAE_H3.findall(block)]
+ names += [clean(text) for text in JAE_H4.findall(block)]
+ links: list[tuple[str, str]] = []
+ for fragment in JAE_2015_LINKS.findall(block):
+ links += jae_anchors(fragment, base)
+ image = JAE_2015_IMG.search(block)
+ out.append(jae_entry(anchor, names, links,
+ jae_portrait(image.group(1) if image else "", base)))
+ return out
+
+
+def jae_2017_pages(html: str, base: str) -> list[str]:
+ """名录页 → 详情页 URL。详情页文件名有的是编号有的是罗马字,一律照写。"""
+ return sorted({urljoin(base, href) for href in JAE_2017_DETAIL.findall(html)})
+
+
+def jae_2017_entry(html: str, url: str) -> dict:
+ """详情页一位一条:`name_area` 给名字,`girls_area_right` 的图标列表给账号。
+
+ 人像取 `class="group pop"` 那个大图,不取旁边 `m.jpg` 的缩略图。
+ """
+ body = strip_comments(html)
+ area = JAE_2017_NAME.search(body)
+ names: list[str] = []
+ if area:
+ names = [clean(text) for text in JAE_H2.findall(area.group(1))]
+ names += [clean(text) for text in JAE_P.findall(area.group(1))]
+ links: list[tuple[str, str]] = []
+ for fragment in JAE_2017_LINKS.findall(body):
+ links += jae_anchors(fragment, url)
+ image = JAE_2017_IMG.search(body)
+ return jae_entry(url.rsplit("/", 1)[-1], names, links,
+ jae_portrait(image.group(1) if image else "", url))
+
+
+def take(items: list, limit: int) -> list:
+ return items[:limit] if limit else items
+
+
+def collect_jae(site: Site, limit: int = 0) -> tuple[list[str], list[dict]]:
+ """展会名录三届。名录页上没有女优的账号,站方链接一栏为空。
+
+ 链接文字(`公式ブログ`/`ツイッター`)当标签;平台账号照常走 `links`,
+ 博客与本人官网走 `owned`。人像同批带出,判定与链接同一次。
+ """
+ pages: list[dict] = []
+ entries: list[tuple[str, dict]] = []
+
+ for path in JAE_2014_LISTS:
+ url = JAE + path
+ try:
+ html = site.get(url)
+ except Exception as exc:
+ pages.append(failed("jae", url, exc))
+ continue
+ entries += [(f"{url}#{entry['anchor']}", entry)
+ for entry in take(jae_2014_entries(html, url), limit)]
+
+ url = JAE + JAE_2015_LIST
+ try:
+ html = site.get(url)
+ except Exception as exc:
+ pages.append(failed("jae", url, exc))
+ else:
+ entries += [(f"{url}#{entry['anchor']}", entry)
+ for entry in take(jae_2015_entries(html, url), limit)]
+
+ url = JAE + JAE_2017_LIST
+ detail_urls: list[str] = []
+ try:
+ listing = site.get(url)
+ except Exception as exc:
+ pages.append(failed("jae", url, exc))
+ else:
+ detail_urls = take(jae_2017_pages(listing, url), limit)
+ for detail in detail_urls:
+ try:
+ html = site.get(detail)
+ except Exception as exc:
+ pages.append(failed("jae", detail, exc))
+ continue
+ entries.append((detail, jae_2017_entry(html, detail)))
+
+ for page_url, entry in entries:
+ owned = [(url, label) for url, label in entry["links"] if not platform(url)]
+ pages.append(page_record("jae", page_url, entry["names"],
+ [url for url, _ in entry["links"]],
+ owned=owned, portrait=entry["portrait"]))
+ return [], pages
+
+
+COLLECTORS = {"laoshi": collect_laoshi, "bstar": collect_bstar,
+ "jae": collect_jae}
# ---------------------------------------------------------------- 判定
@@ -268,6 +461,18 @@ def index_names(performers: list[dict]) -> dict[str, set[int]]:
return index
+def matched_ids(names: list[str], index: dict[str, set[int]]) -> tuple[set[int], list[str]]:
+ """页面上的名字 → (命中的 entity_id, 真正对上的那几个名字)。"""
+ matched: set[int] = set()
+ used: list[str] = []
+ for name in names:
+ ids = index.get(name_key(name))
+ if ids:
+ matched |= ids
+ used.append(name)
+ return matched, used
+
+
def load_existing(connection: sqlite3.Connection) -> tuple[dict, dict]:
"""账本现有链接 → ({entity_id: {(平台, handle): url}}, {entity_id: {url}})。"""
handles: dict[int, dict[tuple[str, str], str]] = {}
@@ -298,13 +503,7 @@ def judge(pages: list[dict], site_links: list[str], performers: list[dict],
rows.append(row(**base, verdict="未取得", evidence=page["note"]))
stats["页面未取得"] += 1
continue
- matched: set[int] = set()
- used: list[str] = []
- for name in page["names"]:
- ids = index.get(name_key(name))
- if ids:
- matched |= ids
- used.append(name)
+ matched, used = matched_ids(page["names"], index)
socials = []
seen: set[tuple[str, str]] = set()
for url in page["links"]:
@@ -330,7 +529,7 @@ def judge(pages: list[dict], site_links: list[str], performers: list[dict],
record = by_id[entity_id]
base.update(entity_id=entity_id, name=record["name"], matched_name=matched_name)
where = f"{page['source']} {page['page']};页面名「{matched_name}」对上账本「{record['name']}」"
- if not socials and not page["official"]:
+ if not socials and not page["official"] and not page["owned"]:
rows.append(row(**base, verdict="未取得", evidence=f"{where};页面上没有社交链接"))
stats["命中但无社媒"] += 1
continue
@@ -351,6 +550,18 @@ def judge(pages: list[dict], site_links: list[str], performers: list[dict],
held[(name, account)] = url
rows.append(item)
stats[item["verdict"]] += 1
+ # 博客与本人官网没有 handle 可比,只按 URL 判重;标签用页面上写的那行链接文字。
+ for url, shown in page["owned"]:
+ link_kind, fallback = classify(url)
+ item = row(**base, link_kind=link_kind, label=shown or fallback, url=url)
+ if url in existing_urls.get(entity_id, set()):
+ item.update(verdict="已有", evidence=f"{where};账本已有此地址")
+ else:
+ item.update(verdict="ok",
+ evidence=f"{where};资料页写明的本人链接「{shown or fallback}」")
+ existing_urls.setdefault(entity_id, set()).add(url)
+ rows.append(item)
+ stats[item["verdict"]] += 1
if page["official"]:
url, label = page["official"]
if url in existing_urls.get(entity_id, set()):
@@ -365,6 +576,29 @@ def judge(pages: list[dict], site_links: list[str], performers: list[dict],
return rows, stats
+def portrait_rows(pages: list[dict], performers: list[dict]) -> list[dict]:
+ """名录页上的人像 → 头像候选行,喂 harvest_social_avatars.py 的 jae 路线。
+
+ 与链接队列同一批页面、同一次名字判定:唯一命中才出行,对上多位的不出——
+ 头像装错人和链接装错人是同一个错误,判据不能两套。
+ """
+ by_id = {record["entity_id"]: record for record in performers}
+ index = index_names(performers)
+ out: list[dict] = []
+ for page in pages:
+ if page["note"] or not page["portrait"]:
+ continue
+ matched, used = matched_ids(page["names"], index)
+ if len(matched) != 1:
+ continue
+ entity_id = next(iter(matched))
+ out.append({"entity_id": str(entity_id), "kind": "performer",
+ "name": by_id[entity_id]["name"], "matched_name": "、".join(used),
+ "portrait_url": page["portrait"], "source": page["source"],
+ "page": page["page"], "verdict": "命中"})
+ return out
+
+
# ---------------------------------------------------------------- 验活
def probe_x(site: Site, account: str, memo: dict[str, tuple[str, str]]) -> tuple[str, str]:
@@ -453,10 +687,12 @@ def run(args) -> int:
print(f"账本可比对 performer {len(performers)} 位")
rows: list[dict] = []
+ portraits: list[dict] = []
totals: Counter = Counter()
sources = SOURCES if args.source == "all" else (args.source,)
for source in sources:
- site = Site(args.cache_dir / source, args.interval, args.timeout, refresh=args.refresh)
+ site = Site(args.cache_dir / source, args.interval, args.timeout, refresh=args.refresh,
+ via_proxy=source in PROXY_SOURCES)
try:
site_links, pages = COLLECTORS[source](site, args.limit)
except Exception as exc:
@@ -466,6 +702,7 @@ def run(args) -> int:
site.close()
source_rows, stats = judge(pages, site_links, performers, existing_handles, existing_urls)
rows += source_rows
+ portraits += portrait_rows(pages, performers)
totals.update(stats)
print(f"[{source}] 页面 {len(pages)},网络 {site.fetched} / 缓存 {site.cached},"
f"站方账号 {len(site_links)} 条已剔除,{dict(stats)}")
@@ -485,8 +722,13 @@ def run(args) -> int:
queue = installable(rows)
write_rows(args.output, FIELDS, queue)
write_rows(review, FIELDS, rows)
- print({"安装队列": len(queue), "复核行": len(rows), **totals,
- "output": str(args.output), "review": str(review)})
+ result = {"安装队列": len(queue), "复核行": len(rows), **totals,
+ "output": str(args.output), "review": str(review)}
+ if portraits:
+ portrait_path = args.output.with_name(args.output.stem + "-portraits.csv")
+ write_rows(portrait_path, PORTRAIT_FIELDS, portraits)
+ result.update({"人像候选": len(portraits), "portraits": str(portrait_path)})
+ print(result)
return 0
diff --git a/tests/test_directory_link_harvest.py b/tests/test_directory_link_harvest.py
index 75431a920..e9bfd718f 100644
--- a/tests/test_directory_link_harvest.py
+++ b/tests/test_directory_link_harvest.py
@@ -68,6 +68,64 @@ BSTAR_MODEL = """<ul class="sns_list">
<a href="https://x.com/bstar_pro/">事务所</a>
<a href="/https://www.instagram.com/bstar_pro_">写坏的</a>"""
+# 按 2026-09-04 实测的 jae.tokyo 三届名录复刻。三处陷阱都留在样本里:2014 那届开头是
+# 一条填好数据的模板 `<li>`(在注释里),2015 那届资料表里有片商的商品页,2017 那届每页
+# 都是从上一位那页复制来的,上一位的账号整段留在注释里。
+JAE_2014_PAGE = """<section class="sec_list_performers"><ul>
+ <!--
+ <li id="AyamiShunka"><h2>あやみ</h2><p class="alignright">Shunka</p>
+ <img src="images/nophoto.jpg" alt="">
+ <div class="clearfix"><p><span><span class="rc3">リンク</span></span>
+ <span><a href="http://example.com/template">公式</a></span></p></div></li>
+ -->
+ <li id="YuiHatano"><h2>波多野結衣</h2><p class="alignright">Yui Hatano</p>
+ <img src="images/Hatano_Yui.jpg" alt="波多野結衣">
+ <div class="clearfix">
+ <p><span><span class="rc3">所属</span></span><span>MAXING</span></p>
+ <p><span><span class="rc3">リンク</span></span><span>
+ <a href="http://blog.livedoor.jp/hatano_yui/">公式ブログ</a>
+ <a href="https://twitter.com/hatano_yui">ツイッター</a></span></p></div></li>
+ <li id="Nameless"><h2>架空同名</h2><p class="alignright">Nameless</p>
+ <img src="images/nophoto.jpg" alt="架空同名"><div class="clearfix"></div></li>
+</ul></section>"""
+
+JAE_2015_PAGE = """<div id="joyu001" class="off">
+ <img src="images/actress/sod/seto_l.jpg" class="textLeft">
+ <div class="textRightOrange"><div class="nameBackOrange">
+ <h3 class="bigName">瀬戸環奈</h3><h4 class="smallName">Kanna Seto</h4></div>
+ <table><tr><th>おすすめの<br>作品タイトル</th>
+ <td><a href="http://ec.sod.co.jp/detail/index/-_-/iid/STAR-621" target="_blank">作品</a></td>
+ </tr></table>
+ <div class="actLinkOrange">
+ <a href="http://kanna-seto.ameblo.jp/" target="_blank">オフィシャルブログ<span></span></a>
+ <a href="https://twitter.com/kanna_seto0510" target="_blank">ツイッター<span></span></a>
+ </div></div></div>
+<div id="joyu002" class="off">
+ <img src="images/actress/sod/nameless_l.jpg" class="textLeft">
+ <h3 class="bigName">架空同名</h3><h4 class="smallName">Nameless</h4></div>"""
+
+JAE_2017_LIST_PAGE = """<ul>
+ <li><a href="actress/04.html"><img src="images/actress/girls/04.jpg" alt="波多野結衣"></a></li>
+ <li><a href="actress/sonoda_mion.html"><img src="images/actress/girls/03.jpg"></a></li>
+ <li><a href="actress/04.html">重复</a></li>
+ <li><a href="../jae2015/actress.html">上一届</a></li></ul>"""
+
+JAE_2017_PAGE = """<div id="girls_area" class="other_area">
+ <div class="girls_btn"><a href="sonoda_mion.html" class="btn_left pop">◀◀</a></div>
+ <div class="girls_area_left">
+ <a class="group pop" href="../images/actress/girls/04l.jpg" title="波多野結衣">
+ <img src="../images/actress/girls/04m.jpg" alt="波多野結衣"></a></div>
+ <div class="girls_area_right">
+ <div class="name_area"><h2>波多野結衣</h2><p>Yui Hatano</p></div>
+ <ul><li><a href="https://twitter.com/hatano_yui" target="_blank" class="pop">
+ <img src="../images/actress/icon01.png" alt="twitter"></a></li>
+ <!-- <li><a href="http://blog.livedoor.jp/sonoda_mion/" target="_blank" class="pop"></a></li>
+ <li><a href="https://www.instagram.com/kamisaki_shiori/" class="pop"></a></li> -->
+ </ul>
+ <table><tr><th>おすすめの作品タイトル</th>
+ <td><a href="http://www.max-a.co.jp/item.php?item_id=ef33" class="pop">作品</a></td>
+ </tr></table></div></div>"""
+
X_ALIVE = """<html><head><meta content="瀬戸環奈 (@kanna_seto0510) / X" property="og:title">
<meta property="og:image" content="https://pbs.twimg.com/profile_images/1/abc_200x200.jpg"></head></html>"""
X_SUSPENDED = """<html><head><meta property="og:title" content="X"><meta property="og:image"
@@ -237,6 +295,95 @@ class BstarCollectTests(unittest.TestCase):
self.assertIn("https://s1s1s1.com/actress/detail/849776", links)
+class JaeCollectTests(unittest.TestCase):
+ """展会名录三届:结构各不相同,注释里的东西一律不算这一页的内容。"""
+
+ def setUp(self):
+ self.module = load_module()
+ self.list_2017 = self.module.JAE + self.module.JAE_2017_LIST
+ # 2014 那届按五十音分页,样本只给「あ行」有人,其余页留空。
+ self.pages = {self.module.JAE + path: "<ul></ul>"
+ for path in self.module.JAE_2014_LISTS}
+ self.pages.update({
+ self.module.JAE + self.module.JAE_2014_LISTS[0]: JAE_2014_PAGE,
+ self.module.JAE + self.module.JAE_2015_LIST: JAE_2015_PAGE,
+ self.list_2017: JAE_2017_LIST_PAGE,
+ "http://www.jae.tokyo/jae2017/actress/04.html": JAE_2017_PAGE,
+ "http://www.jae.tokyo/jae2017/actress/sonoda_mion.html": "<div></div>"})
+
+ def entries_2014(self):
+ return self.module.jae_2014_entries(
+ JAE_2014_PAGE, self.module.JAE + self.module.JAE_2014_LISTS[0])
+
+ def test_the_commented_out_template_entry_is_not_a_person(self):
+ """2014 那届列表开头是一条填好数据的模板 `<li>`,整段在注释里。"""
+ entries = self.entries_2014()
+ self.assertEqual([entry["anchor"] for entry in entries], ["YuiHatano", "Nameless"])
+ self.assertTrue(all("example.com/template" not in url
+ for entry in entries for url, _ in entry["links"]))
+
+ def test_an_entry_pairs_both_name_spellings_with_its_own_links_and_portrait(self):
+ entry = self.entries_2014()[0]
+ self.assertEqual(entry["names"], ["波多野結衣", "Yui Hatano"])
+ self.assertEqual(entry["links"], [("http://blog.livedoor.jp/hatano_yui/", "公式ブログ"),
+ ("https://twitter.com/hatano_yui", "ツイッター")])
+ self.assertEqual(entry["portrait"],
+ "http://www.jae.tokyo/jae2014/performer/images/Hatano_Yui.jpg")
+
+ def test_the_placeholder_photo_is_not_a_portrait(self):
+ """没交照片的位置放的是 `nophoto.jpg`,那不是这个人的像。"""
+ self.assertEqual(self.entries_2014()[1]["portrait"], "")
+
+ def test_2015_takes_links_from_the_link_row_and_not_from_the_product_table(self):
+ """同一层的资料表里还有片商的商品页,那不是本人的链接。"""
+ entries = self.module.jae_2015_entries(
+ JAE_2015_PAGE, self.module.JAE + self.module.JAE_2015_LIST)
+ self.assertEqual([entry["anchor"] for entry in entries], ["joyu001", "joyu002"])
+ self.assertEqual(entries[0]["names"], ["瀬戸環奈", "Kanna Seto"])
+ self.assertEqual(entries[0]["links"],
+ [("http://kanna-seto.ameblo.jp/", "オフィシャルブログ"),
+ ("https://twitter.com/kanna_seto0510", "ツイッター")])
+ self.assertEqual(entries[1]["links"], [])
+
+ def test_2017_listing_names_each_detail_page_once_and_stays_in_its_own_year(self):
+ pages = self.module.jae_2017_pages(JAE_2017_LIST_PAGE, self.list_2017)
+ self.assertEqual(pages, ["http://www.jae.tokyo/jae2017/actress/04.html",
+ "http://www.jae.tokyo/jae2017/actress/sonoda_mion.html"])
+
+ def test_2017_detail_does_not_inherit_the_neighbours_accounts_from_the_comments(self):
+ """每页都是从上一位那页复制来的,上一位的账号整段留在注释里。"""
+ entry = self.module.jae_2017_entry(
+ JAE_2017_PAGE, "http://www.jae.tokyo/jae2017/actress/04.html")
+ self.assertEqual(entry["names"], ["波多野結衣", "Yui Hatano"])
+ self.assertEqual(entry["links"], [("https://twitter.com/hatano_yui", "")])
+ self.assertEqual(entry["portrait"],
+ "http://www.jae.tokyo/jae2017/images/actress/girls/04l.jpg")
+
+ def test_platform_accounts_and_own_sites_leave_the_collector_on_separate_tracks(self):
+ """平台账号照常走 `links`(要按 handle 判冲突);博客与本人官网走 `owned`。"""
+ site = FakeSite(self.pages, HttpStatusError=self.module.HttpStatusError)
+ site_links, pages = self.module.collect_jae(site)
+ self.assertEqual(site_links, [])
+ got = {page["page"]: page for page in pages if not page["note"]}
+ entry = got["http://www.jae.tokyo/jae2014/performer/#YuiHatano"]
+ self.assertEqual(entry["links"], ["http://blog.livedoor.jp/hatano_yui/",
+ "https://twitter.com/hatano_yui"])
+ self.assertEqual(entry["owned"], [("http://blog.livedoor.jp/hatano_yui/", "公式ブログ")])
+ self.assertEqual(entry["portrait"],
+ "http://www.jae.tokyo/jae2014/performer/images/Hatano_Yui.jpg")
+
+ def test_a_missing_year_only_leaves_未取得_and_the_others_still_run(self):
+ pages = dict(self.pages)
+ del pages[self.module.JAE + self.module.JAE_2015_LIST]
+ site = FakeSite(pages, HttpStatusError=self.module.HttpStatusError)
+ _, collected = self.module.collect_jae(site)
+ failures = [page for page in collected if page["note"]]
+ self.assertEqual([page["page"] for page in failures],
+ [self.module.JAE + self.module.JAE_2015_LIST])
+ self.assertTrue(failures[0]["note"].startswith("未取得:HttpStatusError: HTTP 404"))
+ self.assertTrue(any(page["page"].endswith("#YuiHatano") for page in collected))
+
+
class JudgeTests(unittest.TestCase):
def setUp(self):
self.module = load_module()
@@ -322,6 +469,55 @@ class JudgeTests(unittest.TestCase):
rows, _ = self.judge([page], urls={2: {url}})
self.assertEqual([(row["link_kind"], row["verdict"]) for row in rows], [("official", "已有")])
+ def test_an_own_site_is_labelled_with_the_words_printed_on_the_page(self):
+ """博客与本人官网没有 handle 可比,只按 URL 判重;标签用资料页上那行文字。"""
+ blog = "http://blog.livedoor.jp/hatano_yui/"
+ home = "http://hatano-yui.jp/"
+ page = self.module.page_record(
+ "jae", "http://www.jae.tokyo/jae2014/performer/#YuiHatano", ["波多野結衣"], [],
+ owned=[(blog, "公式ブログ"), (home, "")])
+ rows, stats = self.judge([page])
+ self.assertEqual([(row["link_kind"], row["label"], row["verdict"]) for row in rows],
+ [("social", "公式ブログ", "ok"), ("official", "官方网站", "ok")])
+ self.assertIn("资料页写明的本人链接「公式ブログ」", rows[0]["evidence"])
+ self.assertEqual(stats["ok"], 2)
+
+ def test_an_own_site_the_ledger_already_holds_is_已有(self):
+ blog = "http://blog.livedoor.jp/hatano_yui/"
+ page = self.module.page_record("jae", "p", ["波多野結衣"], [], owned=[(blog, "公式ブログ")])
+ rows, _ = self.judge([page], urls={1: {blog}})
+ self.assertEqual([row["verdict"] for row in rows], ["已有"])
+
+
+class PortraitTests(unittest.TestCase):
+ """名录页带的人像走头像候选表,判据与链接同一套。"""
+
+ def setUp(self):
+ self.module = load_module()
+
+ def rows(self, pages):
+ return self.module.portrait_rows(pages, PERFORMERS)
+
+ def test_a_unique_match_becomes_a_candidate_row(self):
+ page = self.module.page_record("jae", "p#YuiHatano", ["波多野結衣", "Yui Hatano"], [],
+ portrait="http://www.jae.tokyo/x.jpg")
+ self.assertEqual(self.rows([page]), [{
+ "entity_id": "1", "kind": "performer", "name": "波多野结衣",
+ "matched_name": "波多野結衣", "portrait_url": "http://www.jae.tokyo/x.jpg",
+ "source": "jae", "page": "p#YuiHatano", "verdict": "命中"}])
+
+ def test_a_name_matching_several_performers_yields_no_portrait(self):
+ """头像装错人和链接装错人是同一个错误,判据不能两套。"""
+ page = self.module.page_record("jae", "p", ["架空同名"], [],
+ portrait="http://www.jae.tokyo/x.jpg")
+ self.assertEqual(self.rows([page]), [])
+
+ def test_a_page_without_a_portrait_or_a_failed_page_yields_nothing(self):
+ blank = self.module.page_record("jae", "p", ["波多野結衣"], [])
+ broken = self.module.page_record("jae", "q", [], [], portrait="http://x/y.jpg",
+ note="未取得:HTTP 404")
+ self.assertEqual(self.rows([blank, broken]), [])
+
class ProbeTests(unittest.TestCase):
def setUp(self):