Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(cli): 资料处理扫描阶段显示已发现的文件数

longmeidaob41bbb967805
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac2b7789f..ddd8d93ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@ Removed / Fixed / Security。
### 修复
- **馆藏**:扫描 SMB 共享时整趟共用一条连接,不再每进入一个目录都重新连接和认证,大型媒体库的扫描明显加快;连接断开时自动重连一次后继续。
+- **馆藏**:命令行或托盘运行资料处理时,扫描阶段的进度显示已发现的文件数,不再一直显示「扫描文件:0/0」。
## [0.53.0] - 2026-11-02
diff --git a/src/peach/cli.py b/src/peach/cli.py
index f156cb8e5..bbc0873c1 100644
--- a/src/peach/cli.py
+++ b/src/peach/cli.py
@@ -497,6 +497,27 @@ def _scan(args: argparse.Namespace) -> int:
return 0
+def _processing_line(state: dict) -> str:
+ """一行进度,口径同页面的 `processingLine`:总量已知写完成数,扫描目录时写已发现的文件数。"""
+ if state.get('total'):
+ return f"{state['stage']}:{state.get('checked', 0)}/{state['total']}"
+ if state.get('current_action') == 'scanning_files' or state.get('stage') == '扫描文件':
+ return f"{state['stage']}:已发现 {state.get('scanned', 0):,} 个文件"
+ return str(state['stage'])
+
+
+def _processing_printer():
+ """资料处理的进度回调:流量、问题等回报也会走这里,和上一行相同就不再打印。"""
+ last = None
+ def report(state):
+ nonlocal last
+ line = _processing_line(state)
+ if line != last:
+ print(line, flush=True)
+ last = line
+ return report
+
+
def _process_library(args: argparse.Namespace) -> int:
"""命令行跑资料处理,和网页那一轮一样记进任务中心、结算时派发声明的后继。
@@ -512,8 +533,7 @@ def _process_library(args: argparse.Namespace) -> int:
try:
result = process_library(config, args.db, config.directory('generated'),
config.directory('generated') / 'covers', location=args.location,
- database=LedgerDatabase(args.db),
- report=lambda state: print(f"{state['stage']}:{state['checked']}/{state['total']}", flush=True))
+ database=LedgerDatabase(args.db), report=_processing_printer())
except JobCancelled:
handle.finish('cancelled', error='用户停止任务')
print('任务已停止,已保存结果保留。')
diff --git a/tests/test_cli.py b/tests/test_cli.py
index bac8aaf2f..f7cec3b4e 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -600,6 +600,23 @@ class ProcessCommandTests(unittest.TestCase):
self.assertEqual(rows,[('cancelled',None)])
self.assertIn('已保存结果保留',output.getvalue())
+ def test_progress_lines_show_files_found_while_scanning_and_skip_repeats(self):
+ def process(*_args, report, **_kwargs):
+ scanning = {"stage": "扫描文件", "checked": 0, "total": 0, "current_action": "scanning_files"}
+ report({**scanning, "scanned": 0})
+ report({**scanning, "scanned": 8096})
+ report({**scanning, "scanned": 8096})
+ report({"stage": "读取时长与分辨率", "checked": 12, "total": 40, "scanned": 8096})
+ report({"stage": "整理结果", "checked": 0, "total": 0, "scanned": 8096})
+ return {"status": "complete", "followups": []}
+ with mock.patch("peach.library_processing.process_library", side_effect=process), \
+ redirect_stdout(io.StringIO()) as output:
+ code = cli.main(["process", "--db", str(self.db)])
+ self.assertEqual(code, 0)
+ self.assertEqual(output.getvalue().splitlines(), [
+ "扫描文件:已发现 0 个文件", "扫描文件:已发现 8,096 个文件",
+ "读取时长与分辨率:12/40", "整理结果"])
+
class ReplicationAssemblyTests(unittest.TestCase):
"""ADR-0023 第 3 阶段:整条复制链路按 `replication.enabled` 装配或完全不装配。"""