Peach: Local-first video metadata scraper and media manager.
feat(library): 入库时读出视频时长与分辨率
longmeidaofdfde5b73d3d
diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 7cfa0c626..279683336 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -292,7 +292,7 @@ Python、npm 与 GitHub Actions 的版本由 `.github/dependabot.yml` 每周检|---|---|---|| `rm-web.py` / `rm-web.html` | `src/peach/api.py`、`src/peach/web_contract.py`、`web/index.html` | 不得恢复旧 HTTP server || `rm-javlookup.py` | `scripts/scrape_codes.py` | 扩展来源适配器,不再分叉刮削器 |-| `rm-probe.py` | `scripts/probe.py` | 可复用策略移入 `src/peach`,保留续跑语义 |+| `rm-probe.py` | `src/peach/media_probe.py`(入库时探本机与 115)、`scripts/probe.py`(历史、重探与计流量来源) | 探测与失败记 -1 只有 `media_probe` 一份,保留续跑语义 || `rm-sheets.py` | `scripts/sheets.py` | 共用 FFmpeg/任务原语,不再新建抽帧管线 || `rm-ledger.py`、`scripts/ledger.py` | `peach init`/`peach scan`(`src/peach/cli.py`、`src/peach/scan.py`)+ repository/migrations | 摄取与建库只有 `peach` 一个入口,不放回旧 CLI;Stash 回灌随 ADR-0021 退役 || `rm-status.py`、`scripts/status.py` | `peach status`(`src/peach/cli.py`) | 状态命令只读,并且只有一个入口:打包入口转发全部子命令,不再单独发一个脚本 |diff --git a/scripts/probe.py b/scripts/probe.pyindex f1151e9ef..86b4cda02 100644--- a/scripts/probe.py+++ b/scripts/probe.py@@ -1,12 +1,14 @@#!/usr/bin/env python3-"""全库 ffprobe:可续跑、单写者、显式计费授权。"""+"""全库 ffprobe:可续跑、单写者、显式计费授权。++新文件入库时已经探过一次(`peach.media_probe`),这里补的是历史空缺、失败重探和点名+重探,以及入库时不碰的计费来源。+"""from __future__ import annotationsimport argparse-import jsonimport queueimport sqlite3-import subprocessimport threadingimport timeimport sys@@ -31,6 +33,7 @@ from peach.jobs import ()from peach.platform import system_volumefrom peach.media import resolve_case_insensitive+from peach.media_probe import UPDATE, context_fields, probe_filedef build_parser() -> argparse.ArgumentParser:@@ -67,21 +70,6 @@ def build_parser() -> argparse.ArgumentParser:return parser-def context_fields(width: int, height: int, duration: float) -> tuple[str | None, str | None, str | None]:- orientation = quality = length = None- if width and height:- orientation = "竖屏" if height > width else "横屏"- longest = max(width, height)- quality = (- "4K" if longest >= 3000 else "2K" if longest >= 1900- else "1080P" if longest >= 1300 else "720P" if longest >= 900- else "低画质"- )- if duration and duration > 0:- length = "速食" if duration < 300 else "短" if duration < 900 else "中" if duration < 2400 else "长"- return length, orientation, quality--def duration_selection(redo: str) -> str:"""未探测和"探测过但没拿到时长"是两种状态;后者必须显式要求才重跑。@@ -96,39 +84,6 @@ def duration_selection(redo: str) -> str:}[redo]-def probe_file(ffprobe: str, path: str, timeout: float = 20.0) -> tuple:- result = subprocess.run(- [- ffprobe, "-v", "error", "-rw_timeout", "8000000",- "-select_streams", "v:0", "-show_entries",- "format=duration:stream=width,height,codec_name,avg_frame_rate",- "-of", "json", path,- ],- capture_output=True,- timeout=timeout,- )- payload = json.loads(result.stdout or b"{}")- duration = float((payload.get("format") or {}).get("duration") or 0)- if duration <= 0:- # 拿不到时长就是失败,不能写 0 —— 0 会被后续步骤当成"已探测"而永久跳过。- duration = -1.0- stream = (payload.get("streams") or [{}])[0]- fps = 0.0- try:- numerator, denominator = (stream.get("avg_frame_rate") or "0/1").split("/")- fps = float(numerator) / float(denominator) if float(denominator) else 0.0- except (TypeError, ValueError, ZeroDivisionError):- pass- return (- duration,- int(stream.get("width") or 0),- int(stream.get("height") or 0),- stream.get("codec_name"),- fps,- None,- )--def run(args: argparse.Namespace) -> int:if args.workers < 1 or args.interval < 0 or args.limit < 0:raise SystemExit("workers 必须大于 0;interval/limit 不能为负数")@@ -237,10 +192,7 @@ def run(args: argparse.Namespace) -> int:connection = sqlite3.connect(args.db, timeout=120)connection.execute("PRAGMA journal_mode=WAL")connection.execute("PRAGMA busy_timeout=120000")- update = (- "UPDATE asset SET duration=?,width=?,height=?,vcodec=?,fps=?,has_audio=?,"- "ctx_length=?,ctx_orient=?,ctx_quality=? WHERE id=?"- )+ update = UPDATEbuffer = []while any(thread.is_alive() for thread in threads) or not results.empty():try:diff --git a/scripts/test_runner.py b/scripts/test_runner.pyindex 61f6223e9..cf73d8d8e 100644--- a/scripts/test_runner.py+++ b/scripts/test_runner.py@@ -44,7 +44,7 @@ SCOPES: dict[str, tuple[str, ...]] = {"test_link_marks.py", "test_site_icons.py", "test_site_logos.py","test_avatar_face.py","test_brand_marks.py", "test_studio_icon_variants.py",- "test_push_discovery.py",+ "test_push_discovery.py", "test_media_probe.py","test_review_csv.py", "test_related.py","test_search_suggest.py", "test_subtitles.py","test_task_runs.py", "test_followups.py", "test_task_center_integration.py",@@ -91,7 +91,7 @@ SCOPES: dict[str, tuple[str, ...]] = {"test_resource_identification.py","test_agency_entity.py"),"tooling": ("test_scripts.py", "test_trash_junk.py", "test_auth.py", "test_access.py", "test_cli.py", "test_script_policy.py",- "test_scan.py", "test_push_discovery.py", "test_subtitles.py", "test_onboarding.py", "test_configuration_sources.py", "test_folder_picker.py", "test_ledger_backups.py", "test_clear_camera_filename_codes.py",+ "test_scan.py", "test_push_discovery.py", "test_media_probe.py", "test_subtitles.py", "test_onboarding.py", "test_configuration_sources.py", "test_folder_picker.py", "test_ledger_backups.py", "test_clear_camera_filename_codes.py","test_agent_worktree.py", "test_test_evidence.py", "test_dependency_policy.py","test_version_bump.py", "test_changelog.py", "test_release_due.py","test_restart_windows_tray.py", "test_deploy_windows_tray.py",diff --git a/src/peach/api.py b/src/peach/api.pyindex b687163e8..d489987c8 100644--- a/src/peach/api.py+++ b/src/peach/api.py@@ -226,6 +226,7 @@ def create_app(declared_roots=LOCATION_ROOT_DECLARATIONS,mounts=location_mounts(),available=_writer(sync),+ ffprobe=resolver.ffprobe,)contract.follow_scheduler = follow_scheduler# 订阅源拉取(ADR-0042)用同一个调度实现,只换 job id、状态文件与默认间隔。diff --git a/src/peach/library_processing.py b/src/peach/library_processing.pyindex 475cc5f76..f73f353e8 100644--- a/src/peach/library_processing.py+++ b/src/peach/library_processing.py@@ -28,7 +28,9 @@ from .metadata_policy import SOURCE_SPECSfrom .platform import root_online, translate_ledger_pathfrom .review_csv import read_rows, write_rowsfrom .scan import scan_location+from .ffmpeg import FFmpegResolverfrom .jobs import DiskGuard+from .media_probe import probe_unmeasuredFIELDS = ('item_key', 'code', 'query', 'asset_id', 'asset_path', 'field', 'field_label', 'current_value','candidates_json', 'source_count', 'source_profile', 'policy_version', 'status',@@ -1276,6 +1278,12 @@ def _avatar_followups(database, config, watermark, covered=()):for item in found]+def _ffprobe_path(config):+ """数据目录里那份 ffprobe,没有就退到 PATH;都没有回 `None`,扫描照常、只是不探。"""+ choice = FFmpegResolver(config.directory('tools') / 'ffmpeg').ffprobe()+ return str(choice.path) if choice else None++def process_library(config, db_path, candidate_root, cover_root, *, location='configured',report=lambda state: None, provider_factory=None, job_id=None,retry_ids=None, active=lambda: True, stage=ALL_STAGES,@@ -1305,7 +1313,7 @@ def process_library(config, db_path, candidate_root, cover_root, *, location='cowith FileLock(str(path) + '.lock', timeout=0):state = dict(job_id=job_id or uuid.uuid4().hex, status='running',stage='读取本地资料' if retrying else '扫描文件',- checked=0, total=0, scanned=0, identified=0, candidates=0, covers=0,+ checked=0, total=0, scanned=0, probed=0, identified=0, candidates=0, covers=0,issue_count=0, paused_count=0, issue_preview=[], issues_truncated=False,notes={}, retryable_asset_ids=[],last_progress_at=time.time(), progress_seq=0,@@ -1371,6 +1379,7 @@ def process_library(config, db_path, candidate_root, cover_root, *, location='coguard.check(force=True)locations = config.locations if location == 'configured' else {location: config.locations[location]}mounts = {key: tuple(str(value) for value in values) for key, values in config.mounts.items()}+ ffprobe = _ffprobe_path(config)online_roots = []for source, roots in locations.items():for root in roots:@@ -1383,9 +1392,13 @@ def process_library(config, db_path, candidate_root, cover_root, *, location='coresult = scan_location(db_path, source, root, declared_roots=config.locations,mounts=mounts, report=lambda line: update(stage='扫描文件'))state['scanned'] += result.files+ state['probed'] += probe_unmeasured(+ db_path, ffprobe, source, root,+ report=lambda done, total: update(stage='读取时长与分辨率', checked=done, total=total))if stage == SCAN_STAGE:+ # `checked`/`total` 在探时长时借给进度条用过;只扫描这一段没有采集,读数归零。update(status='failed' if state['issue_count'] else 'complete',- stage='处理结束', completed_at=time.time(),+ stage='处理结束', completed_at=time.time(), checked=0, total=0,error=issue_summary(state['issue_count'], state['paused_count']))return state# 演员和标签是另外两张表,`asset` 上没有这两列。不带上它们,采集就把每部片都diff --git a/src/peach/media_probe.py b/src/peach/media_probe.pynew file mode 100644index 000000000..16665204f--- /dev/null+++ b/src/peach/media_probe.py@@ -0,0 +1,137 @@+"""视频的时长、分辨率与编码:ffprobe 读一次文件头,写回 `asset`。++入库时顺手探一次,新文件一登记就带着时长和分辨率:全量扫描扫完一个根就探这个根下+还没探过的视频,推送发现登记一个视频就探这一个。`scripts/probe.py` 只剩补历史空缺、+重探失败和按 id 点名三件事。++计费来源(PikPak)入库时一律不探。入库是自动发生的,没有人在场确认流量预算;要探就+显式跑那个脚本并加 `--allow-metered`。++拿不到时长写 -1,不写 0,也不留 NULL。0 会同时躲过 `duration IS NULL` 的待办和抽帧的+`duration>2` 门槛,永久卡住;留 NULL 的话,每一轮入库都会把同一个坏文件再探一遍。+"""+from __future__ import annotations++import json+import sqlite3+import subprocess+from collections.abc import Callable, Sequence+from concurrent.futures import ThreadPoolExecutor+from contextlib import closing+from pathlib import PureWindowsPath++from .jobs import ACTIVE_ASSET_SQL, SourceAccessPolicy+from .media import resolve_case_insensitive++#: 一次探测最多等多久。ffprobe 只读文件头,网盘上实测一两秒。+TIMEOUT_SECONDS = 20.0+#: 入库时同时探几个。网盘挂载上这是延迟受限的元数据读取,开多了只会把 CloudDrive 压住。+WORKERS = 4++UPDATE = (+ "UPDATE asset SET duration=?,width=?,height=?,vcodec=?,fps=?,has_audio=?,"+ "ctx_length=?,ctx_orient=?,ctx_quality=? WHERE id=?"+)+_UNMEASURED = f"medium='video' AND duration IS NULL AND location=? AND {ACTIVE_ASSET_SQL}"+++def context_fields(width: int, height: int, duration: float) -> tuple[str | None, str | None, str | None]:+ orientation = quality = length = None+ if width and height:+ orientation = "竖屏" if height > width else "横屏"+ longest = max(width, height)+ quality = (+ "4K" if longest >= 3000 else "2K" if longest >= 1900+ else "1080P" if longest >= 1300 else "720P" if longest >= 900+ else "低画质"+ )+ if duration and duration > 0:+ length = "速食" if duration < 300 else "短" if duration < 900 else "中" if duration < 2400 else "长"+ return length, orientation, quality+++def probe_file(ffprobe: str, path: str, timeout: float = TIMEOUT_SECONDS) -> tuple:+ result = subprocess.run(+ [+ ffprobe, "-v", "error", "-rw_timeout", "8000000",+ "-select_streams", "v:0", "-show_entries",+ "format=duration:stream=width,height,codec_name,avg_frame_rate",+ "-of", "json", path,+ ],+ capture_output=True,+ timeout=timeout,+ )+ payload = json.loads(result.stdout or b"{}")+ duration = float((payload.get("format") or {}).get("duration") or 0)+ if duration <= 0:+ duration = -1.0+ stream = (payload.get("streams") or [{}])[0]+ fps = 0.0+ try:+ numerator, denominator = (stream.get("avg_frame_rate") or "0/1").split("/")+ fps = float(numerator) / float(denominator) if float(denominator) else 0.0+ except (TypeError, ValueError, ZeroDivisionError):+ pass+ return (+ duration,+ int(stream.get("width") or 0),+ int(stream.get("height") or 0),+ stream.get("codec_name"),+ fps,+ None,+ )+++def measure(ffprobe: str, asset_id: int, path: str, timeout: float = TIMEOUT_SECONDS) -> tuple:+ """这一行的 `UPDATE` 参数。探不出来的一律是 -1 那一行,不抛。"""+ try:+ duration, width, height, codec, fps, audio = probe_file(+ ffprobe, resolve_case_insensitive(path), timeout)+ except Exception: # 超时、文件读不到、输出不是 JSON:对这一行都是「没拿到」+ return (-1, 0, 0, None, 0, 0, None, None, None, asset_id)+ return (duration, width, height, codec, fps, audio,+ *context_fields(width, height, duration), asset_id)+++def probe_unmeasured(+ db_path, ffprobe: str | None, location: str, root: str, *,+ report: Callable[[int, int], None] = lambda done, total: None,+) -> int:+ """`root`(账本口径)下还没探过的视频逐个探一遍,返回探了几个。"""+ if not ffprobe or location in SourceAccessPolicy().metered_locations:+ return 0+ prefix = str(PureWindowsPath(root)).rstrip("\\") + "\\"+ with closing(sqlite3.connect(db_path, timeout=30)) as connection:+ rows = connection.execute(+ f"SELECT id,path FROM asset WHERE {_UNMEASURED} AND substr(path,1,?)=? ORDER BY id",+ (location, len(prefix), prefix)).fetchall()+ return _record(db_path, ffprobe, rows, report)+++def probe_path(db_path, ffprobe: str | None, location: str, path: str) -> int:+ """推送发现刚登记的这一个文件;不是视频、已经探过或来源计费都回 0。"""+ if not ffprobe or location in SourceAccessPolicy().metered_locations:+ return 0+ with closing(sqlite3.connect(db_path, timeout=30)) as connection:+ rows = connection.execute(+ f"SELECT id,path FROM asset WHERE {_UNMEASURED} AND path=?",+ (location, str(PureWindowsPath(path)))).fetchall()+ return _record(db_path, ffprobe, rows, lambda done, total: None)+++def _record(db_path, ffprobe: str, rows: Sequence, report: Callable[[int, int], None]) -> int:+ """探完一条写一条。`report` 抛出来(任务被停)时,还没开始的那些不再探。"""+ if not rows:+ return 0+ done = 0+ executor = ThreadPoolExecutor(max_workers=min(WORKERS, len(rows)), thread_name_prefix="PeachProbe")+ try:+ with closing(sqlite3.connect(db_path, timeout=120)) as connection:+ for measured in executor.map(lambda row: measure(ffprobe, row[0], row[1]), rows):+ connection.execute(UPDATE, measured)+ connection.commit()+ done += 1+ report(done, len(rows))+ finally:+ executor.shutdown(wait=False, cancel_futures=True)+ return donediff --git a/src/peach/push_discovery.py b/src/peach/push_discovery.pyindex 77b5f4343..9d19058dc 100644--- a/src/peach/push_discovery.py+++ b/src/peach/push_discovery.py@@ -34,6 +34,7 @@ import jsonimport loggingimport osimport secrets+import sqlite3import threadingimport timefrom dataclasses import dataclass, field@@ -596,8 +597,11 @@ class PushDiscoveryService:self, *, state_root: Path, secrets_root: Path, db_path: Path,declared_roots, mounts, available: bool = True,debounce: float = DEBOUNCE_SECONDS, settle: float = SETTLE_SECONDS,+ ffprobe: Callable[[], object] | None = None,):self.settings = PushDiscoverySettings(state_root)+ #: 取 ffprobe 的回调,登记完视频当场探时长用;每次现取,装上 FFmpeg 不必重启。+ self.ffprobe = ffprobeself.secret = WebhookSecret(secrets_root)self.db_path = Path(db_path)self.declared_roots = {key: tuple(value) for key, value in declared_roots.items()}@@ -627,8 +631,20 @@ class PushDiscoveryService:def _ingest(self, location: str, path: str) -> bool:from .scan import ingest_path- return ingest_path(self.db_path, location, path,- declared_roots=self.declared_roots, mounts=self.mounts).found+ found = ingest_path(self.db_path, location, path,+ declared_roots=self.declared_roots, mounts=self.mounts).found+ if found:+ self._measure(location, path)+ return found++ def _measure(self, location: str, path: str) -> None:+ """登记完顺手探时长与分辨率。探不成不影响这一条已经入库,全量扫描还会再补。"""+ from .media_probe import probe_path+ choice = self.ffprobe() if self.ffprobe else None+ try:+ probe_path(self.db_path, str(choice.path) if choice else None, location, path)+ except sqlite3.Error:+ LOGGER.exception("推送发现探测时长失败:%s", path)def submit(self, location: str, path: str) -> bool:if ignored(PureWindowsPath(path).name):diff --git a/tests/test_media_probe.py b/tests/test_media_probe.pynew file mode 100644index 000000000..fed472855--- /dev/null+++ b/tests/test_media_probe.py@@ -0,0 +1,130 @@+"""入库时顺手探时长:探哪些行、哪些来源不碰、探不出来记成什么。"""+from __future__ import annotations++import os+import sqlite3+import subprocess+import tempfile+import unittest+from pathlib import Path, PureWindowsPath+from types import SimpleNamespace+from unittest import mock++from peach import media_probe+from peach import push_discovery as push+from support.ledger import fresh_ledger++ROOT = r"R:\media"+++class ProbeUnmeasuredTests(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.addCleanup(self.tmp.cleanup)+ self.db = fresh_ledger(Path(self.tmp.name))+ self.probed: list[str] = []++ def add(self, path, *, location="local", medium="video", duration=None, disposal=None) -> int:+ connection = sqlite3.connect(self.db)+ try:+ cursor = connection.execute(+ "INSERT INTO asset(location,path,name,medium,duration,disposal) VALUES(?,?,?,?,?,?)",+ (location, path, PureWindowsPath(path).name, medium, duration, disposal))+ connection.commit()+ return cursor.lastrowid+ finally:+ connection.close()++ def row(self, asset_id):+ connection = sqlite3.connect(self.db)+ try:+ return connection.execute(+ "SELECT duration,width,height,ctx_quality FROM asset WHERE id=?", (asset_id,)).fetchone()+ finally:+ connection.close()++ def fake_probe(self, _ffprobe, path, _timeout):+ self.probed.append(PureWindowsPath(path).name)+ return 1800.0, 1920, 1080, "h264", 30.0, None++ def probe(self, location="local", root=ROOT, ffprobe="ffprobe"):+ with mock.patch.object(media_probe, "probe_file", self.fake_probe), \+ mock.patch.object(media_probe, "resolve_case_insensitive", str):+ return media_probe.probe_unmeasured(self.db, ffprobe, location, root)++ def test_only_unmeasured_active_videos_under_the_scanned_root_are_probed(self):+ fresh = self.add(ROOT + r"\新片\a.mp4")+ measured = self.add(ROOT + r"\b.mp4", duration=10.0)+ self.add(ROOT + r"\c.jpg", medium="image")+ self.add(ROOT + r"\d.mp4", disposal="trash")+ self.add(r"R:\mediax\e.mp4")+ self.add(r"R:\other\f.mp4")++ self.assertEqual(self.probe(), 1)+ self.assertEqual(self.probed, ["a.mp4"], "同前缀的兄弟目录 R:\\mediax 不在这个根下")+ self.assertEqual(self.row(fresh), (1800.0, 1920, 1080, "2K"))+ self.assertEqual(self.row(measured)[0], 10.0)++ def test_a_metered_source_is_left_for_the_explicit_batch(self):+ pending = self.add(r"A:\创作者\a.mp4", location="pikpak")+ self.assertEqual(self.probe("pikpak", "A:\\"), 0)+ self.assertEqual(self.probed, [])+ self.assertIsNone(self.row(pending)[0])++ def test_without_ffprobe_the_scan_still_finishes_and_leaves_rows_pending(self):+ pending = self.add(ROOT + r"\a.mp4")+ self.assertEqual(self.probe(ffprobe=None), 0)+ self.assertIsNone(self.row(pending)[0])++ def test_an_unreadable_file_is_marked_failed_so_the_next_scan_skips_it(self):+ broken = self.add(ROOT + r"\坏.mp4")++ def timeout(*_args):+ raise subprocess.TimeoutExpired("ffprobe", 20)++ with mock.patch.object(media_probe, "probe_file", timeout), \+ mock.patch.object(media_probe, "resolve_case_insensitive", str):+ media_probe.probe_unmeasured(self.db, "ffprobe", "local", ROOT)+ self.assertEqual(self.row(broken), (-1, 0, 0, None))+ self.assertEqual(self.probe(), 0, "-1 已经不是待办")++ def test_a_pushed_file_is_probed_on_its_own(self):+ pushed = self.add(ROOT + r"\a.mp4")+ other = self.add(ROOT + r"\b.mp4")+ with mock.patch.object(media_probe, "probe_file", self.fake_probe), \+ mock.patch.object(media_probe, "resolve_case_insensitive", str):+ self.assertEqual(media_probe.probe_path(self.db, "ffprobe", "local", ROOT + r"\a.mp4"), 1)+ self.assertEqual(self.row(pushed)[0], 1800.0)+ self.assertIsNone(self.row(other)[0])+++class PushDiscoveryProbeTests(unittest.TestCase):+ def test_a_pushed_video_lands_with_its_duration(self):+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp).resolve()+ db = fresh_ledger(root)+ media = root / "media"+ media.mkdir()+ (media / "a.mp4").write_bytes(b"0" * 8)+ if os.name == "nt":+ declared, mounts = {"local": (str(media),)}, {}+ else:+ declared, mounts = {"local": (ROOT,)}, {"local": (str(media),)}+ service = push.PushDiscoveryService(+ state_root=root / "state", secrets_root=root / "secrets", db_path=db,+ declared_roots=declared, mounts=mounts,+ ffprobe=lambda: SimpleNamespace(path="ffprobe"))+ path = str(PureWindowsPath(declared["local"][0]).joinpath("a.mp4"))+ with mock.patch.object(media_probe, "probe_file",+ lambda *_args: (95.0, 1280, 720, "h264", 25.0, None)):+ self.assertTrue(service.queue.ingest("local", path))+ connection = sqlite3.connect(db)+ try:+ duration, height = connection.execute("SELECT duration,height FROM asset").fetchone()+ finally:+ connection.close()+ self.assertEqual((duration, height), (95.0, 720))+++if __name__ == "__main__":+ unittest.main()diff --git a/tests/test_scripts.py b/tests/test_scripts.pyindex 3af54f5ca..e24933744 100644--- a/tests/test_scripts.py+++ b/tests/test_scripts.py@@ -1781,7 +1781,7 @@ class OperationalScriptTests(unittest.TestCase):def test_probe_never_records_an_unknown_duration_as_zero(self):"""0 会同时躲过 probe 的 `duration IS NULL` 和抽帧的 `duration>2`,永久卡住。"""- module = self.probe+ from peach import media_probe as moduleclass _Empty:stdout = b'{"format":{},"streams":[{"width":0,"height":0}]}'