Skip to content

Commit 6b47ecb

Browse files
committed
docs: 修复文档渲染错误并同步 Feature 机制描述;优化异常处理语义
1 parent 3f8246d commit 6b47ecb

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

assets/docs/sources/tutorial/13_export_and_feature.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ download_album('123', option, extra=Feature.export_pdf)
3939

4040
**效果**:在本子下载完以后,额外在**当前工作目录**下生成包含所有本子图片的 PDF 文件:
4141

42-
```
42+
```text
4343
./
4444
├── [JM123]本子标题.pdf ← 整本合并为 1 个 PDF,注意pdf文件名的格式,默认包含本子禁漫车号+本子标题
4545
```
@@ -59,7 +59,7 @@ download_album('123', option, extra=Feature.export_pdf | Feature.export_zip)
5959

6060
效果同pdf,会在本子下载完以后,额外在当前工作目录下,生成包含所有本子图片的 PDF 文件和 ZIP 文件:
6161

62-
```
62+
```text
6363
./
6464
├── [JM123]本子标题.pdf ← 整本合并为 1 个 PDF
6565
├── [JM123]本子标题.zip ← 整本合并为 1 个 zip 压缩包
@@ -78,12 +78,14 @@ download_album('123', option, extra=Feature.export_pdf(
7878
filename_rule='Atitle', # 用本子标题作为文件名
7979
delete_original_file=True, # 合并完 PDF 后删除原图
8080
))
81+
```
8182

8283
> 💡 **小白必读:命名规则(filename_rule)的小知识**
8384
> - `A` 开头的占位符(如 `Atitle`, `Aid`)代表 **Album (本子)**,适用于 `download_album`
8485
> - `P` 开头的占位符(如 `Ptitle`, `Pid`)代表 **Photo (章节)**,适用于 `download_photo`
8586
> - 如果在下载整本(Album)时强行使用章节级(Photo)的规则,程序会因为不知道该用哪一章的标题而报错。
8687
88+
```python
8789
# 示例 2:全都要——ZIP 存盘 + 长图阅读
8890
combo = (
8991
Feature.export_zip(zip_dir='D:/zips')
@@ -103,7 +105,7 @@ download_photo('456', option, extra=Feature.export_pdf)
103105

104106
效果:在当前工作目录下生成以章节标题命名的 PDF:
105107

106-
```
108+
```text
107109
./
108110
├── [章节标题].pdf ← 该章节导出为 1 个 PDF
109111
```
@@ -147,20 +149,20 @@ plugins:
147149
148150
### 类层次
149151
150-
```
152+
```text
151153
Feature (基类)
152154
├── PluginFeature ← 封装插件调用,参数根据来源自适应
153155
└── 你的自定义 Feature ← 继承 Feature,实现任意逻辑
154156
```
155157

156158
- **Feature 基类**:通用的附加行为抽象,不绑定任何具体实现。默认在所有生命周期钩子中执行。
157-
- **PluginFeature**:Feature 的子类,专门封装 jmcomic 插件。除了调用插件之外,还会根据调用来源动态适配 `filename_rule``level` 等参数
159+
- **PluginFeature**:Feature 的子类,专门封装 jmcomic 插件。除了调用插件之外,还会根据调用来源动态适配 `filename_rule` 参数;ZIP 的打包粒度则由插件在运行时根据上下文自动推导
158160

159161
### 执行流程
160162

161163
Feature **自然嵌入到 downloader 的生命周期钩子**中自动触发:
162164

163-
```
165+
```text
164166
api.download_album(extra=Feature.export_pdf)
165167
166168
├→ dler.add_features(pdf, 'download_album') # 注册: [(pdf, 'download_album')]
@@ -186,7 +188,7 @@ api.download_album(extra=Feature.export_pdf)
186188
> 💡 **关键点**
187189
>
188190
> - **执行时机**`PluginFeature` 根据注册来源自动推导(`download_album``after_album``download_photo``after_photo`)。自定义 Feature 默认在所有钩子都会执行,你可以覆写 `should_invoke` 来控制。
189-
> - **参数自适应**`PluginFeature``filename_rule` 前缀(A/P)`level`(album/photo)会根据来源动态适配。用户显式传入的参数不会被覆盖。
191+
> - **参数自适应**`PluginFeature``filename_rule` 前缀(A/P)会根据来源动态适配。ZIP 的打包粒度由插件根据上下文自动推导。用户显式传入的参数不会被覆盖。
190192
191193
### 自定义 Feature
192194

src/jmcomic/jm_downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def _invoke_features_for(self, when: str, **kwargs):
310310
if feature.should_invoke(feature_from, when):
311311
try:
312312
feature.invoke(self.option, feature_from=feature_from, when=when, **kwargs)
313-
except BaseException as e:
313+
except Exception as e:
314314
jm_log('downloader.feature.exception', f'Feature执行失败: [{feature}], 来源: [{feature_from}], 异常: [{e}]')
315315

316316
def raise_if_has_exception(self):

0 commit comments

Comments
 (0)