将本地电子书库扫描、分类整理、搜索简介、导入Obsidian的完整工作流。
当用户提到以下需求时使用此技能:
# 扫描指定目录,提取epub/mobi/azw3/pdf格式的书籍元数据
# 支持读取书名、作者、分类等信息
关键函数:
scan_book_directory(book_dir) - 扫描书库目录extract_metadata(filepath) - 提取单本书的元数据分类规则:
分类/国家/作者/书名.mdAPI调用:
使用元宝搜索API搜索书籍简介,每个请求间隔2秒避免限流。
Windows编码处理:
decode('utf-8', errors='ignore')每本书生成一个Markdown文件,包含:
| 参数 | 说明 | 默认值 |
|---|---|---|
| ----- | ------ | ------- |
book_dir | 书库源目录 | 必填 |
output_dir | 输出目录 | Required |
batch_size | 每批处理数量 | 500 |
delay_seconds | API请求间隔 | 2 |
save_every | 每...本保存一次 | 100 |
书库/
├── 书库索引.json # 主索引(含全部书籍信息)
├── 书库总目录.md # 总览文档
├── 文学/ # 分类文件夹
│ ├── 中国/ # 国家文件夹
│ │ ├── 鲁迅/ # 作者文件夹
│ │ │ ├── 呐喊.md
│ │ │ └── ...
│ └── ...
└── ...
{
"version": "1.0",
"scan_date": "2026-04-18",
"books": [
{
"title": "书名",
"author": "作者",
"category": "文学",
"country": "中国",
"format": "EPUB",
"filename": "原文件名.epub",
"filepath": "原文件路径",
"introduction": "内容简介",
"intro_source": "来源URL"
}
]
}
Python调用PowerShell传递中文参数时:
result = subprocess.run(
['powershell', '-File', script_path, '-Keyword', keyword],
capture_output=True,
timeout=30
)
output = result.stdout.decode('utf-8', errors='ignore').strip()
import re
safe_name = re.sub(r'[<>:"/\\|?*]', '', original_name)[:50]
每批完成后保存进度,支持断点续传:
checkpoint = {
'last_batch': batch_num,
'total_found': found_count,
'last_index': last_processed_index,
'timestamp': datetime.now().isoformat()
}
用户: 帮我扫描 D:\LWbook 书库,整理后导入 Obsidian
执行步骤:
1. 扫描 D:\LWbook 目录
2. 提取书籍元数据
3. 按分类→国家→作者整理
4. 搜索每本书的简介
5. 生成 Obsidian Markdown 笔记
6. 建立索引文件
scripts/book_scanner.py - 书库扫描脚本scripts/batch_search.py - 批量搜索简介脚本scripts/generate_notes.py - 生成Obsidian笔记脚本scripts/search_book.ps1 - PowerShell搜索封装共 1 个版本