fix(srt): add disable_reasoning parameter for ASR correction and include title in archive filename
PR Test / lint (pull_request) Successful in 1s

- SimpleAIClient: Add disable_reasoning parameter to control AI thinking mode
- ASRCorrector: Use disable_reasoning=True to get direct correction results
- ArchiveProcessor: Extract title from frontmatter and include in filename

File naming format: {YYYYMMDD}_{content_id}_{title}_analysis.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 22:19:14 +08:00
parent 9e007432eb
commit 4d2645876b
4 changed files with 176 additions and 10 deletions
+66 -2
View File
@@ -7,6 +7,7 @@ to the archive directory organized by platform.
from __future__ import annotations
import logging
import re
import shutil
from datetime import datetime
from pathlib import Path
@@ -65,9 +66,14 @@ class ArchiveProcessor(BaseProcessor):
platform_dir = archive_base / input_data.platform
platform_dir.mkdir(parents=True, exist_ok=True)
# 文件命名: {YYYYMMDD}_{content_id}_analysis.md
# 从源文件中提取标题(用于文件命名)
title = self._extract_title_from_file(Path(input_data.analysis_file))
# 清理标题:移除特殊字符,限制长度
safe_title = self._sanitize_title(title) if title else input_data.content_id
# 文件命名: {YYYYMMDD}_{content_id}_{title}_analysis.md
timestamp = datetime.now().strftime("%Y%m%d")
archive_filename = f"{timestamp}_{input_data.content_id}_analysis.md"
archive_filename = f"{timestamp}_{input_data.content_id}_{safe_title}_analysis.md"
archive_path = platform_dir / archive_filename
# Step 3: 检查重复
@@ -147,6 +153,64 @@ class ArchiveProcessor(BaseProcessor):
matches = list(platform_dir.glob(pattern))
return matches[0] if matches else None
def _extract_title_from_file(self, file_path: Path) -> Optional[str]:
"""从 Markdown 文件的 frontmatter 中提取标题
Args:
file_path: Markdown 文件路径
Returns:
标题字符串,如果未找到返回 None
"""
try:
content = file_path.read_text(encoding='utf-8')
# 查找 frontmatter 中的 title 字段
# 格式:title: "标题内容" 或 title: 标题内容
title_match = re.search(r'^title:\s*(?:"([^"]*)"|(.+))$', content, re.MULTILINE)
if title_match:
# 优先使用引号内的内容,否则使用第二个捕获组
title = title_match.group(1) or title_match.group(2)
return title.strip() if title else None
return None
except Exception as e:
logger.warning(f"Failed to extract title from {file_path}: {e}")
return None
def _sanitize_title(self, title: str) -> str:
"""清理标题用于文件命名
移除特殊字符,限制长度,转换为安全的文件名。
Args:
title: 原始标题
Returns:
清理后的标题
"""
# 移除或替换不适合文件名的字符
# 保留中文、字母、数字、下划线、连字符
# 替换所有特殊字符(包括标点符号和常见符号)
safe = re.sub(r'[\\/:*?"<>|,。!?、;:""\'\'\s@#$%&*+\-=\[\]{}()<>]+', '_', title)
# 移除连续的下划线
safe = re.sub(r'_+', '_', safe)
# 去除首尾下划线和空格
safe = safe.strip('_')
# 限制长度(避免文件名过长)
if len(safe) > 50:
safe = safe[:50]
# 如果清理后为空,返回默认值
if not safe:
safe = "untitled"
return safe
def _ask_overwrite(self, existing_file: Path, is_non_interactive: bool = False) -> bool:
"""询问用户是否覆盖已存在的文件