Skip to content

armgit / peach

Public Imported from GitHub
0

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.py
index 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.py
index 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), path
audit_binary(path, architecture)
for tool in ("ffmpeg", "untrunc"):
- bundle = executable.parent / "tools" / tool
+ bundle = executable.parent.parent / "Resources/tools" / tool
manifest = json.loads((bundle / "manifest.json").read_text())
assert manifest["platform"] == "darwin" and manifest["architecture"] == architecture
from media_tool_bundle import checked_file
diff --git a/src/peach/ffmpeg.py b/src/peach/ffmpeg.py
index 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.py
index f28f0e4be..d8ef49cc8 100644
--- a/src/peach/mp4recover.py
+++ b/src/peach/mp4recover.py
@@ -21,6 +21,7 @@ from dataclasses import dataclass
from pathlib import Path, PureWindowsPath
from .mp4repair import RepairUnavailable, _top_level
+from .ffmpeg import bundled_tools_root
UNTRUNC_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' / name
if bundled.is_file():
return bundled.resolve()
managed = Path(tools_root) / "untrunc" / name
diff --git a/tests/test_macos_media.py b/tests/test_macos_media.py
index 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_binary
executable = 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")