feat(pipeline): 批量整理、归档服务化与 watch 全自动

- main/pipeline: -p 改为 append,多目录走 run_batch(共享一次确认与一次执行);
  单目录整理后自动接归档,多目录只整理
- services/archive: 归档从脚本抽成服务,三道闸(有视频/无下载残留/有唯一 TMDB 建议),
  Jellyfin 刷新走 172.17.0.1 回退
- watcher: 改为监听 .qkdownloading 的消失/移走事件并归并到下载根下一级目录,
  _running/_pending 互斥,下载判定用 is_download_complete()
- task: notes + add_note(),预览按五阶段固定顺序打印;execute() 返回统计
- config: AUTO_ARCHIVE / FOLLOW_SPECIALS / DOWNLOADING_EXTS / WATCH_SETTLE_SECONDS
This commit is contained in:
ali
2026-11-21 21:09:40 +08:00
parent 201e9e8745
commit 753063401f
9 changed files with 1243 additions and 111 deletions
+33 -2
View File
@@ -10,6 +10,7 @@
"""
import json
import os
import time
from dataclasses import dataclass, field
from pathlib import Path
@@ -357,8 +358,8 @@ class PreflightService:
return report
@classmethod
def scan(cls, root: Path) -> list:
"""check 模式:只体检不动文件。"""
def _scan_root(cls, root: Path) -> list:
"""单个根目录体检(只读),返回 [(path, PreflightResult)]。"""
results = []
files = [
p for p in root.rglob("*")
@@ -372,12 +373,42 @@ class PreflightService:
detail = f"{r.info.get('codec')} {r.info.get('height')}p {r.info.get('mbps')}Mbps"
log.info(f"{mark} {r.verdict:<7} {p.name} [{detail}]"
+ (f" | {', '.join(r.reasons)}" if r.reasons else ""))
return results
@staticmethod
def _log_counts(results: list) -> None:
counts = {}
for _, r in results:
counts[r.verdict] = counts.get(r.verdict, 0) + 1
log.info(f"📊 共 {len(results)} 个文件: " +
", ".join(f"{k}={v}" for k, v in sorted(counts.items())))
@staticmethod
def _common_root(roots: list) -> Path:
if len(roots) == 1:
return Path(roots[0])
try:
return Path(os.path.commonpath([str(Path(r)) for r in roots]))
except ValueError: # 跨盘符(Windows)无法求公共前缀
return Path(roots[0])
@classmethod
def scan(cls, root: Path) -> list:
"""check 模式:只体检不动文件。"""
results = cls._scan_root(root)
cls._log_counts(results)
cls.write_report(root, results)
return results
@classmethod
def scan_many(cls, roots: list) -> list:
"""多目录体检:合并成一份报告(否则一次多选会吃掉全部 report_keep)。"""
results = []
for root in roots:
if len(roots) > 1:
log.info(f"— 体检 {Path(root)}")
results.extend(cls._scan_root(Path(root)))
cls._log_counts(results)
cls.write_report(cls._common_root(roots), results)
return results