Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(scraping): 封面失败原因分清下架占位图、单一图源与图源不一致

longmeidaofa37fff9558e
diff --git a/docs/SOURCING.md b/docs/SOURCING.md
index ad2e89080..390bc6302 100644
--- a/docs/SOURCING.md
+++ b/docs/SOURCING.md
@@ -263,6 +263,10 @@ av911.tv,三条候选已进复核队列。
javdb.com 抓得到,但它自己按出口 IP 封速率(2026-09-04 封 3~7 日),只能小批量慢跑,见下文。
既有库采集只在官方渠道落空时按番号问 javdb 与 AVBase:javdb 主机间隔 5 秒,两家回 403 就整源停下
(`scraping_access.SOURCES` 的 `blocked_pause`),资料与封面的比对规则见 ADR-0030。
+ 失败原因分开说:官方各版本只回「准备中」占位图是作品多半已下架(MIDE-594);社区只有一个图源有图是
+ 缺第二个图源印证(IPX-060 只有 javdb);两个图源各有图但 dHash 对不上是「不是同一张图」。
+ JavBus 不作封面兜底:2026-09-15 实测番号页不带年龄确认 Cookie 回答题式年龄验证页,伪造 Cookie 属于绕过验证;
+ IPX-060 在 JavBus 也是 404。
Gfriends 只按 `Filetree.json` 和单张 raw 媒体当外部 Provider 用,不克隆图库、不把图片放进 Git。
索引缓存按 mtime 计龄(一天),取不到新索引就退回旧缓存并在输出里告警;那一轮的「未收录」
记 error 不记 no_match,否则 `--resume` 会把一次网络失败固化成永久答案。
diff --git a/src/peach/community_catalog.py b/src/peach/community_catalog.py
index 627b3ce79..705823b4a 100644
--- a/src/peach/community_catalog.py
+++ b/src/peach/community_catalog.py
@@ -248,6 +248,10 @@ def verified_cover(transport, code: str, works: list[tuple[str, dict]], *,
if len(origins) >= 2 and (best is None or one.pixels > best[0].pixels):
best = (one, tuple(sorted(origins)))
if best is None:
- raise Unavailable("社区来源的封面没有第二个图源能对上" if len(pool) > (reference is not None)
- else "社区来源的封面下载失败")
+ if len(pool) <= (reference is not None):
+ raise Unavailable("社区来源的封面下载失败")
+ origins = sorted({one.origin for one in pool})
+ if len(origins) == 1:
+ raise Unavailable(f"社区来源的封面只有 {origins[0]} 一个图源,缺第二个图源印证")
+ raise Unavailable(f"{'、'.join(origins)} 给的封面不是同一张图,无法互相印证")
return best[0].candidate, best[0].size, best[0].data, best[1]
diff --git a/src/peach/jav_cover_fetch.py b/src/peach/jav_cover_fetch.py
index 0e26268d2..a2bb5bfe3 100644
--- a/src/peach/jav_cover_fetch.py
+++ b/src/peach/jav_cover_fetch.py
@@ -93,6 +93,10 @@ SMALL_MIN_WIDTH = 240
PLACEHOLDER = re.compile(r"now_?printing", re.I)
#: 官方候选一张都量不出可用尺寸时的两种说法,下标是「有没有量到过偏小的图」。
NO_USABLE_OFFICIAL = ("官方封面地址都没有取到图片", "官方封面只有缩略图或占位图")
+#: 占位图是来源自己说「没有图」:DMM 下架的作品两个版本都只剩这一张。
+PLACEHOLDER_REASON = "来源给的是「准备中」占位图"
+#: 官方候选里取到的只有占位图、没有偏小的真图时的说法。
+OFFICIAL_PLACEHOLDER_ONLY = "官方封面地址只回「准备中」占位图,作品多半已从官方下架"
#: 韩国 MIB 的编号不在 JAV 目录站上,封面来源一律不问;记进日志算确认落空,不重探。
MIB_NOT_JAV = "韩国 MIB 不适用 JAV 封面来源"
#: 量尺寸只需要 JPEG 头部,别把整张 1 MB 的图拉下来。
@@ -227,7 +231,7 @@ def _fetch(transport: HttpTransport, url: str, *, referer: str,
_sleep_within(NETWORK_RETRY_DELAYS[attempt], deadline)
final_url = getattr(response, "url", "")
if isinstance(final_url, str) and PLACEHOLDER.search(final_url):
- raise NotFound("来源给的是「准备中」占位图")
+ raise NotFound(PLACEHOLDER_REASON)
if response.status == 404:
raise NotFound("HTTP 404")
if response.status not in (200, 206):
@@ -235,6 +239,18 @@ def _fetch(transport: HttpTransport, url: str, *, referer: str,
return response.body
+def _probe_failure(error: Exception) -> str:
+ """量尺寸失败记进诊断的哪一格:占位图单列,它是来源自己说没有图。"""
+ return "placeholder" if isinstance(error, NotFound) and str(error) == PLACEHOLDER_REASON else "probe_failed"
+
+
+def _no_usable_official(diagnostics: dict) -> str:
+ """官方候选一张都量不出可用尺寸时的原因。"""
+ if diagnostics.get("placeholder") and not diagnostics.get("too_small"):
+ return OFFICIAL_PLACEHOLDER_ONLY
+ return NO_USABLE_OFFICIAL[bool(diagnostics.get("too_small"))]
+
+
def code_variants(code: str) -> list[str]:
"""素人系番号带三位厂牌前缀,去掉才查得到:`278GYAN-017` -> `GYAN-017`。"""
value = normalise_code_key(code)
@@ -613,8 +629,8 @@ def best_cover(transport: HttpTransport, code: str, delay: float, *,
for candidate in candidates:
try:
width, height = probe_size(transport, candidate, deadline=deadline)
- except (Unavailable, httpx.TransportError):
- record("probe_failed")
+ except (Unavailable, httpx.TransportError) as error:
+ record(_probe_failure(error))
continue
except (UnidentifiedImageError, OSError):
record("invalid_image")
@@ -626,7 +642,7 @@ def best_cover(transport: HttpTransport, code: str, delay: float, *,
else:
record("too_small")
if not measured:
- raise Unavailable(NO_USABLE_OFFICIAL[bool(diagnostics.get("too_small"))])
+ raise Unavailable(_no_usable_official(diagnostics))
for _pixels, winner, size in sorted(measured, key=lambda item: item[0], reverse=True):
try:
diff --git a/src/peach/web_scraping.py b/src/peach/web_scraping.py
index d622491c4..e76fd06b8 100644
--- a/src/peach/web_scraping.py
+++ b/src/peach/web_scraping.py
@@ -29,7 +29,8 @@ def w_scraping_cover(contract, body):
def _fetch_cover(contract, code):
- from .jav_cover_fetch import (best_cover, HostLimitedTransport, Unavailable,
+ from .jav_cover_fetch import (best_cover, HostLimitedTransport, NO_USABLE_OFFICIAL,
+ OFFICIAL_PLACEHOLDER_ONLY, Unavailable,
fc2_cover_candidates, logged_success_evidence)
from .review_csv import read_rows
target = contract.cover_root / (code + ".jpg")
@@ -99,11 +100,13 @@ def _fetch_cover(contract, code):
reason, message = "source_error", "来源服务异常(HTTP 5xx),请稍后重试。"
elif str(exc) == "所有渠道都没有候选":
reason, message = "no_candidate", "本次来源未返回匹配该番号的封面候选,无法判断是否还有高清版。"
- elif str(exc) in {"官方封面只有缩略图或占位图", "官方封面地址都没有取到图片"}:
- reason, message = "unusable_candidate", "候选封面未通过检查:图片未取得、无法解码或宽度不足 700px。"
else:
- reason, message = "download_failed", "候选封面完整下载或图片校验失败,未取得可保存的图片。"
- labels = {"probe_failed": "图片头请求失败", "invalid_image": "图片无法解码",
+ reason, message = {
+ OFFICIAL_PLACEHOLDER_ONLY: ("placeholder_only", f"{OFFICIAL_PLACEHOLDER_ONLY}。"),
+ **dict.fromkeys(NO_USABLE_OFFICIAL, (
+ "unusable_candidate", "候选封面未通过检查:图片未取得、无法解码或宽度不足 700px。")),
+ }.get(str(exc), ("download_failed", "候选封面完整下载或图片校验失败,未取得可保存的图片。"))
+ labels = {"placeholder": "「准备中」占位图", "probe_failed": "图片头请求失败", "invalid_image": "图片无法解码",
"too_small": "图片宽度不足 700px", "download_failed": "完整下载失败",
"dimension_mismatch": "完整图片尺寸与探测结果不一致"}
details = ";".join(f"{label} {diagnostics[key]} 张" for key, label in labels.items() if diagnostics.get(key))
diff --git a/tests/test_community_catalog.py b/tests/test_community_catalog.py
index ae586793a..dabf764bc 100644
--- a/tests/test_community_catalog.py
+++ b/tests/test_community_catalog.py
@@ -116,9 +116,14 @@ class VerifiedCoverTests(unittest.TestCase):
self.assertEqual((candidate.url, size, origins), (JAVDB_COVER, (800, 534), ("dmm", "javdb")))
self.assertEqual(candidate.referer, "https://javdb.com/")
pages[DMM_COVER] = gradient(400, 267, rising=False)
- with self.assertRaisesRegex(Unavailable, "没有第二个图源能对上"):
+ with self.assertRaisesRegex(Unavailable, "^dmm、javdb 给的封面不是同一张图"):
verified_cover(serve(pages), "ABW-358", works)
+ def test_a_cover_only_javdb_has_names_the_missing_second_origin(self):
+ works = [("avbase", {"cover_urls": []}), ("javdb", {"cover_urls": [JAVDB_COVER]})]
+ with self.assertRaisesRegex(Unavailable, "^社区来源的封面只有 javdb 一个图源,缺第二个图源印证$"):
+ verified_cover(serve({JAVDB_COVER: gradient(800, 534)}), "IPX-060", works)
+
def test_a_small_official_cover_counts_as_the_second_origin(self):
works = [("javdb", {"cover_urls": [JAVDB_COVER]})]
small = Candidate("image.mgstage.com", "https://image.mgstage.com/images/x/pf_o1_x.jpg")
diff --git a/tests/test_complexity_ratchet.py b/tests/test_complexity_ratchet.py
index c1e57bc2d..16dbb7f0d 100644
--- a/tests/test_complexity_ratchet.py
+++ b/tests/test_complexity_ratchet.py
@@ -51,7 +51,7 @@ BASELINE: dict[str, int] = {
"src/peach/web_catalog.py:q_items": 38,
"scripts/harvest_social_avatars.py:harvest_entity": 37,
"scripts/probe.py:run": 36,
- "src/peach/web_scraping.py:_fetch_cover": 35,
+ "src/peach/web_scraping.py:_fetch_cover": 34,
"scripts/merge_duplicate_identities.py:collect_repeated_projections": 34,
"src/peach/fc2_similarity.py:media_evidence": 34,
"scripts/clean_names.py:run": 33,
diff --git a/tests/test_jav_covers.py b/tests/test_jav_covers.py
index 4607d1a85..8cb20f732 100644
--- a/tests/test_jav_covers.py
+++ b/tests/test_jav_covers.py
@@ -44,6 +44,17 @@ class FetchRetryTests(unittest.TestCase):
prior_candidates=(candidate,), diagnostics=diagnostics)
self.assertEqual(diagnostics, {expected: 1})
+ def test_official_placeholders_only_say_the_work_was_taken_down(self):
+ """DMM 下架的片各版本都 302 到「准备中」,原因要说成下架,不是没取到图。"""
+ candidate = covers.Candidate("test", "https://example.test/cover.jpg")
+ diagnostics = {}
+ with patch.object(covers, "cached_metadata", return_value=covers.MetadataEvidence()), \
+ patch.object(covers, "probe_size", side_effect=covers.NotFound(covers.PLACEHOLDER_REASON)):
+ with self.assertRaisesRegex(covers.Unavailable, f"^{covers.OFFICIAL_PLACEHOLDER_ONLY}$"):
+ covers.best_cover(lambda *args: None, "FC2-PPV-123456", 0,
+ prior_candidates=(candidate,), diagnostics=diagnostics)
+ self.assertEqual(diagnostics, {"placeholder": 1})
+
def test_source_saying_no_is_told_apart_from_source_trouble(self):
"""404 与「所有渠道都没有候选」是来源明确说没有,采集任务据此记住一阵子;
5xx 与候选探测失败下次再问可能就好了,仍是普通的 Unavailable。"""
diff --git a/tests/test_metadata_library.py b/tests/test_metadata_library.py
index 998a07bb1..9b5ec97df 100644
--- a/tests/test_metadata_library.py
+++ b/tests/test_metadata_library.py
@@ -287,7 +287,7 @@ class LibraryNfoTests(unittest.TestCase):
self.assertEqual((evidence['width'], evidence['verified_by']), (1200, ['javdb', 'mgstage']))
with patch('peach.jav_cover_fetch.best_cover', return_value=small), \
- patch('peach.community_catalog.verified_cover', side_effect=Unavailable('社区来源的封面没有第二个图源能对上')):
+ patch('peach.community_catalog.verified_cover', side_effect=Unavailable('社区来源的封面只有 javdb 一个图源,缺第二个图源印证')):
self.assertTrue(provider.cover('ORETD-616', covers))
self.assertEqual((covers / 'ORETD-616.jpg').read_bytes(), b'small')