Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(media): Windows 媒体处理使用静默子进程

longmeidaoa1e6b0d6ae15
diff --git a/docs/REUSE.md b/docs/REUSE.md
index 8b44f2526..40b06d6d5 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -489,7 +489,9 @@ Python、npm 与 GitHub Actions 的版本由 `.github/dependabot.yml` 每周检
## 静态检查
-Python 复用 MIT 许可的 [Ruff](https://docs.astral.sh/ruff/) 0.16.10,版本由开发依赖和 `uv.lock` 固定。规则配置在 `pyproject.toml`;正式入口通过 `tests/test_python_lint.py` 扫描全仓自有 Python 文件,检查 Pyflakes、Ruff 支持的 Pylint 错误规则与四项常见行为隐患。Ruff 的 Pylint 规则覆盖是部分覆盖;需要跨模块推断的问题仍由对应行为回归验证。
+Windows 媒体子进程复用 Python 标准库 `subprocess.CREATE_NO_WINDOW`:入库探测、抽帧、拼图、预览、关注封面与媒体修复均显式设置,输出捕获、超时和取消按各入口原有契约处理。该标记由 Windows 原生支持,不引入依赖;见 [Python 文档](https://docs.python.org/3/library/subprocess.html#subprocess.CREATE_NO_WINDOW) 与 [Windows 创建标记](https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags)。
+
+Python 复用 MIT 许可的 [Ruff](https://docs.astral.sh/ruff/) 0.17.0,版本由开发依赖和 `uv.lock` 固定。规则配置在 `pyproject.toml`;正式入口通过 `tests/test_python_lint.py` 扫描全仓自有 Python 文件,检查 Pyflakes、Ruff 支持的 Pylint 错误规则与四项常见行为隐患。Ruff 的 Pylint 规则覆盖是部分覆盖;需要跨模块推断的问题仍由对应行为回归验证。
复用现有 Oxlint 1.85.0 的 correctness、`eqeqeq` 与 `oxc/no-accumulating-spread`,不新增依赖。源码和测试共用基础规则;shadcn 设计规则仅作用于自有 React 源码。
diff --git a/scripts/adopt_dependency_bump.py b/scripts/adopt_dependency_bump.py
index 0391fc0c4..e59e42cec 100644
--- a/scripts/adopt_dependency_bump.py
+++ b/scripts/adopt_dependency_bump.py
@@ -50,8 +50,13 @@ RECIPES = {
"web": {
"label": "根 package.json(手工 vendor 的四个 web 包)",
"manifests": ("package.json", "package-lock.json"),
- "derived": ("web/vendor/", "web/index.html"),
- "commands": (("npm", "ci", "--ignore-scripts"), ("npm", "run", "vendor:web")),
+ "derived": ("web/vendor/", "web/index.html", "web/dist/", "docs/REUSE.md",
+ "frontend/src/player/videojs.ts", "tests/test_web_ui.py",
+ "frontend/src/react/photo-lightbox/photo-lightbox.ts",
+ "frontend/test/react/photo-lightbox.test.tsx"),
+ "commands": (("npm", "ci", "--ignore-scripts"), ("npm", "run", "vendor:web"),
+ ("npm", "--prefix", "frontend", "ci"),
+ ("npm", "--prefix", "frontend", "run", "build")),
"checks": (),
},
"frontend": {
@@ -202,8 +207,9 @@ def bring_over(branch: str, manifests: tuple[str, ...], *, root: Path = ROOT,
def working_changes(*, root: Path = ROOT) -> list[str]:
- return [line for line in run(("git", "diff", "--name-only", "HEAD"), root=root).splitlines()
- if line]
+ tracked = run(("git", "diff", "--name-only", "HEAD"), root=root).splitlines()
+ added = run(("git", "ls-files", "--others", "--exclude-standard"), root=root).splitlines()
+ return sorted({line for line in (*tracked, *added) if line})
def commit_message(key: str, versions: list[str], pr: str | None,
diff --git a/src/peach/follow_covers.py b/src/peach/follow_covers.py
index 8fb4ca7bc..f6731db28 100644
--- a/src/peach/follow_covers.py
+++ b/src/peach/follow_covers.py
@@ -170,7 +170,8 @@ class FollowCoverService:
try:
with self._slots:
result = subprocess.run(
- command, capture_output=True, timeout=self.timeout, check=False)
+ command, capture_output=True, timeout=self.timeout, check=False,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
if (result.returncode != 0 or not temporary.is_file()
or temporary.stat().st_size == 0):
self._remember_miss(destination.name)
diff --git a/src/peach/frame_capture.py b/src/peach/frame_capture.py
index 419e4f176..77078b1d2 100644
--- a/src/peach/frame_capture.py
+++ b/src/peach/frame_capture.py
@@ -7,6 +7,7 @@
"""
from __future__ import annotations
+import os
import re
import subprocess
from pathlib import Path
@@ -40,7 +41,8 @@ def capture_frame(ffmpeg: str, path: str, timestamp: float, destination: Path, *
"-vf", f"scale={int(width)}:-1", "-q:v", "4", str(destination),
]
try:
- completed = subprocess.run(command, capture_output=True, timeout=timeout)
+ completed = subprocess.run(command, capture_output=True, timeout=timeout,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
except subprocess.TimeoutExpired:
return False, "ffmpeg timeout"
ok = destination.is_file() and destination.stat().st_size > 1024
@@ -70,5 +72,6 @@ def tile_frames(ffmpeg: str, pattern: str, columns: int, rows: int, destination:
[ffmpeg, "-y", "-v", "error", "-i", pattern,
"-filter_complex", f"tile={int(columns)}x{int(rows)}", "-q:v", "4", str(destination)],
capture_output=True, timeout=timeout,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0,
)
return destination.is_file() and destination.stat().st_size > 4096
diff --git a/src/peach/media_probe.py b/src/peach/media_probe.py
index 16665204f..dac4ddb80 100644
--- a/src/peach/media_probe.py
+++ b/src/peach/media_probe.py
@@ -13,6 +13,7 @@
from __future__ import annotations
import json
+import os
import sqlite3
import subprocess
from collections.abc import Callable, Sequence
@@ -60,6 +61,7 @@ def probe_file(ffprobe: str, path: str, timeout: float = TIMEOUT_SECONDS) -> tup
],
capture_output=True,
timeout=timeout,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0,
)
payload = json.loads(result.stdout or b"{}")
duration = float((payload.get("format") or {}).get("duration") or 0)
diff --git a/src/peach/mp4recover.py b/src/peach/mp4recover.py
index 38081e99c..65f2f8d1d 100644
--- a/src/peach/mp4recover.py
+++ b/src/peach/mp4recover.py
@@ -82,7 +82,8 @@ def pick_references(broken: str, candidates: list[str], limit: int = REFERENCE_L
def _run(command: list[str], timeout: float) -> subprocess.CompletedProcess:
- return subprocess.run(command, capture_output=True, stdin=subprocess.DEVNULL, timeout=timeout)
+ return subprocess.run(command, capture_output=True, stdin=subprocess.DEVNULL, timeout=timeout,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
def _stream_durations(ffprobe: Path, path: Path) -> dict[str, float]:
diff --git a/src/peach/mp4repair.py b/src/peach/mp4repair.py
index 7b15715f8..ca1dc4534 100644
--- a/src/peach/mp4repair.py
+++ b/src/peach/mp4repair.py
@@ -12,6 +12,7 @@
from __future__ import annotations
import logging
+import os
import struct
import subprocess
import threading
@@ -151,7 +152,8 @@ def _display_order(ffprobe: Path, source: Path, decode_times: list[int]) -> list
"-show_entries", "frame=pts", "-of", "csv=p=0", str(source),
)
try:
- completed = subprocess.run(command, capture_output=True, timeout=PROBE_TIMEOUT_SECONDS)
+ completed = subprocess.run(command, capture_output=True, timeout=PROBE_TIMEOUT_SECONDS,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
except (OSError, subprocess.TimeoutExpired) as exc:
raise RepairUnavailable(f"ffprobe 没跑完:{exc}") from exc
if completed.returncode:
diff --git a/src/peach/previews.py b/src/peach/previews.py
index 6d4f5c30e..68660f32d 100644
--- a/src/peach/previews.py
+++ b/src/peach/previews.py
@@ -184,6 +184,7 @@ class PreviewService:
[str(ffmpeg), "-v", "error", "-i", str(temporary), "-vf", "scale=1:1",
"-f", "rawvideo", "-pix_fmt", "gray", "-"],
capture_output=True, timeout=20, check=False,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0,
).stdout
except (OSError, subprocess.TimeoutExpired):
raw = b""
@@ -342,7 +343,8 @@ class PreviewService:
@staticmethod
def _run(command: list[str]) -> None:
try:
- result = subprocess.run(command, capture_output=True, timeout=30, check=False)
+ result = subprocess.run(command, capture_output=True, timeout=30, check=False,
+ creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
except (OSError, subprocess.TimeoutExpired) as exc:
Path(command[-1]).unlink(missing_ok=True)
raise PreviewUnavailable("ffmpeg generation failed") from exc
diff --git a/tests/test_dependency_policy.py b/tests/test_dependency_policy.py
index aa7864370..101c5dea1 100644
--- a/tests/test_dependency_policy.py
+++ b/tests/test_dependency_policy.py
@@ -204,9 +204,10 @@ class DependencyPolicyTests(unittest.TestCase):
"""
key, recipe = adopt.recipe_for(["package-lock.json"])
self.assertEqual(key, "web")
- for path in ("package.json", "web/index.html", "web/vendor/lucide/1.40.0/ORIGIN.md"):
+ for path in ("package.json", "web/index.html", "web/vendor/lucide/1.40.0/ORIGIN.md",
+ "web/dist/peach-app.js", "frontend/src/player/videojs.ts", "docs/REUSE.md"):
self.assertTrue(adopt.owned_by(recipe, path), path)
- for path in ("web/index.html.bak", "web/dist/peach-ui.js", "src/peach/api.py"):
+ for path in ("web/index.html.bak", "frontend/src/player/types.ts", "src/peach/api.py"):
self.assertFalse(adopt.owned_by(recipe, path), path)
self.assertEqual(adopt.recipe_for(["frontend/package.json"])[0], "frontend")
self.assertEqual(adopt.recipe_for(["pyproject.toml", "uv.lock"])[0], "uv")
@@ -220,6 +221,19 @@ class DependencyPolicyTests(unittest.TestCase):
with self.assertRaisesRegex(RuntimeError, "认得的清单"):
adopt.recipe_for(["README.md"])
+ def test_takeover_lists_each_new_vendor_file_and_excludes_ignored_builds(self):
+ with tempfile.TemporaryDirectory() as holder:
+ repo = seed_repository(Path(holder).resolve() / "repo",
+ {"package.json": b"{}", ".gitignore": b"build/\n"}, "base")
+ (repo / "package.json").write_bytes(b'{"private":true}')
+ vendor = repo / "web/vendor/videojs/1.2.3/video.min.js"
+ vendor.parent.mkdir(parents=True)
+ vendor.write_bytes(b"player")
+ (repo / "build").mkdir()
+ (repo / "build/log.txt").write_text("ignored", encoding="utf-8")
+ self.assertEqual(adopt.working_changes(root=repo),
+ ["package.json", "web/vendor/videojs/1.2.3/video.min.js"])
+
def test_the_takeover_keeps_what_master_added_to_the_manifest_after_the_fork(self):
"""接管套的是分支自己的改动,分叉后 master 往清单里加的依赖原样留着。
diff --git a/tests/test_frame_capture.py b/tests/test_frame_capture.py
index 853f33c95..c71406c66 100644
--- a/tests/test_frame_capture.py
+++ b/tests/test_frame_capture.py
@@ -1,6 +1,7 @@
"""按时间点抽单帧、把若干帧拼成一张接触印相。九宫格与时间轴预览共用这一份。"""
from __future__ import annotations
+import os
import shutil
import subprocess
import tempfile
@@ -24,7 +25,9 @@ class CaptureFrameTests(unittest.TestCase):
self.commands: list[list[str]] = []
def _run(self, produce: bool = True, stderr: bytes = b""):
- def fake(command, **_kwargs):
+ def fake(command, **options):
+ self.assertEqual(options["creationflags"],
+ subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
self.commands.append(list(command))
if produce:
Path(command[-1]).write_bytes(b"x" * 2048)
@@ -88,7 +91,9 @@ class TileFramesTests(unittest.TestCase):
def test_the_grid_size_reaches_the_filter(self):
seen: list[list[str]] = []
- def fake(command, **_kwargs):
+ def fake(command, **options):
+ self.assertEqual(options["creationflags"],
+ subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
seen.append(list(command))
Path(command[-1]).write_bytes(b"x" * 8192)
return _Completed()
diff --git a/tests/test_media_probe.py b/tests/test_media_probe.py
index fed472855..5a06a6af0 100644
--- a/tests/test_media_probe.py
+++ b/tests/test_media_probe.py
@@ -98,6 +98,21 @@ class ProbeUnmeasuredTests(unittest.TestCase):
self.assertIsNone(self.row(other)[0])
+class ProbeProcessTests(unittest.TestCase):
+ def test_probe_reads_metadata_with_a_hidden_windows_process(self):
+ payload = b'{"format":{"duration":"12.5"},"streams":[{"width":320,"height":240,' \
+ b'"codec_name":"h264","avg_frame_rate":"25/1"}]}'
+ with mock.patch.object(media_probe.subprocess, "run",
+ return_value=SimpleNamespace(stdout=payload)) as run:
+ result = media_probe.probe_file("ffprobe", "sample.mp4", timeout=3)
+ self.assertEqual(result, (12.5, 320, 240, "h264", 25.0, None))
+ options = run.call_args.kwargs
+ self.assertEqual(options["creationflags"],
+ subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)
+ self.assertTrue(options["capture_output"])
+ self.assertEqual(options["timeout"], 3)
+
+
class PushDiscoveryProbeTests(unittest.TestCase):
def test_a_pushed_video_lands_with_its_duration(self):
with tempfile.TemporaryDirectory() as tmp: