Skip to content

armgit / peach

Public Imported from GitHub
0

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

refactor: decouple ffmpeg from Stash runtime

Peach local maintenance1c655cf5a7fa
diff --git a/README.md b/README.md
index 419c19e55..f59c244e3 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Peach(蜜桃)是一个单用户、本地优先的个人媒体系统:统一
项目仓库不保存媒体、数据库、凭据、快照、封面或运行日志。
-`R:\peach-data` 使用固定分层:`database` 保存真相库,`generated` 保存可再生成的视觉资产,`sources` 保存原始分析输入,`state` 保存人工维护状态,`secrets` 保存本机凭据材料,`logs` 保存运行记录,`archive` 保存历史备份,`inbox` 是临时下载落地区。
+`R:\peach-data` 使用固定分层:`database` 保存真相库,`generated` 保存可再生成的视觉资产,`sources` 保存原始分析输入,`state` 保存人工维护状态,`secrets` 保存本机凭据材料,`logs` 保存运行记录,`archive` 保存历史备份,`inbox` 是临时下载落地区,`tools` 保存不进入 Git 的本机运行时工具。
## 结构
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 4fe344920..c8d128d84 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -43,3 +43,4 @@ AI/external metadata -> reviewed candidates -> ledger
- `logs/`: current operational logs
- `archive/`: historical migration evidence and backups
- `inbox/`: transient imports awaiting processing
+- `tools/`: machine-local managed runtimes such as FFmpeg; binaries and licenses stay outside Git
diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md
index 8d21b53fc..a168cae9f 100644
--- a/docs/HANDOFF.md
+++ b/docs/HANDOFF.md
@@ -21,6 +21,7 @@ This is durable operating knowledge, not a per-session transcript.
## Operations
- Main command: `peach serve|migrate` after editable installation.
+- FFmpeg/ffprobe resolve from explicit environment overrides, then `R:\peach-data\tools\ffmpeg\bin`, then `PATH`. No active code may fall back to the Stash private directory.
- Long-running inventory helpers are under `scripts/`; their scheduled tasks use `R:\peach-app\.venv\Scripts\python.exe`. They use absolute data paths and may be interrupted/restarted where their own locking contract allows it.
- Check ports 80, 8900 and 9999 before starting or switching services.
- Report verification separately: static/unit/API, desktop browser, 390×844 browser, and whether production was actually restarted.
diff --git a/docs/STASH.md b/docs/STASH.md
index 0ae94be88..020183ec1 100644
--- a/docs/STASH.md
+++ b/docs/STASH.md
@@ -11,7 +11,7 @@ Peach 最终可以完全去 Stash,但现在不能直接卸载。Web 主链已
- GraphQL 实际暴露 screenshot/preview/stream/webp/vtt/sprite,以及 Direct、MP4、WebM、HLS、DASH、original/480p/240p stream。
- Stash generated 实际只有 80 sprite + 80 VTT(约 17.5 MB),transcodes/screenshots 为空。
- Peach 自有 snapshots 11,457 个(约 1.8 GB)、posters 855、avatars 50,覆盖范围并不等价。
-- 代码中 19 个非文档文件直连 Stash GraphQL,11 个文件硬编码 Stash 私有 `ffmpeg-btbn` 路径。
+- 初次审计的旧树中有 19 个非文档文件直连 Stash GraphQL、11 个文件硬编码 Stash 私有 `ffmpeg-btbn` 路径;项目整理后这些数字只作为迁移基线,不代表当前活跃树。
## 逐项判断
@@ -43,17 +43,17 @@ Peach 最终可以完全去 Stash,但现在不能直接卸载。Web 主链已
## 2026-08-14 第二阶段进展
- 新增集中 `StashClient`,FastAPI/Media Engine 新代码不再各自实现 GraphQL transport。
-- 新增独立 `FFmpegResolver`:环境变量/Peach 托管目录/PATH 优先,Stash 私有目录只作可关闭 fallback。
+- `FFmpegResolver` 现在只接受环境变量、`R:\peach-data\tools\ffmpeg` 和 PATH;Stash 私有目录 fallback 已删除。
- FastAPI 已用 Starlette `FileResponse` 替换候选入口的手写 Range,并验证普通、指定区间、suffix、
越界 416、HEAD、ETag、Last-Modified。
-- 旧 19 个脚本直连和 11 个硬编码依赖尚未归零;不能因此宣称已经去 Stash。
+- 活跃代码中的 Stash 私有 FFmpeg 路径已归零;剩余 GraphQL transport 是集中 adapter 与 `scripts/ledger.py` 的一个待迁移 helper,仍不能宣称已经去 Stash。
## 验收门槛
-关闭 Stash 前必须完成:2,551 Scene 全关联;842 Performer、126 Tag、140 Studio 与全部关系、别名、hash 有 external ID/provenance;24,980 视频探测覆盖不回退;10,714 个账本 snapshot 仍可访问;常用和异常 Range、seek、两路并发及不兼容编码转码通过;关键别名/Studio/组合标签/云资产搜索一致;19/11 个依赖计数归零;关闭和回退均演练。
+关闭 Stash 前必须完成:2,551 Scene 全关联;842 Performer、126 Tag、140 Studio 与全部关系、别名、hash 有 external ID/provenance;24,980 视频探测覆盖不回退;10,714 个账本 snapshot 仍可访问;常用和异常 Range、seek、两路并发及不兼容编码转码通过;关键别名/Studio/组合标签/云资产搜索一致;GraphQL 直连与私有二进制依赖归零;关闭和回退均演练。
## 许可证
-Stash v0.31.1 是 AGPL-3.0。Peach 只通过公开协议调用独立 Stash 进程,不复制其 Go 实现。当前 Stash 目录中的 FFmpeg 是启用 GPLv3/x264/x265 的构建:本机调用与安装包分发是不同问题;后续必须改为独立 resolver,并在捆绑时处理许可证、源码和通知义务。
+Stash v0.31.1 是 AGPL-3.0。Peach 只通过公开协议调用独立 Stash 进程,不复制其 Go 实现。当前 Peach-managed FFmpeg 是从本机既有构建复制的 GPLv3/x264/x265 shared bundle,完整 `LICENSE.txt` 已保留且仅供此个人实例运行;它不进入 Git,也不能在未处理源码、许可证和通知义务前作为 Peach 安装包分发。
官方依据:[Stash 架构](https://github.com/stashapp/stash/blob/develop/docs/ARCHITECTURE.md)、[Scene schema](https://github.com/stashapp/stash/blob/v0.31.1/graphql/schema/types/scene.graphql)、[AGPL-3.0](https://raw.githubusercontent.com/stashapp/stash/v0.31.1/LICENSE)、[FFmpeg 法律说明](https://www.ffmpeg.org/legal.html)。
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 3e0155fa0..8b0e2a37f 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -4,7 +4,7 @@ Last verified: 2026-08-14
## Runtime
-- Production Peach: FastAPI `0.2.0` from `R:\peach-app` on `0.0.0.0:80`, PID observed as 46596; health mode is `fastapi`.
+- Production Peach: FastAPI `0.2.0` from `R:\peach-app` on `0.0.0.0:80`, PID observed as 58508; health mode is `fastapi`.
- Stash: `127.0.0.1:9999`, PID observed as 35332.
- Traffic monitor: running through `RM-TrafficWatch` from `R:\peach-app\.venv`; all probe/sheets tasks use the same project environment.
- Runtime Python: 3.14.7. The removed system Python 3.12 invalidated the old venv, which was rebuilt and reverified before production start.
@@ -17,15 +17,15 @@ Runtime PIDs are observations, not configuration; always re-check them.
- FastAPI serves home, legacy-compatible JSON, standard Range/HEAD media, thumbnails, posters, avatars and logos.
- Default ledger connections in the compatibility query layer are read-only; activity/play/feedback writes are explicit.
-- FFmpeg resolution is centralized: environment, Peach-managed binary, PATH, then temporary Stash fallback.
-- `R:\peach-data` now separates `database/generated/sources/state/secrets/logs/archive/inbox`; the old empty root Inbox and old Resources/Tools compatibility surface are removed.
-- 23 isolated tests passed under Python 3.14 after the real migration and production restart.
+- FFmpeg/ffprobe are Peach-managed under `R:\peach-data\tools\ffmpeg`; resolver order is environment, managed bundle, then PATH. Active code has no Stash private binary fallback.
+- `R:\peach-data` now separates `database/generated/sources/state/secrets/logs/archive/inbox/tools`; the old empty root Inbox and old Resources/Tools compatibility surface are removed.
+- 24 isolated tests passed under Python 3.14 after the real migration and FFmpeg decoupling.
- Real migration preserved 81,873 assets and 59,697 tag links; both live database and backup passed `integrity_check` and `foreign_key_check`.
- Desktop 1280×720 and mobile 390×844 browser checks passed on the same application candidate before the schema-only migration; visual checks were not rerun after migration because no browser instance was connected.
- Restarted production port 80 passed health, home, 24,980-item all-source list, 2,552-item local list and one-byte `206 Partial Content` Range smoke checks.
## Next work
-1. Move FFmpeg/ffprobe to a Peach-managed installation and remove the temporary Stash binary fallback.
-2. Extract the remaining query/write functions from `compat_web.py`, then delete that compatibility module.
+1. Extract the remaining query/write functions from `compat_web.py`, then delete that compatibility module.
+2. Route the remaining `scripts/ledger.py` Stash import through the centralized adapter and formalize entity provenance.
3. Implement the first real online-source and AI provider adapters behind the existing boundaries.
diff --git a/scripts/probe.py b/scripts/probe.py
index 88dfa3ab4..80e64df27 100644
--- a/scripts/probe.py
+++ b/scripts/probe.py
@@ -15,8 +15,14 @@
"""
import os, sys, time, json, sqlite3, subprocess, threading, queue
+from peach.config import FFMPEG_DIR
+from peach.ffmpeg import FFmpegResolver
+
DB = r"R:\peach-data\database\ledger.db"
-FFPROBE = r"C:\Users\longm\AppData\Local\Stash\ffmpeg-btbn\ffmpeg-master-latest-win64-gpl-shared\bin\ffprobe.exe"
+_FFPROBE_CHOICE = FFmpegResolver(FFMPEG_DIR).ffprobe()
+if _FFPROBE_CHOICE is None:
+ raise RuntimeError("ffprobe is unavailable; install it under Peach data tools or PATH")
+FFPROBE = str(_FFPROBE_CHOICE.path)
LOG = r"R:\peach-data\logs\probe-{}.log".format(time.strftime("%Y%m%d-%H%M%S"))
a = sys.argv[1:]
diff --git a/scripts/sheets.py b/scripts/sheets.py
index 4bc5f499b..1c43b97cf 100644
--- a/scripts/sheets.py
+++ b/scripts/sheets.py
@@ -16,9 +16,16 @@
"""
import os, sys, time, hashlib, sqlite3, subprocess, threading, queue, tempfile, shutil
+from peach.config import FFMPEG_DIR
+from peach.ffmpeg import FFmpegResolver
+
DB = r"R:\peach-data\database\ledger.db"
-BIN = r"C:\Users\longm\AppData\Local\Stash\ffmpeg-btbn\ffmpeg-master-latest-win64-gpl-shared\bin"
-FFMPEG, FFPROBE = os.path.join(BIN, "ffmpeg.exe"), os.path.join(BIN, "ffprobe.exe")
+_FFMPEG_RESOLVER = FFmpegResolver(FFMPEG_DIR)
+_FFMPEG_CHOICE = _FFMPEG_RESOLVER.ffmpeg()
+_FFPROBE_CHOICE = _FFMPEG_RESOLVER.ffprobe()
+if _FFMPEG_CHOICE is None or _FFPROBE_CHOICE is None:
+ raise RuntimeError("ffmpeg/ffprobe are unavailable; install them under Peach data tools or PATH")
+FFMPEG, FFPROBE = str(_FFMPEG_CHOICE.path), str(_FFPROBE_CHOICE.path)
OUTROOT = r"R:\peach-data\generated\snapshots\cloud"
LOG = r"R:\peach-data\logs\sheets-{}.log".format(time.strftime("%Y%m%d-%H%M%S"))
diff --git a/src/peach/api.py b/src/peach/api.py
index 093e0834c..ac7cb41b6 100644
--- a/src/peach/api.py
+++ b/src/peach/api.py
@@ -4,7 +4,7 @@ from typing import Any
from fastapi import Body, FastAPI, Request
from fastapi.responses import FileResponse, JSONResponse, PlainTextResponse, Response
-from .config import PROJECT_ROOT, PeachSettings
+from .config import PeachSettings
from .ffmpeg import FFmpegResolver
from .legacy_web import load_legacy
from .media import FilesystemMediaService, MediaNotFound, MediaUnavailable
@@ -32,7 +32,7 @@ def create_app(settings: PeachSettings | None = None) -> FastAPI:
settings = settings or PeachSettings()
legacy = load_legacy(settings.legacy_module_path, settings.db_path, settings.token)
repository = LedgerRepository(settings.db_path)
- resolver = FFmpegResolver(PROJECT_ROOT, settings.allow_legacy_stash_ffmpeg)
+ resolver = FFmpegResolver(settings.ffmpeg_root)
media_service = FilesystemMediaService(
repository, settings.allowed_media_roots, settings.snapshot_root,
)
diff --git a/src/peach/compat_web.py b/src/peach/compat_web.py
index 0402bb122..8c70dcb31 100644
--- a/src/peach/compat_web.py
+++ b/src/peach/compat_web.py
@@ -26,6 +26,9 @@ from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
from http.cookies import SimpleCookie
from pathlib import Path
+from peach.config import FFMPEG_DIR
+from peach.ffmpeg import FFmpegResolver
+
DB = r"R:\peach-data\database\ledger.db"
HERE = os.path.dirname(os.path.abspath(__file__))
PAGE = os.path.join(os.path.dirname(os.path.dirname(HERE)), "web", "index.html")
@@ -33,10 +36,11 @@ SNAP_ROOT = r"R:\peach-data\generated\snapshots"
LOGO_ROOT = r"R:\peach-data\generated\logos"
AVA_ROOT = r"R:\peach-data\generated\avatars"
POSTER_ROOT = r"R:\peach-data\generated\posters"
-FFPROBE = os.path.join(os.environ.get("LOCALAPPDATA", ""), "Stash", "ffmpeg-btbn",
- "ffmpeg-master-latest-win64-gpl-shared", "bin", "ffprobe.exe")
-FFMPEG = os.path.join(os.environ.get("LOCALAPPDATA", ""), "Stash", "ffmpeg-btbn",
- "ffmpeg-master-latest-win64-gpl-shared", "bin", "ffmpeg.exe")
+_FFMPEG_RESOLVER = FFmpegResolver(FFMPEG_DIR)
+_FFMPEG_CHOICE = _FFMPEG_RESOLVER.ffmpeg()
+_FFPROBE_CHOICE = _FFMPEG_RESOLVER.ffprobe()
+FFMPEG = str(_FFMPEG_CHOICE.path) if _FFMPEG_CHOICE else ""
+FFPROBE = str(_FFPROBE_CHOICE.path) if _FFPROBE_CHOICE else ""
# 导入模块时绝不能解析进程级 sys.argv:Uvicorn 等宿主也使用 --host/--port。
# 旧服务仍从 main() 显式读取同样的参数,现有启动命令保持兼容。
diff --git a/src/peach/config.py b/src/peach/config.py
index 817da6915..c381eb3ff 100644
--- a/src/peach/config.py
+++ b/src/peach/config.py
@@ -14,6 +14,8 @@ SECRETS_DIR = DATA_ROOT / "secrets"
LOG_DIR = DATA_ROOT / "logs"
ARCHIVE_DIR = DATA_ROOT / "archive"
INBOX_DIR = DATA_ROOT / "inbox"
+TOOLS_DIR = DATA_ROOT / "tools"
+FFMPEG_DIR = TOOLS_DIR / "ffmpeg"
MIGRATIONS_DIR = PROJECT_ROOT / "migrations"
@@ -29,4 +31,4 @@ class PeachSettings:
poster_root: Path = GENERATED_DIR / "posters"
avatar_root: Path = GENERATED_DIR / "avatars"
logo_root: Path = GENERATED_DIR / "logos"
- allow_legacy_stash_ffmpeg: bool = True
+ ffmpeg_root: Path = FFMPEG_DIR
diff --git a/src/peach/ffmpeg.py b/src/peach/ffmpeg.py
index 01f4541a7..a792b799b 100644
--- a/src/peach/ffmpeg.py
+++ b/src/peach/ffmpeg.py
@@ -13,11 +13,10 @@ class BinaryChoice:
class FFmpegResolver:
- """统一二进制定位;Stash 私有目录只是显式、可关闭的迁移 fallback。"""
+ """Resolve explicit, Peach-managed, or PATH binaries without backend coupling."""
- def __init__(self, tools_dir: Path, allow_legacy_stash: bool = True):
- self.tools_dir = tools_dir
- self.allow_legacy_stash = allow_legacy_stash
+ def __init__(self, managed_root: Path):
+ self.managed_root = managed_root
def ffmpeg(self) -> BinaryChoice | None:
return self._resolve("ffmpeg", "PEACH_FFMPEG")
@@ -33,7 +32,7 @@ class FFmpegResolver:
if path.is_file():
return BinaryChoice(path.resolve(), "environment")
- managed = self.tools_dir / "bin" / f"{executable}{suffix}"
+ managed = self.managed_root / "bin" / f"{executable}{suffix}"
if managed.is_file():
return BinaryChoice(managed.resolve(), "peach-managed")
@@ -41,10 +40,4 @@ class FFmpegResolver:
if found:
return BinaryChoice(Path(found).resolve(), "path")
- if self.allow_legacy_stash:
- local = Path(os.environ.get("LOCALAPPDATA", ""))
- root = local / "Stash" / "ffmpeg-btbn"
- matches = sorted(root.glob(f"*/bin/{executable}.exe"), reverse=True)
- if matches:
- return BinaryChoice(matches[0].resolve(), "legacy-stash")
return None
diff --git a/tests/test_fastapi_api.py b/tests/test_fastapi_api.py
index bf6638f34..ef5ad89f2 100644
--- a/tests/test_fastapi_api.py
+++ b/tests/test_fastapi_api.py
@@ -67,7 +67,7 @@ class FastApiContractTests(unittest.IsolatedAsyncioTestCase):
db_path=self.db, token="secret", page_path=self.page,
allowed_media_roots=(self.media_root,), snapshot_root=self.snapshot_root,
poster_root=self.poster_root, avatar_root=self.avatar_root, logo_root=self.logo_root,
- allow_legacy_stash_ffmpeg=False,
+ ffmpeg_root=self.root / "ffmpeg",
))
self.client = httpx.AsyncClient(
transport=httpx.ASGITransport(app=app), base_url="http://test"
diff --git a/tests/test_media.py b/tests/test_media.py
index f419ea39f..812ef8c3d 100644
--- a/tests/test_media.py
+++ b/tests/test_media.py
@@ -49,11 +49,22 @@ class MediaEngineTests(unittest.TestCase):
root = Path(tmp)
binary = root / "ffmpeg.exe"
binary.write_bytes(b"test")
- resolver = FFmpegResolver(root, allow_legacy_stash=False)
+ resolver = FFmpegResolver(root)
with patch.dict("os.environ", {"PEACH_FFMPEG": str(binary)}, clear=False):
choice = resolver.ffmpeg()
self.assertEqual(choice.source, "environment")
+ def test_ffmpeg_resolver_uses_managed_bundle(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ binary = root / "bin" / "ffmpeg.exe"
+ binary.parent.mkdir()
+ binary.write_bytes(b"test")
+ with patch.dict("os.environ", {"PEACH_FFMPEG": ""}, clear=False), \
+ patch("peach.ffmpeg.shutil.which", return_value=None):
+ choice = FFmpegResolver(root).ffmpeg()
+ self.assertEqual(choice.source, "peach-managed")
+
def test_offline_windows_root_does_not_block_startup(self):
with patch.object(Path, "resolve", side_effect=OSError("offline")):
path = normalized_path(Path("B:/"))