Peach: Local-first video metadata scraper and media manager.
fix(macos): 将媒体工具清单保存在签名资源目录
Peach local maintenanceb2c73f24b17e
diff --git a/scripts/build_macos_standalone.py b/scripts/build_macos_standalone.pyindex b785913d5..9c022031b 100644--- a/scripts/build_macos_standalone.py+++ b/scripts/build_macos_standalone.py@@ -114,7 +114,7 @@ def build(destination: Path, *, dmg: bool = True, target_arch: str | None = None], check=True, cwd=ROOT, env={**os.environ, "PEACH_MACOS_BUILD_INFO": str(work / "build-info.json"),"PEACH_MACOS_TARGET_ARCH": architecture})app = destination / "Peach.app"- tools = app / "Contents/MacOS/tools"+ tools = app / "Contents/Resources/tools"tools.mkdir()for tool in ("ffmpeg", "untrunc"):shutil.copytree(media_root / tool / tool, tools / tool)diff --git a/scripts/smoke_macos_media.py b/scripts/smoke_macos_media.pyindex dceac4a41..699d549de 100644--- a/scripts/smoke_macos_media.py+++ b/scripts/smoke_macos_media.py@@ -34,10 +34,10 @@ def smoke(app: Path, architecture: str) -> dict:assert ffmpeg.source == ffprobe.source == "peach-bundled"paths = [ffmpeg.path, ffprobe.path, repair, tunnel]for path in paths:- assert path.is_relative_to(executable.parent), path+ assert path.is_relative_to(executable.parent.parent), pathaudit_binary(path, architecture)for tool in ("ffmpeg", "untrunc"):- bundle = executable.parent / "tools" / tool+ bundle = executable.parent.parent / "Resources/tools" / toolmanifest = json.loads((bundle / "manifest.json").read_text())assert manifest["platform"] == "darwin" and manifest["architecture"] == architecturefrom media_tool_bundle import checked_filediff --git a/src/peach/ffmpeg.py b/src/peach/ffmpeg.pyindex 8e741b9c8..e32fe7e45 100644--- a/src/peach/ffmpeg.py+++ b/src/peach/ffmpeg.py@@ -14,6 +14,13 @@ class BinaryChoice:source: str+def bundled_tools_root() -> Path:+ executable = Path(sys.executable).resolve()+ if sys.platform == "darwin" and executable.parent.name == "MacOS":+ return executable.parent.parent / "Resources/tools"+ return executable.parent / "tools"++def binary_diagnostics(choice: BinaryChoice | None, *, decoders=False) -> dict:"""检查实际工具版本与 AV1 软件解码器;路径存在和可执行分别报告。"""facts = {'available': choice is not None, 'source': choice.source if choice else None,@@ -62,7 +69,7 @@ class FFmpegResolver:return BinaryChoice(path.resolve(), "environment")if getattr(sys, "frozen", False):- bundled = Path(sys.executable).parent / "tools" / "ffmpeg" / "bin" / f"{executable}{suffix}"+ bundled = bundled_tools_root() / "ffmpeg" / "bin" / f"{executable}{suffix}"if bundled.is_file():return BinaryChoice(bundled.resolve(), "peach-bundled")diff --git a/src/peach/mp4recover.py b/src/peach/mp4recover.pyindex f28f0e4be..d8ef49cc8 100644--- a/src/peach/mp4recover.py+++ b/src/peach/mp4recover.py@@ -21,6 +21,7 @@ from dataclasses import dataclassfrom pathlib import Path, PureWindowsPathfrom .mp4repair import RepairUnavailable, _top_level+from .ffmpeg import bundled_tools_rootUNTRUNC_ENV = "PEACH_UNTRUNC"#: 一部坏片最多试几个参照。每试一个都要把坏片完整读一遍,网盘上是实打实的流量。@@ -51,7 +52,7 @@ def untrunc_path(tools_root: Path) -> Path | None:return Path(configured).expanduser().resolve()name = f"untrunc{'.exe' if os.name == 'nt' else ''}"if getattr(sys, 'frozen', False):- bundled = Path(sys.executable).resolve().parent / 'tools' / 'untrunc' / name+ bundled = bundled_tools_root() / 'untrunc' / nameif bundled.is_file():return bundled.resolve()managed = Path(tools_root) / "untrunc" / namediff --git a/tests/test_macos_media.py b/tests/test_macos_media.pyindex 8b6204c76..119169388 100644--- a/tests/test_macos_media.py+++ b/tests/test_macos_media.py@@ -99,13 +99,14 @@ class MacMediaBundleTests(unittest.TestCase):from peach.tunnel import resolve_binaryexecutable = self.root / "Peach.app/Contents/MacOS/Peach"for name in ("tools/ffmpeg/bin/ffmpeg", "tools/ffmpeg/bin/ffprobe", "tools/untrunc/untrunc", "cloudflared"):- path = executable.parent / name+ path = (executable.parent.parent / "Resources" / name if name.startswith("tools/")+ else executable.parent / name)path.parent.mkdir(exist_ok=True, parents=True)path.write_bytes(b"fixture")with patch.object(sys, "executable", str(executable)), patch.object(sys, "frozen", True, create=True), \patch.dict("os.environ", {"PATH": ""}, clear=True):resolver = FFmpegResolver(self.root / "missing")self.assertEqual(resolver.ffmpeg().source, "peach-bundled")- self.assertEqual(resolver.ffprobe().path, executable.parent / "tools/ffmpeg/bin/ffprobe")- self.assertEqual(untrunc_path(self.root / "missing"), executable.parent / "tools/untrunc/untrunc")+ self.assertEqual(resolver.ffprobe().path, executable.parent.parent / "Resources/tools/ffmpeg/bin/ffprobe")+ self.assertEqual(untrunc_path(self.root / "missing"), executable.parent.parent / "Resources/tools/untrunc/untrunc")self.assertEqual(resolve_binary(), executable.parent / "cloudflared")