Peach: Local-first video metadata scraper and media manager.
refactor(scripts): 演示库去掉人像缓推短片
longmeidaof525ac48a4e2
diff --git a/docs/README_MAINTENANCE.md b/docs/README_MAINTENANCE.mdindex 9de0ecd3f..0ffb5d8ac 100644--- a/docs/README_MAINTENANCE.md+++ b/docs/README_MAINTENANCE.md@@ -51,9 +51,10 @@ README、教程与网站的截图一律取自演示库,不取自真实馆藏& .\.venv\Scripts\python.exe -X utf8 scripts\demo_dataset.py --output <目录> --count 24```-画面由 `--art` 决定。默认 `portrait`:人像取自 Gfriends 图库,封面、头像与播放画面都由-这张人像排版而成,出演者用清单里的规范艺名,界面因此有真实馆藏的样子。`synthetic` 是-FFmpeg lavfi 的渐变、测试图与分形加 Pillow 几何海报,不联网,规模基准与测试走它。+封面由 `--art` 决定。默认 `portrait`:人像取自 Gfriends 图库,封面与图集由这张人像排版+而成,出演者用清单里的规范艺名,界面因此有真实馆藏的样子。`synthetic` 是 Pillow 几何+海报,不联网,规模基准与测试走它。两种模式的短片都是 FFmpeg lavfi 的渐变、测试图与分形,+只占位,不拿去当演示视频。两种模式下作品、厂牌、系列与标签一律虚构:真实艺名配虚构作品,演示素材因此不会断言「某人演过某片」这种它没有资格断言的事。diff --git a/scripts/demo_dataset.py b/scripts/demo_dataset.pyindex 47f09b4d6..0bd379c8a 100644--- a/scripts/demo_dataset.py+++ b/scripts/demo_dataset.py@@ -4,10 +4,12 @@演示素材不取自真实馆藏。画面有两种来源,由 `--art` 选:- `portrait`(默认):人像取自 Gfriends 图库里一份人工逐张看过的清单- (`scripts/demo-portraits.json`),封面、头像与播放画面都由这张人像排版而成,- 出演者用清单里的规范艺名。界面因此有真实馆藏的样子。-- `synthetic`:画面是 FFmpeg lavfi 的渐变、测试图与分形,海报是 Pillow 画的几何图,- 出演者也是虚构名。不联网,规模基准与测试用它。+ (`scripts/demo-portraits.json`),封面与图集由这张人像排版而成,出演者用清单里的+ 规范艺名。界面因此有真实馆藏的样子。+- `synthetic`:海报是 Pillow 画的几何图,出演者也是虚构名。不联网,规模基准与测试用它。++两种模式的短片都是 FFmpeg lavfi 的渐变、测试图与分形,只占位让 scan、probe 与播放器+有东西可读。两种模式下作品、厂牌、系列和标签一律虚构,不与 `catalog_rules` 的成人词表相交,由`tests/test_demo_dataset.py` 把守——真实艺名配虚构作品,演示素材因此不会断言@@ -308,10 +310,10 @@ def write_video(ffmpeg: str | None, item: DemoItem, destination: Path, seed: intclass PortraitArt:- """人像模式下的画面产出:取图、画封面、渲染播放画面。+ """人像模式下的封面产出:取图、画封面。- 取回的人像和渲染好的底图都按「一位一张」缓存——一套库里同一位常出现好几次,- 每次重新取图重新渲染,二十四条作品要多花十几倍时间。+ 取回的人像按「一位一张」缓存——一套库里同一位常出现好几次,每次重新取图,+ 二十四条作品要多联网十几倍。"""def __init__(self, portraits: list, cache_dir: Path, fetch) -> None:@@ -319,7 +321,6 @@ class PortraitArt:self.cache_dir = cache_dirself.fetch = fetchself.sources: dict[str, Path] = {}- self.frames: dict[tuple[str, str], Path] = {}def source(self, item: DemoItem) -> Path:if item.portrait not in self.sources:@@ -334,15 +335,6 @@ class PortraitArt:performer=item.portrait, studio=item.studio or item.creator or "未署名",year=(item.release_date[:4] or "2026"), orientation=item.orientation)- def video(self, item: DemoItem, destination: Path, ffmpeg: str) -> None:- key = (item.portrait, item.orientation)- if key not in self.frames:- base = self.cache_dir / f"frame-{item.orientation}-{len(self.frames):03d}.png"- demo_portraits.draw_frame(self.source(item), base, item.orientation)- self.frames[key] = base- demo_portraits.render_video(ffmpeg, self.frames[key], destination,- duration=item.duration, orientation=item.orientation)-def resolve_portraits(art: str, portraits: list | None) -> list | None:"""定下这一趟用哪套人像。`synthetic` 返回 None,走几何图那条路。"""@@ -393,11 +385,7 @@ def generate(output: Path, *, count: int, seed: int, video: str, duration: int,started = time.time()for index, item in enumerate(items, 1):- target = output / item.path- if artist and item.portrait and video == "ffmpeg":- artist.video(item, target, ffmpeg)- else:- write_video(ffmpeg if video == "ffmpeg" else None, item, target, seed + index)+ write_video(ffmpeg if video == "ffmpeg" else None, item, output / item.path, seed + index)if item.nfo:(output / item.nfo).write_text(render_nfo(item), encoding="utf-8")if item.poster:diff --git a/scripts/demo_portraits.py b/scripts/demo_portraits.pyindex ce5325771..5f195bb72 100644--- a/scripts/demo_portraits.py+++ b/scripts/demo_portraits.py@@ -1,4 +1,4 @@-"""演示库的人像素材:按钉死的清单取图,再排成封面、头像与播放画面。+"""演示库的人像素材:按钉死的清单取图,再排成封面与头像。图片字节不进仓库(ADR-0026),进仓库的只有 `demo-portraits.json` 这份清单——去哪取、取到的该是什么哈希。生成器运行时按清单取一次,缓存在输出目录旁边。@@ -11,7 +11,6 @@ from __future__ import annotationsimport hashlibimport json-import subprocessimport urllib.parseimport urllib.requestfrom dataclasses import dataclass@@ -25,8 +24,6 @@ MAX_IMAGE_BYTES = 4 * 1024 * 1024COVER_LANDSCAPE = (800, 538)COVER_PORTRAIT = (600, 900)AVATAR_SIDE = 480-FRAME_LANDSCAPE = (1280, 720)-FRAME_PORTRAIT = (720, 1280)#: 封面与画面上的文字要落到 CJK 字形上。按平台找一份,找不到就不写字——#: 缺字体的机器上宁可出一张没有标题的封面,也不要满屏豆腐块。@@ -198,62 +195,3 @@ def draw_avatar(source: Path, destination: Path) -> None:square = image.crop((left, top, left + side, top + side))destination.parent.mkdir(parents=True, exist_ok=True)square.resize((AVATAR_SIDE, AVATAR_SIDE), Image.LANCZOS).save(destination, quality=90)---#: 裁切填满能接受的形状差距。人像与画面同朝向时落在这个区间内,直接铺满;-#: 差得太远(竖版人像塞进横画面)再退回居中加模糊背景,否则会裁得只剩一条。-FILL_RATIO_RANGE = (0.6, 1.7)---def draw_frame(source: Path, destination: Path, orientation: str) -> None:- """播放画面的底图。-- 人像与画面同朝向就裁切铺满——真实视频的画面本来就是满的,中间一块人像配一圈- 模糊背景,一看就是拿静态图凑的。朝向对不上才退回居中加模糊背景。-- 按两倍渲染——缓推是在这张底图上放大的,原生分辨率推起来会抖。- """- from PIL import Image, ImageFilter-- size = FRAME_PORTRAIT if orientation == "竖屏" else FRAME_LANDSCAPE- image = Image.open(source).convert("RGB")- fit = (image.width / image.height) / (size[0] / size[1])- if FILL_RATIO_RANGE[0] <= fit <= FILL_RATIO_RANGE[1]:- frame = _cover_box(image, size, anchor=0.22)- else:- frame = _cover_box(image, size, anchor=0.5)- frame = frame.filter(ImageFilter.GaussianBlur(size[0] // 46)).point(- lambda v: int(v * 0.5))- front = image.copy()- front.thumbnail((size[0], size[1]), Image.LANCZOS)- frame.paste(front, ((size[0] - front.width) // 2, (size[1] - front.height) // 2))- destination.parent.mkdir(parents=True, exist_ok=True)- frame.resize((size[0] * 2, size[1] * 2), Image.LANCZOS).save(destination)---def video_command(ffmpeg: str, base: Path, destination: Path, *, duration: int,- orientation: str) -> list[str]:- """人像缓推:一镜到底的慢推,没有转场也没有文字动画。-- `d` 取满整段时长的帧数,缓推才不会中途回弹重来。- """- size = FRAME_PORTRAIT if orientation == "竖屏" else FRAME_LANDSCAPE- frames = max(1, duration * 30)- return [- ffmpeg, "-y", "-v", "error", "-loop", "1", "-i", str(base),- "-vf", (f"zoompan=z='min(zoom+0.0004,1.14)':d={frames}:"- "x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':"- f"s={size[0]}x{size[1]}:fps=30,format=yuv420p"),- "-t", str(duration), "-an", "-c:v", "libx264", "-preset", "veryfast",- "-crf", "26", "-movflags", "+faststart", str(destination),- ]---def render_video(ffmpeg: str, base: Path, destination: Path, *, duration: int,- orientation: str) -> None:- destination.parent.mkdir(parents=True, exist_ok=True)- result = subprocess.run(- video_command(ffmpeg, base, destination, duration=duration, orientation=orientation),- capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=300)- if result.returncode != 0 or not destination.is_file() or destination.stat().st_size == 0:- raise RuntimeError(f"ffmpeg 生成 {destination.name} 失败:{result.stderr.strip()[:300]}")diff --git a/tests/test_demo_dataset.py b/tests/test_demo_dataset.pyindex a4cdd38f9..63cfef3b3 100644--- a/tests/test_demo_dataset.py+++ b/tests/test_demo_dataset.py@@ -216,7 +216,7 @@ class PortraitManifestTests(unittest.TestCase):for entry in entries:self.assertEqual(len(entry.sha256), 64, entry.name)self.assertTrue(entry.name.strip() and "\n" not in entry.name, entry.name)- # 封面最长边 900、播放底图两倍渲染到 2560,小于 640 的原图撑不起来。+ # 竖版封面高 900,长边不到 640 的原图放大上去就糊了。self.assertGreaterEqual(max(entry.width, entry.height), 640, entry.name)self.assertTrue(entry.url.startswith("https://"), entry.name)