Peach: Local-first video metadata scraper and media manager.
fix(covers): 以实际像素优先选择官方封面
longmeidao6f4ccc5118f0
diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 3705fd488..7cf58f168 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -217,6 +217,10 @@ JAV 默认封面(官方封面/预览图)与视频默认大小(大图/无快照的有码作品由封面入口复用现有 `DmmSource` 的 GraphQL 查询与精确身份核验;成功快照直接展开 DMM 图片候选,r18.dev 与 DMM 使用同一份目录证据。FC2 来源快照通过 `storage_original` 提取发行方存储原件,排除社区图床。目录查询沿用来源冷却,HTTP、网络与解析失败分别保留未取得状态。+MGS 专属发行先查自营商品目录,Prestige 番号复用 `metadata_routes.maker_sites` 路由后汇总集团官网与 MGS 图片;手上已有候选仍一起比较实际尺寸。专属目录未取得候选时才查综合目录,避免无关目录故障消耗整项预算。++正式封面和商品图以像素面积择优,同尺寸优先商品图,剧照预览保留末档;图片角色不让低清商品图覆盖更大的官方封面。+人脸缓存使用 `cover-face-v2` 与源图尺寸校验。`detect_cover_faces.py` 自动重算过期记录,逐图核查加 `--refresh-faces` 可在重算整图主脸后再决定版式;无可信书脊且左侧主脸明显占优的大封按整幅画面取景。安装、批次重算与恢复默认取景读取同一版式标记。取景由 `poster-crop-v12` 管理。Blu-ray 来源标题、明确的版次标签与图片比例共同决定 0.85 正封比例,标题随正封框保留,重算人脸与正封框均读取同一版次;有效宽正封框在没有版次标题的卡片上也完整显示。VR 标记、IENEE、IENFE、SDHS 数字发行拼图,以及可信主脸跨过 DVD 正封先验边界的大封保留整幅画面,由 `cover_frame.layout=still` 传给卡片。大封在竖版大图按主脸居中填满,横版小图完整显示,均不使用模糊补边;JPEG 软边的书脊识别结合突出度、左忙右静的方向与正封侧基线。手工框保持用户取景。重试队列按最早尝试时间轮转,收起的合集沿用设置跳过;逐番号结果保存在 `feed-cover-attempts/`。复用现有 HTTP、Pillow、OpenCV 与文件锁,无新增依赖。diff --git a/src/peach/jav_cover_fetch.py b/src/peach/jav_cover_fetch.pyindex 4699aa94e..6ea700159 100644--- a/src/peach/jav_cover_fetch.py+++ b/src/peach/jav_cover_fetch.py@@ -749,10 +749,19 @@ def _site_candidates(transport: HttpTransport, code: str, evidence: MetadataEvid"""复用官方目录并按发行面查询图片;FC2 由调用方提供商品图候选。"""if code.upper().startswith("FC2-PPV-"):return []+ from peach.metadata_routes import maker_sitescandidates: list[Candidate] = []live_evidence = MetadataEvidence()+ prestige = _is_prestige(evidence) or 'prestige' in maker_sites(code)+ amateur = is_amateur_code(code) or 'mgstage' in evidence.sources+ if prestige:+ candidates += prestige_group_images(transport, code, deadline=deadline)+ elif amateur:+ candidates += mgstage_images(transport, code, deadline=deadline)+ if candidates or ((prestige or amateur) and evidence.candidates):+ return candidatesif (not evidence.candidates and 'dmm' not in evidence.sources- and not is_amateur_code(code) and not is_uncensored_code(code)):+ and not prestige and not amateur and not is_uncensored_code(code)):try:live_evidence = dmm_evidence(transport, code, deadline=deadline)candidates += list(live_evidence.candidates)@@ -764,16 +773,10 @@ def _site_candidates(transport: HttpTransport, code: str, evidence: MetadataEvidlive_evidence = r18_evidence(transport, code, deadline=deadline, record=record)candidates += list(live_evidence.candidates)_sleep_within(delay, deadline)- # MGS 与 Prestige 都是 Prestige 集团的官方供给面。只在本地厂牌证据命中时- # 查询,避免把全库 960 个番号无差别打到两个站点。- if _is_prestige(evidence) or _is_prestige(live_evidence):+ # 目录新识别出 Prestige 时补问集团自营渠道。+ if not prestige and _is_prestige(live_evidence):candidates += prestige_group_images(transport, code, deadline=deadline)_sleep_within(delay, deadline)- # 素人系番号按形状就能确定发行面是 MGS,不必先有元数据。等元数据的旧写法让- # 259LUXU / 300MIUM / 428SUKE 这批番号一次也没问过 MGS——而 MGS 一直有图。- elif is_amateur_code(code) or "mgstage" in evidence.sources:- candidates += mgstage_images(transport, code, deadline=deadline)- _sleep_within(delay, deadline)return candidates@@ -889,7 +892,7 @@ def _measure(transport: HttpTransport, candidates, record, *, minimum_width: intdef _download_best(transport: HttpTransport, measured, record, *, minimum_width: int,minimum_quality: int, minimum_pixels: int,deadline: float | None) -> tuple[Candidate, tuple[int, int], bytes]:- """按来源档次与像素从高到低完整下载,第一张尺寸对得上、是静态图、确实更好的就是它。+ """封面按像素面积择优,同尺寸优先商品图;预览图仅作末档候选。动图只有下完整张才认得出:FC2 链末档 JavArchive 的图床存的常是 GIF 预览动画,只读头部量尺寸时它和一张静态图没有区别,落进 `.jpg` 之后卡片就一直在动。候选全是@@ -897,7 +900,7 @@ def _download_best(transport: HttpTransport, measured, record, *, minimum_width:"""animated = 0for _pixels, winner, size in sorted(- measured, key=lambda item: (candidate_quality(item[1]), item[0]), reverse=True):+ measured, key=lambda item: (candidate_quality(item[1]) > 0, item[0], candidate_quality(item[1])), reverse=True):try:data = _fetch(transport, winner.url, referer=winner.referer,limit=16 * 1024 * 1024, deadline=deadline)diff --git a/tests/test_jav_covers.py b/tests/test_jav_covers.pyindex a2a0297ef..6eaf15ea5 100644--- a/tests/test_jav_covers.py+++ b/tests/test_jav_covers.py@@ -32,6 +32,28 @@ class _Response:class FetchRetryTests(unittest.TestCase):+ def test_larger_official_cover_beats_a_smaller_product_image(self):+ large = covers.candidate_for('https://official.example/full.jpg')+ small = covers.candidate_for('https://image.mgstage.com/pb_e_product.jpg')+ winner, size, _ = covers.best_cover(transport_for({large.url: (200, jpeg(2184, 1468)),+ small.url: (200, jpeg(840, 563))}), 'FC2-PPV-123456', 0, prior_candidates=(small, large))+ self.assertEqual((winner, size), (large, (2184, 1468)))++ def test_mgs_releases_use_their_own_catalog_without_waiting_for_an_unrelated_mirror(self):+ url = 'https://image.mgstage.com/images/nanpatv/200gana/1995/pb_e_200gana-1995.jpg'+ with patch.object(covers, 'mgstage_images', return_value=[covers.candidate_for(url)]):+ with patch.object(covers, 'r18_evidence', side_effect=AssertionError('专属目录已取得')):+ with patch.object(covers, 'dmm_evidence', side_effect=AssertionError('MGS 不在 DMM 目录')):+ _, size, _ = covers.best_cover(transport_for({url: (200, jpeg(840, 472))}), '200GANA-1995', 0)+ self.assertEqual(size, (840, 472))++ def test_prestige_code_routing_uses_the_official_group_without_a_snapshot(self):+ url = 'https://www.prestige-av.com/api/media/package.jpg'+ with patch.object(covers, 'prestige_group_images', return_value=[covers.candidate_for(url)]) as group:+ with patch.object(covers, 'r18_evidence', side_effect=AssertionError('片商目录已取得')):+ _, size, _ = covers.best_cover(transport_for({url: (200, jpeg(1600, 1000))}), 'ABW-192', 0)+ self.assertEqual(size, (1600, 1000))+ group.assert_called_once()def test_empty_snapshots_use_the_identified_dmm_catalog_and_largest_image(self):COVER = 'https://awsimgsrc.dmm.co.jp/pics_dig/digital/video/ssis00057/ssis00057pl.jpg'ENDPOINT = 'https://api.video.dmm.co.jp/graphql'