Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(tooling): 拦下标题只回显域名的通用站

longmeidaof37001ec0ed4
diff --git a/scripts/harvest_studio_sites.py b/scripts/harvest_studio_sites.py
index c88fef793..f4965ebca 100644
--- a/scripts/harvest_studio_sites.py
+++ b/scripts/harvest_studio_sites.py
@@ -113,12 +113,13 @@ def page_title(body: bytes) -> str:
return re.sub(r"\s+", " ", text).strip()[:120]
-def site_verdict(name: str, status: int, body: bytes, title: str) -> tuple[str, str]:
+def site_verdict(name: str, status: int, body: bytes, title: str,
+ url: str = "") -> tuple[str, str]:
"""这一页认不认自己是这个厂牌。
- 三道都必须过:HTTP 200、页面不是停放页、标题里出现厂牌名。缺任何一道都写成
- 未取得而不是「大概是」——一个错的官网会被下游当成社媒 handle 的来源,
- 把别人的账号安到这个厂牌头上。
+ 四道都必须过:HTTP 200、不是空壳、不是停放页、标题里出现厂牌名且不只是域名回显。
+ 缺任何一道都写成未取得而不是「大概是」——一个错的官网会被下游当成社媒 handle 的
+ 来源,把别人的账号安到这个厂牌头上。
"""
if status != 200:
return "未取得", f"HTTP {status}"
@@ -127,6 +128,14 @@ def site_verdict(name: str, status: int, body: bytes, title: str) -> tuple[str,
text = decode(body)
if PARKED.search(text[:20000]):
return "未取得", "停放页或域名出售页"
+ # 标题不比域名多说任何东西,就等于没有自述身份。实测 `prestige.com` 返回 200、
+ # 不是停放页、标题正好是 `prestige.com`——它因此通过了「标题含厂牌名」,被判成
+ # Prestige 官网,而真站是 `prestige-av.com`,那是另一家公司。停放页规则拦不住它:
+ # 它是个正常的站,只是不属于这个厂牌。
+ host = (urlsplit(url).hostname or "").casefold().removeprefix("www.")
+ title_token = normalise(title)
+ if host and title_token and title_token in normalise(host):
+ return "未取得", f"标题只是域名回显,没有自述身份({title[:40]})"
token = normalise(name)
if token and token in normalise(title):
return "ok", "标题自述厂牌名"
@@ -205,7 +214,7 @@ def run(args) -> int:
note=f"取不到:{type(exc).__name__}")
continue
title = page_title(body)
- verdict, note = site_verdict(name, status, body, title)
+ verdict, note = site_verdict(name, status, body, title, final)
row.update(candidate_url=url, final_url=final, status=status,
bytes=len(body), sha256=hashlib.sha256(body).hexdigest(),
title=title, verdict=verdict, note=note)
diff --git a/tests/test_studio_site_harvest.py b/tests/test_studio_site_harvest.py
index 193705e6b..37859d3e5 100644
--- a/tests/test_studio_site_harvest.py
+++ b/tests/test_studio_site_harvest.py
@@ -89,6 +89,27 @@ class VerdictTests(unittest.TestCase):
self.assertEqual(verdict, "未取得")
self.assertIn("停放", note)
+ def test_a_generic_domain_whose_title_is_just_its_address_is_rejected(self):
+ """停放页规则拦不住这一类:它是个正常的站,只是不属于这个厂牌。
+
+ 实测 `https://www.prestige.com/` 返回 200、不是停放页、标题正好是
+ `prestige.com`,因此通过了「标题含厂牌名」被判成 Prestige 官网——而真站是
+ `prestige-av.com`,`prestige.com` 是另一家公司。判据是:标题若不比域名多说
+ 任何东西,就等于没有自述身份。
+ """
+ verdict, note = self.module.site_verdict(
+ "Prestige", 200, page("prestige.com"), "prestige.com",
+ "https://www.prestige.com/")
+ self.assertEqual(verdict, "未取得")
+ self.assertIn("域名回显", note)
+
+ def test_a_real_site_is_not_rejected_by_the_domain_echo_rule(self):
+ """真站的标题远不止域名,这条规则不能误伤它们。"""
+ title = "年齢チェック | 人気知名度NO.1!アダルトビデオ最強のAVメーカー【MOODYZ(ムーディーズ)】公式サイト"
+ verdict, _ = self.module.site_verdict(
+ "MOODYZ", 200, page(title), title, "https://moodyz.com/")
+ self.assertEqual(verdict, "ok")
+
def test_a_short_page_is_rejected(self):
"""空壳页也是 200。真站首页实测都在 10 KB 以上。"""
verdict, note = self.module.site_verdict("MOODYZ", 200, b"<title>MOODYZ</title>", "MOODYZ")