Peach: Local-first video metadata scraper and media manager.
fix: skip black frames in follow covers
longmeidao6559ffd4436c
diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 320bd0b6f..221af94a8 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -94,7 +94,7 @@| `taste_history.py` 自写 Chrome/Firefox/Zen/Safari SQLite 解析 | **已替换为 `browserexport==0.4.4`** | Python 3.14 依赖解析通过;审计 POC 在本机 7 个 Chrome/Firefox/Zen profile 上与 Peach 逐库计数完全一致,macOS 的 Safari/Zen/Firefox/Chrome 路径发现有独立测试。首个消费者是 `/taste` 的本机读取与导出导入;Peach 保留 SQLite backup、Takeout、私有原始存储、域名分析和 candidate 生成,并在 Windows 自己关闭只读连接以避开依赖的文件句柄滞留。跨主机同步不由该依赖提供,仍须显式导出、传输和按来源去重合并。 || `jobs.PidFileLock` | **优先替换为 `portalocker==4.3.0` 的 `PidFileLock`** | Python 3.14 解析通过,现成覆盖 PID 写入、锁持有者、原子替换、陈旧文件与释放清理。Peach 只保留任务归属和错误文案映射。 || Rule34Video 媒体页解析 | **部分替换为 `yt-dlp==2026.8.19`** | 对真实视频 4533145 无写入提取成功,取得 4 个格式、31 个标签、缩略图与时间。Peach 仍负责作者分页、合集/超多 model 排除、来源分组和跨站去重。 |-| Rule34.xxx / Paheal 高清封面 | **固定参考 gallery-dl `86047cf67a12bdb6ff1085774f8ad9fc347e8da9`,运行时复用现有 FFmpeg** | gallery-dl(GPL-2.0)只作协议行为证据,不引入或复制为运行时:booru URL 明确支持 `sample_url`/`preview_url`/`file_url` 回退,Paheal 抽取器只取得原始 `file_url`。真实 POC 中 Rule34.xxx 历史 preview 为 250×141、同哈希 sample 为 1920×1080;Paheal 页面只有低清 poster/og:image,原视频首帧可在约 2.3 秒生成 1280×720 JPEG。Peach 负责 URL 白名单、同源代理、按需双并发抽帧、缓存与低清失败回退,不新增依赖、不改 ledger。 |+| Rule34.xxx / Paheal 高清封面 | **固定参考 gallery-dl `86047cf67a12bdb6ff1085774f8ad9fc347e8da9`,运行时复用现有 FFmpeg** | gallery-dl(GPL-2.0)只作协议行为证据,不引入或复制为运行时:booru URL 明确支持 `sample_url`/`preview_url`/`file_url` 回退,Paheal 抽取器只取得原始 `file_url`。真实 POC 中 Rule34.xxx 历史 preview 为 250×141、同哈希 sample 为 1920×1080;Paheal 页面只有低清 poster/og:image,原视频可生成 1280×720 JPEG。视频缩略图工具 ffmpegthumbnailer 默认取 10% 位置,Peach 不再引入 GPL 运行时;直接复用 FFmpeg `blackframe` 导出的 `lavfi.blackframe.pblack`,在开头 30 秒选第一张黑色像素低于 98% 的帧,并用版本化缓存键淘汰旧黑帧。Peach 继续负责 URL 白名单、同源代理、按需双并发抽帧、缓存与低清失败回退,不新增依赖、不改 ledger。 || FANBOX 正文解析 | **已采用 PixivUtil2 `v20251112` / `e537e96` 的公开正文模型** | Peach 的独立规范化 DTO 已覆盖 image/text/file/article/video/entry、`fileMap`、`embedMap`、`urlEmbedMap` 和旧 HTML 正文,并保留正文顺序、稳定去重、可播放媒体与文件页边界;BSD-2-Clause 依据写在实现头部。PixivUtil2 是完整下载器而非可嵌入解析库,因此不引入整套依赖;传输继续固定 `curl_cffi==0.16.2`。真实公开帖 12228983 只读 POC 得到 article、6 图和 Gofile `OS2Qz9`。 || `mp4index.py` 有界 MP4 关键帧索引 | **保留自研** | PyAV 需要 demux,`pymp4` 依赖旧 Construct,Bento4 是额外二进制;都不能证明在云盘文件上保留“只读 moov/stss/stts、避免整片流量”的约束。 || `certs.py` 固定项目 CA 与短期叶证书 | **保留自研 policy,继续调用 OpenSSL** | mkcert 会接管本机 CA 安装/私钥,不能保持跨设备固定项目 CA;cryptography 只替换证书编码且增加原生依赖,不能删除 Peach 的 Apple 398 天与 CA 生命周期策略。 |diff --git a/src/peach/__init__.py b/src/peach/__init__.pyindex fb85ae268..b551c348d 100644--- a/src/peach/__init__.py+++ b/src/peach/__init__.py@@ -1,3 +1,3 @@"""Peach application package."""-__version__ = "0.7.8"+__version__ = "0.7.9"diff --git a/src/peach/follow_covers.py b/src/peach/follow_covers.pyindex 435f94aee..342d0b7fa 100644--- a/src/peach/follow_covers.py+++ b/src/peach/follow_covers.py@@ -1,7 +1,8 @@"""Generate cached high-resolution covers for remote follow videos.Paheal exposes the original video and a 150/250px thumbnail, but no larger still.-The card therefore extracts the first decodable frame once and serves the cached JPEG.+The card therefore extracts the first non-black decodable frame once and serves the+cached JPEG."""from __future__ import annotations@@ -16,6 +17,20 @@ from .follow_store import FollowItemRowfrom .follow_stream import FollowMediaResolver, FollowMediaUnavailable+# FFmpeg's blackframe filter exports ``lavfi.blackframe.pblack`` only when the+# configured amount is reached. Setting amount=0 makes that percentage available+# on every frame; metadata/select can then drop frames that are at least 98% black.+# Scan at most the opening 30 seconds so an all-black/broken video still reaches the+# existing low-resolution fallback promptly.+FOLLOW_COVER_SCAN_SECONDS = 30+FOLLOW_COVER_FILTER = (+ "blackframe=amount=0:threshold=32,"+ "metadata=select:key=lavfi.blackframe.pblack:value=98:function=less,"+ "scale='min(1280,iw)':-2"+)+_CACHE_VERSION = "nonblack-v1"++class FollowCoverUnavailable(RuntimeError):pass@@ -47,7 +62,9 @@ class FollowCoverService:if choice is None:raise FollowCoverUnavailable("ffmpeg 不可用")- fingerprint = hashlib.sha256(target.url.encode("utf-8")).hexdigest()[:16]+ fingerprint = hashlib.sha256(+ f"{_CACHE_VERSION}\0{target.url}".encode("utf-8")+ ).hexdigest()[:16]destination = self.root / f"{item.id}-{fingerprint}.jpg"if destination.is_file():return destination@@ -65,8 +82,8 @@ class FollowCoverService:if target.referer:command.extend(("-referer", target.referer))command.extend((- "-i", target.url, "-frames:v", "1",- "-vf", "scale='min(1280,iw)':-2", "-update", "1",+ "-t", str(FOLLOW_COVER_SCAN_SECONDS), "-i", target.url,+ "-frames:v", "1", "-vf", FOLLOW_COVER_FILTER, "-update", "1","-q:v", "4", str(temporary),))try:diff --git a/tests/test_follow_covers.py b/tests/test_follow_covers.pyindex d434f9f2b..4e2dde73a 100644--- a/tests/test_follow_covers.py+++ b/tests/test_follow_covers.py@@ -5,8 +5,15 @@ from pathlib import Pathfrom types import SimpleNamespacefrom unittest import mock-from peach.ffmpeg import BinaryChoice-from peach.follow_covers import FollowCoverService, FollowCoverUnavailable+from PIL import Image++from peach.ffmpeg import BinaryChoice, FFmpegResolver+from peach.follow_covers import (+ FOLLOW_COVER_FILTER,+ FOLLOW_COVER_SCAN_SECONDS,+ FollowCoverService,+ FollowCoverUnavailable,+)from peach.follow_stream import ResolvedFollowMedia@@ -39,7 +46,7 @@ class FollowCoverServiceTests(unittest.TestCase):id=7, provider=provider, metadata={"media_kind": kind},url="https://rule34.paheal.net/post/view/7")- def test_first_frame_is_generated_once_and_cached(self):+ def test_first_non_black_frame_is_generated_once_and_cached(self):commands = []def run(command, **kwargs):@@ -54,7 +61,55 @@ class FollowCoverServiceTests(unittest.TestCase):self.assertEqual(first.read_bytes(), b"jpeg")self.assertEqual(len(commands), 1)self.assertIn("-frames:v", commands[0])- self.assertIn("scale='min(1280,iw)':-2", commands[0])+ filter_value = commands[0][commands[0].index("-vf") + 1]+ self.assertIn("blackframe=amount=0:threshold=32", filter_value)+ self.assertIn(+ "metadata=select:key=lavfi.blackframe.pblack:value=98:function=less",+ filter_value,+ )+ self.assertIn("scale='min(1280,iw)':-2", filter_value)+ self.assertEqual(+ commands[0][commands[0].index("-t") + 1],+ str(FOLLOW_COVER_SCAN_SECONDS),+ )++ def test_ffmpeg_filter_skips_a_black_intro(self):+ choice = FFmpegResolver(self.root).ffmpeg()+ if choice is None:+ self.skipTest("ffmpeg is unavailable")+ source = self.root / "black-intro.mp4"+ still = self.root / "selected.jpg"+ generated = subprocess.run(+ [+ str(choice.path), "-y", "-v", "error",+ "-f", "lavfi", "-i", "color=c=black:s=320x180:d=1:r=5",+ "-f", "lavfi", "-i", "color=c=red:s=320x180:d=1:r=5",+ "-filter_complex", "[0:v][1:v]concat=n=2:v=1:a=0[v]",+ "-map", "[v]", "-c:v", "libx264", "-pix_fmt", "yuv420p",+ str(source),+ ],+ capture_output=True,+ check=False,+ timeout=20,+ )+ if generated.returncode != 0:+ self.skipTest("test ffmpeg cannot create an H.264 fixture")+ selected = subprocess.run(+ [+ str(choice.path), "-y", "-v", "error", "-i", str(source),+ "-frames:v", "1", "-vf", FOLLOW_COVER_FILTER,+ "-q:v", "4", str(still),+ ],+ capture_output=True,+ check=False,+ timeout=20,+ )+ self.assertEqual(selected.returncode, 0, selected.stderr.decode(errors="replace"))+ with Image.open(still).convert("RGB") as image:+ red, green, blue = image.resize((1, 1)).getpixel((0, 0))+ self.assertGreater(red, 150)+ self.assertLess(green, 80)+ self.assertLess(blue, 80)def test_only_paheal_videos_enter_the_generator(self):for provider, kind in (("rule34xxx", "video"),