jmcomic 2.7.3__tar.gz → 2.7.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jmcomic-2.7.3/src/jmcomic.egg-info → jmcomic-2.7.4}/PKG-INFO +14 -9
- {jmcomic-2.7.3 → jmcomic-2.7.4}/README.md +13 -8
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/__init__.py +1 -1
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/api.py +28 -16
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/cli.py +41 -6
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_async_client.py +23 -9
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_async_downloader.py +32 -5
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_client_impl.py +42 -12
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_client_interface.py +103 -13
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_config.py +9 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_downloader.py +192 -28
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_entity.py +30 -16
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_feature.py +16 -22
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_plugin.py +449 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_toolkit.py +36 -17
- {jmcomic-2.7.3 → jmcomic-2.7.4/src/jmcomic.egg-info}/PKG-INFO +14 -9
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic.egg-info/SOURCES.txt +0 -1
- jmcomic-2.7.3/src/jmcomic/cl.py +0 -11
- {jmcomic-2.7.3 → jmcomic-2.7.4}/LICENSE +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/pyproject.toml +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/setup.cfg +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/setup.py +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_exception.py +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_option.py +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic/jm_task_context.py +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic.egg-info/dependency_links.txt +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic.egg-info/entry_points.txt +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic.egg-info/requires.txt +0 -0
- {jmcomic-2.7.3 → jmcomic-2.7.4}/src/jmcomic.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jmcomic
|
|
3
|
-
Version: 2.7.
|
|
3
|
+
Version: 2.7.4
|
|
4
4
|
Summary: Python API For JMComic (禁漫天堂)
|
|
5
5
|
Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
|
|
6
6
|
Author: hect0x7
|
|
@@ -179,13 +179,12 @@ jmcomic.download_album(123, option)
|
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
### 3. 使用命令行
|
|
182
|
+
> [!TIP]
|
|
182
183
|
> 如果只想下载本子,使用命令行会比上述方式更加简单直接
|
|
183
184
|
>
|
|
184
185
|
> 例如,在windows上,直接按下 win+R 键,输入`jmcomic xxx`就可以下载本子。
|
|
185
186
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
下载本子123的命令
|
|
187
|
+
示例:下载本子123的命令
|
|
189
188
|
|
|
190
189
|
```sh
|
|
191
190
|
jmcomic 123
|
|
@@ -197,22 +196,28 @@ jmcomic 123 p456
|
|
|
197
196
|
|
|
198
197
|
命令行模式也支持自定义option,你可以使用环境变量或者命令行参数:
|
|
199
198
|
|
|
200
|
-
a.
|
|
199
|
+
a. 通过命令行 --option 参数指定option文件路径
|
|
201
200
|
|
|
202
201
|
```sh
|
|
203
202
|
jmcomic 123 --option="D:/a.yml"
|
|
204
203
|
```
|
|
205
204
|
|
|
206
|
-
b.
|
|
205
|
+
b. 命令行不改,而是配置环境变量 `JM_OPTION_PATH` 为option文件路径(推荐)
|
|
207
206
|
|
|
207
|
+
> [!TIP]
|
|
208
208
|
> 请自行google配置环境变量的方式,或使用powershell命令: `setx JM_OPTION_PATH "D:/a.yml"` 重启后生效
|
|
209
209
|
|
|
210
|
-
|
|
211
|
-
jmcomic
|
|
212
|
-
|
|
210
|
+
|
|
211
|
+
另外,`jmcomic` 还提供了一个美观的进度条能力,默认是开启的,但是需要你手动安装一个额外依赖 `pip install rich`。效果如下:
|
|
212
|
+
|
|
213
|
+

|
|
214
|
+
|
|
215
|
+
详细开启方法参考文档:[启用美观的下载进度条](assets/docs/sources/tutorial/15_download_progress.md)
|
|
216
|
+
|
|
213
217
|
|
|
214
218
|
### 4. 查看本子详情(jmv 命令)
|
|
215
219
|
|
|
220
|
+
> [!NOTE]
|
|
216
221
|
> `jmv` 命令用于快速查看本子详情,不做下载。
|
|
217
222
|
>
|
|
218
223
|
> **适用场景**:在某些网站上看到一串*神秘车号*,想快速看看具体是啥本子。此时只需copy原文本,按下 win+R,输入`jmv [粘贴内容]`即可
|
|
@@ -122,13 +122,12 @@ jmcomic.download_album(123, option)
|
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
### 3. 使用命令行
|
|
125
|
+
> [!TIP]
|
|
125
126
|
> 如果只想下载本子,使用命令行会比上述方式更加简单直接
|
|
126
127
|
>
|
|
127
128
|
> 例如,在windows上,直接按下 win+R 键,输入`jmcomic xxx`就可以下载本子。
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
下载本子123的命令
|
|
130
|
+
示例:下载本子123的命令
|
|
132
131
|
|
|
133
132
|
```sh
|
|
134
133
|
jmcomic 123
|
|
@@ -140,22 +139,28 @@ jmcomic 123 p456
|
|
|
140
139
|
|
|
141
140
|
命令行模式也支持自定义option,你可以使用环境变量或者命令行参数:
|
|
142
141
|
|
|
143
|
-
a.
|
|
142
|
+
a. 通过命令行 --option 参数指定option文件路径
|
|
144
143
|
|
|
145
144
|
```sh
|
|
146
145
|
jmcomic 123 --option="D:/a.yml"
|
|
147
146
|
```
|
|
148
147
|
|
|
149
|
-
b.
|
|
148
|
+
b. 命令行不改,而是配置环境变量 `JM_OPTION_PATH` 为option文件路径(推荐)
|
|
150
149
|
|
|
150
|
+
> [!TIP]
|
|
151
151
|
> 请自行google配置环境变量的方式,或使用powershell命令: `setx JM_OPTION_PATH "D:/a.yml"` 重启后生效
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
jmcomic
|
|
155
|
-
|
|
153
|
+
|
|
154
|
+
另外,`jmcomic` 还提供了一个美观的进度条能力,默认是开启的,但是需要你手动安装一个额外依赖 `pip install rich`。效果如下:
|
|
155
|
+
|
|
156
|
+

|
|
157
|
+
|
|
158
|
+
详细开启方法参考文档:[启用美观的下载进度条](assets/docs/sources/tutorial/15_download_progress.md)
|
|
159
|
+
|
|
156
160
|
|
|
157
161
|
### 4. 查看本子详情(jmv 命令)
|
|
158
162
|
|
|
163
|
+
> [!NOTE]
|
|
159
164
|
> `jmv` 命令用于快速查看本子详情,不做下载。
|
|
160
165
|
>
|
|
161
166
|
> **适用场景**:在某些网站上看到一串*神秘车号*,想快速看看具体是啥本子。此时只需copy原文本,按下 win+R,输入`jmv [粘贴内容]`即可
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
from time import perf_counter
|
|
2
3
|
|
|
3
4
|
from .jm_downloader import *
|
|
4
5
|
from .jm_task_context import bind_jm_task_context, jm_task_context
|
|
@@ -15,6 +16,12 @@ def _download_type(download_api) -> str:
|
|
|
15
16
|
return name
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
def _finish_download_result(detail, dler, task_started_at):
|
|
20
|
+
manifest = dler.manifest_dict[detail]
|
|
21
|
+
manifest.duration = perf_counter() - task_started_at
|
|
22
|
+
return DownloadResult(detail, dler)
|
|
23
|
+
|
|
24
|
+
|
|
18
25
|
def download_batch(download_api,
|
|
19
26
|
jm_id_iter: Union[Iterable, Generator],
|
|
20
27
|
option=None,
|
|
@@ -89,15 +96,17 @@ def download_album(jm_album_id,
|
|
|
89
96
|
if not isinstance(jm_album_id, (str, int)):
|
|
90
97
|
return download_batch(download_album, jm_album_id, option, downloader, extra=extra)
|
|
91
98
|
|
|
92
|
-
|
|
99
|
+
task_started_at = perf_counter()
|
|
100
|
+
with jm_task_context(download_type='album', jm_id=str(jm_album_id), task_started_at=task_started_at):
|
|
93
101
|
with new_downloader(option, downloader) as dler:
|
|
94
|
-
#
|
|
95
|
-
dler.add_features(extra
|
|
102
|
+
# 下载类型已记录在 TaskContext 中,Feature 会据此选择执行钩子
|
|
103
|
+
dler.add_features(extra)
|
|
96
104
|
album = dler.download_album(jm_album_id)
|
|
97
105
|
|
|
98
106
|
if check_exception:
|
|
99
107
|
dler.raise_if_has_exception()
|
|
100
|
-
|
|
108
|
+
|
|
109
|
+
return _finish_download_result(album, dler, task_started_at)
|
|
101
110
|
|
|
102
111
|
|
|
103
112
|
def download_photo(jm_photo_id,
|
|
@@ -116,15 +125,17 @@ def download_photo(jm_photo_id,
|
|
|
116
125
|
if not isinstance(jm_photo_id, (str, int)):
|
|
117
126
|
return download_batch(download_photo, jm_photo_id, option, downloader, extra=extra)
|
|
118
127
|
|
|
119
|
-
|
|
128
|
+
task_started_at = perf_counter()
|
|
129
|
+
with jm_task_context(download_type='photo', jm_id=str(jm_photo_id), task_started_at=task_started_at):
|
|
120
130
|
with new_downloader(option, downloader) as dler:
|
|
121
|
-
#
|
|
122
|
-
dler.add_features(extra
|
|
131
|
+
# 下载类型已记录在 TaskContext 中,Feature 会据此选择执行钩子
|
|
132
|
+
dler.add_features(extra)
|
|
123
133
|
photo = dler.download_photo(jm_photo_id)
|
|
124
134
|
|
|
125
135
|
if check_exception:
|
|
126
136
|
dler.raise_if_has_exception()
|
|
127
|
-
|
|
137
|
+
|
|
138
|
+
return _finish_download_result(photo, dler, task_started_at)
|
|
128
139
|
|
|
129
140
|
|
|
130
141
|
def new_downloader(option=None, downloader=None) -> JmDownloader:
|
|
@@ -161,12 +172,11 @@ create_option = create_option_by_file
|
|
|
161
172
|
|
|
162
173
|
|
|
163
174
|
def new_async_downloader(option=None, downloader=None):
|
|
164
|
-
from .jm_async_downloader import JmAsyncDownloader
|
|
165
175
|
if option is None:
|
|
166
176
|
option = JmModuleConfig.option_class().default()
|
|
167
177
|
|
|
168
178
|
if downloader is None:
|
|
169
|
-
downloader =
|
|
179
|
+
downloader = JmModuleConfig.async_downloader_class()
|
|
170
180
|
|
|
171
181
|
return downloader(option)
|
|
172
182
|
|
|
@@ -194,15 +204,16 @@ async def download_album_async(jm_album_id,
|
|
|
194
204
|
extra=extra
|
|
195
205
|
)
|
|
196
206
|
|
|
197
|
-
|
|
207
|
+
task_started_at = perf_counter()
|
|
208
|
+
with jm_task_context(download_type='album', jm_id=str(jm_album_id), task_started_at=task_started_at):
|
|
198
209
|
async with new_async_downloader(option, downloader) as dler:
|
|
199
|
-
dler.add_features(extra
|
|
210
|
+
dler.add_features(extra)
|
|
200
211
|
album = await dler.download_album(jm_album_id)
|
|
201
212
|
|
|
202
213
|
if check_exception:
|
|
203
214
|
dler.raise_if_has_exception()
|
|
204
215
|
|
|
205
|
-
|
|
216
|
+
return _finish_download_result(album, dler, task_started_at)
|
|
206
217
|
|
|
207
218
|
|
|
208
219
|
async def download_photo_async(jm_photo_id,
|
|
@@ -226,15 +237,16 @@ async def download_photo_async(jm_photo_id,
|
|
|
226
237
|
extra=extra
|
|
227
238
|
)
|
|
228
239
|
|
|
229
|
-
|
|
240
|
+
task_started_at = perf_counter()
|
|
241
|
+
with jm_task_context(download_type='photo', jm_id=str(jm_photo_id), task_started_at=task_started_at):
|
|
230
242
|
async with new_async_downloader(option, downloader) as dler:
|
|
231
|
-
dler.add_features(extra
|
|
243
|
+
dler.add_features(extra)
|
|
232
244
|
photo = await dler.download_photo(jm_photo_id)
|
|
233
245
|
|
|
234
246
|
if check_exception:
|
|
235
247
|
dler.raise_if_has_exception()
|
|
236
248
|
|
|
237
|
-
|
|
249
|
+
return _finish_download_result(photo, dler, task_started_at)
|
|
238
250
|
|
|
239
251
|
|
|
240
252
|
async def download_batch_async(download_api,
|
|
@@ -12,6 +12,7 @@ command-line usage
|
|
|
12
12
|
$ jmv abc123141 --option="D:/option.yml"
|
|
13
13
|
|
|
14
14
|
"""
|
|
15
|
+
import importlib.util
|
|
15
16
|
import os.path
|
|
16
17
|
from typing import List, Optional
|
|
17
18
|
|
|
@@ -29,6 +30,7 @@ class JmcomicUI:
|
|
|
29
30
|
|
|
30
31
|
def __init__(self) -> None:
|
|
31
32
|
self.option_path: Optional[str] = None
|
|
33
|
+
self.progress_enabled = True
|
|
32
34
|
self.raw_id_list: List[str] = []
|
|
33
35
|
self.album_id_list: List[str] = []
|
|
34
36
|
self.photo_id_list: List[str] = []
|
|
@@ -50,8 +52,15 @@ class JmcomicUI:
|
|
|
50
52
|
type=str,
|
|
51
53
|
default=get_env('JM_OPTION_PATH', ''),
|
|
52
54
|
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
'--no-progress',
|
|
57
|
+
action='store_false',
|
|
58
|
+
dest='progress_enabled',
|
|
59
|
+
help='do not automatically enable the download progress plugin',
|
|
60
|
+
)
|
|
53
61
|
|
|
54
62
|
args = parser.parse_args()
|
|
63
|
+
self.progress_enabled = args.progress_enabled
|
|
55
64
|
option = args.option
|
|
56
65
|
if len(option) == 0 or option == "''":
|
|
57
66
|
self.option_path = None
|
|
@@ -82,6 +91,16 @@ class JmcomicUI:
|
|
|
82
91
|
|
|
83
92
|
def main(self):
|
|
84
93
|
self.parse_arg()
|
|
94
|
+
from .api import create_option, JmOption
|
|
95
|
+
from .jm_task_context import jm_task_context
|
|
96
|
+
with jm_task_context(cli_no_progress=not self.progress_enabled):
|
|
97
|
+
if self.option_path is not None:
|
|
98
|
+
option = create_option(self.option_path)
|
|
99
|
+
else:
|
|
100
|
+
option = JmOption.default()
|
|
101
|
+
|
|
102
|
+
self.enable_download_progress(option)
|
|
103
|
+
|
|
85
104
|
from .api import jm_log
|
|
86
105
|
jm_log('command_line',
|
|
87
106
|
f'start downloading...\n'
|
|
@@ -90,14 +109,30 @@ class JmcomicUI:
|
|
|
90
109
|
f'- album: {self.album_id_list}\n'
|
|
91
110
|
f'- photo: {self.photo_id_list}')
|
|
92
111
|
|
|
93
|
-
from .api import create_option, JmOption
|
|
94
|
-
if self.option_path is not None:
|
|
95
|
-
option = create_option(self.option_path)
|
|
96
|
-
else:
|
|
97
|
-
option = JmOption.default()
|
|
98
|
-
|
|
99
112
|
self.run(option)
|
|
100
113
|
|
|
114
|
+
def enable_download_progress(self, option):
|
|
115
|
+
option_enabled = self.option_has_download_progress(option)
|
|
116
|
+
if not self.progress_enabled:
|
|
117
|
+
return
|
|
118
|
+
|
|
119
|
+
if option_enabled:
|
|
120
|
+
return
|
|
121
|
+
|
|
122
|
+
if importlib.util.find_spec('rich') is None:
|
|
123
|
+
from .jm_config import jm_log
|
|
124
|
+
jm_log('command_line.progress',
|
|
125
|
+
'未安装 rich,继续使用普通日志。如需显示下载进度,请执行:pip install rich')
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
from .jm_plugin import DownloadProgressPlugin
|
|
129
|
+
DownloadProgressPlugin.build(option).invoke()
|
|
130
|
+
|
|
131
|
+
@staticmethod
|
|
132
|
+
def option_has_download_progress(option):
|
|
133
|
+
plugin_list = option.plugins.get('after_init', []) or []
|
|
134
|
+
return any(plugin.get('plugin') == 'download_progress' for plugin in plugin_list)
|
|
135
|
+
|
|
101
136
|
def run(self, option):
|
|
102
137
|
from .api import download_album, download_photo
|
|
103
138
|
from common import MultiTaskLauncher
|
|
@@ -7,6 +7,7 @@ from __future__ import annotations
|
|
|
7
7
|
|
|
8
8
|
import asyncio
|
|
9
9
|
import json
|
|
10
|
+
from copy import deepcopy
|
|
10
11
|
from typing import Sequence
|
|
11
12
|
from urllib.parse import urlencode
|
|
12
13
|
|
|
@@ -184,7 +185,6 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
184
185
|
return
|
|
185
186
|
|
|
186
187
|
# 提取应用配置中预设的网络通信元数据信息(如代理配置与全局 Headers)
|
|
187
|
-
from copy import deepcopy
|
|
188
188
|
postman_conf = deepcopy(self.option.client.get('postman', {}))
|
|
189
189
|
meta_data = postman_conf.get('meta_data', {})
|
|
190
190
|
if self._meta_kwargs:
|
|
@@ -393,7 +393,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
393
393
|
cached = self._cache_get(cache_key)
|
|
394
394
|
if cached is not self._SENTINEL:
|
|
395
395
|
# noinspection PyTypeChecker
|
|
396
|
-
return cached
|
|
396
|
+
return deepcopy(cached)
|
|
397
397
|
|
|
398
398
|
url = self.API_ALBUM if issubclass(clazz, JmAlbumDetail) else self.API_CHAPTER
|
|
399
399
|
resp = await self.req_api(url, params={'id': jmid})
|
|
@@ -402,7 +402,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
402
402
|
ExceptionTool.raise_missing(resp, jmid)
|
|
403
403
|
|
|
404
404
|
result = JmApiAdaptTool.parse_entity(resp.res_data, clazz)
|
|
405
|
-
self._cache_set(cache_key, result)
|
|
405
|
+
self._cache_set(cache_key, deepcopy(result))
|
|
406
406
|
return result
|
|
407
407
|
|
|
408
408
|
async def get_album_detail(self, album_id) -> JmAlbumDetail:
|
|
@@ -559,9 +559,9 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
559
559
|
data = resp.model_data
|
|
560
560
|
if data.get('redirect_aid', None) is not None:
|
|
561
561
|
aid = data.redirect_aid
|
|
562
|
-
result = JmSearchPage.wrap_single_album(await self.get_album_detail(aid))
|
|
562
|
+
result = JmSearchPage.wrap_single_album(await self.get_album_detail(aid), page)
|
|
563
563
|
else:
|
|
564
|
-
result = JmPageTool.parse_api_to_search_page(data)
|
|
564
|
+
result = JmPageTool.parse_api_to_search_page(data, page)
|
|
565
565
|
|
|
566
566
|
self._cache_set(cache_key, result)
|
|
567
567
|
return result
|
|
@@ -592,7 +592,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
592
592
|
'o': o,
|
|
593
593
|
}
|
|
594
594
|
resp = await self.req_api(self.API_CATEGORIES_FILTER, params=params)
|
|
595
|
-
return JmPageTool.parse_api_to_search_page(resp.model_data)
|
|
595
|
+
return JmPageTool.parse_api_to_search_page(resp.model_data, page)
|
|
596
596
|
|
|
597
597
|
# month_ranking / week_ranking / day_ranking
|
|
598
598
|
# 继承自 AsyncJmcomicClient 基类
|
|
@@ -631,7 +631,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
631
631
|
'o': order_by,
|
|
632
632
|
}
|
|
633
633
|
)
|
|
634
|
-
return JmPageTool.parse_api_to_favorite_page(resp.model_data)
|
|
634
|
+
return JmPageTool.parse_api_to_favorite_page(resp.model_data, page)
|
|
635
635
|
|
|
636
636
|
async def album_pagination(self,
|
|
637
637
|
jm_id: str,
|
|
@@ -640,7 +640,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
640
640
|
with_ad_wcm=1,
|
|
641
641
|
need_total=True,
|
|
642
642
|
) -> JmAlbumCommentPage:
|
|
643
|
-
"""
|
|
643
|
+
"""获取本子评论分页,返回评论分页对象。"""
|
|
644
644
|
resp = await self.req_api(
|
|
645
645
|
self.API_FORUM,
|
|
646
646
|
params={
|
|
@@ -649,7 +649,21 @@ class AsyncJmApiClient(AsyncJmcomicClient):
|
|
|
649
649
|
'aid': JmcomicText.parse_to_jm_id(jm_id),
|
|
650
650
|
},
|
|
651
651
|
)
|
|
652
|
-
return JmPageTool.parse_api_to_album_comment_page(resp.model_data)
|
|
652
|
+
return JmPageTool.parse_api_to_album_comment_page(resp.model_data, page)
|
|
653
|
+
|
|
654
|
+
async def forum_pagination(self,
|
|
655
|
+
page=1,
|
|
656
|
+
with_ad_wcm=1,
|
|
657
|
+
) -> JmAlbumCommentPage:
|
|
658
|
+
"""获取全站评论分页。"""
|
|
659
|
+
resp = await self.req_api(
|
|
660
|
+
self.API_FORUM,
|
|
661
|
+
params={
|
|
662
|
+
'mode': 'all',
|
|
663
|
+
'page': page,
|
|
664
|
+
},
|
|
665
|
+
)
|
|
666
|
+
return JmPageTool.parse_api_to_album_comment_page(resp.model_data, page)
|
|
653
667
|
|
|
654
668
|
async def add_favorite_album(self, album_id, folder_id='0'):
|
|
655
669
|
"""
|
|
@@ -12,10 +12,10 @@ import asyncio
|
|
|
12
12
|
import os
|
|
13
13
|
from concurrent.futures import ThreadPoolExecutor
|
|
14
14
|
|
|
15
|
-
from .jm_downloader import BaseDownloader
|
|
15
|
+
from .jm_downloader import BaseDownloader, record_download_duration
|
|
16
16
|
from .jm_entity import JmAlbumDetail, JmPhotoDetail, JmImageDetail
|
|
17
17
|
from .jm_toolkit import JmImageTool
|
|
18
|
-
from .jm_config import jm_log
|
|
18
|
+
from .jm_config import JmModuleConfig, jm_log
|
|
19
19
|
from .jm_task_context import bind_jm_task_context
|
|
20
20
|
from .jm_option import JmOption
|
|
21
21
|
|
|
@@ -53,6 +53,18 @@ class JmAsyncDownloader(BaseDownloader):
|
|
|
53
53
|
# 解密线程池(CPU 密集操作卸载)
|
|
54
54
|
self._decode_pool = ThreadPoolExecutor(max_workers=decode_worker, thread_name_prefix='jm-async-decode')
|
|
55
55
|
|
|
56
|
+
@classmethod
|
|
57
|
+
def use(cls, *args, **kwargs):
|
|
58
|
+
before_class = JmModuleConfig.async_downloader_class()
|
|
59
|
+
JmModuleConfig.CLASS_ASYNC_DOWNLOADER = cls
|
|
60
|
+
after_class = JmModuleConfig.async_downloader_class()
|
|
61
|
+
jm_log(
|
|
62
|
+
'async_downloader.use',
|
|
63
|
+
f'替换 Async Downloader class: '
|
|
64
|
+
f'[{before_class.__module__}.{before_class.__qualname__}] -> '
|
|
65
|
+
f'[{after_class.__module__}.{after_class.__qualname__}]'
|
|
66
|
+
)
|
|
67
|
+
|
|
56
68
|
# ======================================================================
|
|
57
69
|
# 核心下载流程 — 对齐 sync JmDownloader
|
|
58
70
|
# ======================================================================
|
|
@@ -65,17 +77,24 @@ class JmAsyncDownloader(BaseDownloader):
|
|
|
65
77
|
*args,
|
|
66
78
|
)
|
|
67
79
|
|
|
80
|
+
@record_download_duration('album_started_at')
|
|
68
81
|
async def download_album(self, album_id) -> JmAlbumDetail:
|
|
69
82
|
"""对齐 sync JmDownloader.download_album"""
|
|
70
83
|
album = await self.client.get_album_detail(album_id)
|
|
71
|
-
|
|
84
|
+
self.begin_manifest(album)
|
|
85
|
+
try:
|
|
86
|
+
await self.download_by_album_detail(album)
|
|
87
|
+
finally:
|
|
88
|
+
self.finish_manifest(album)
|
|
72
89
|
return album
|
|
73
90
|
|
|
91
|
+
@record_download_duration('album_started_at')
|
|
74
92
|
async def download_by_album_detail(self, album: JmAlbumDetail):
|
|
75
93
|
"""
|
|
76
94
|
异步下载整个本子。
|
|
77
95
|
对齐 sync JmDownloader.download_by_album_detail 的回调链路。
|
|
78
96
|
"""
|
|
97
|
+
album.save_path = self.option.dir_rule.decide_album_root_dir(album)
|
|
79
98
|
await self.before_album(album)
|
|
80
99
|
if album.skip:
|
|
81
100
|
return
|
|
@@ -99,17 +118,24 @@ class JmAsyncDownloader(BaseDownloader):
|
|
|
99
118
|
jm_log('photo.failed', f'章节下载失败: [{photo.id}], 异常: [{e}]', e)
|
|
100
119
|
self.download_failed_photo.append((photo, e))
|
|
101
120
|
|
|
121
|
+
@record_download_duration('photo_started_at')
|
|
102
122
|
async def download_photo(self, photo_id) -> JmPhotoDetail:
|
|
103
123
|
"""对齐 sync JmDownloader.download_photo"""
|
|
104
124
|
photo = await self.client.get_photo_detail(photo_id)
|
|
105
|
-
|
|
125
|
+
self.begin_manifest(photo)
|
|
126
|
+
try:
|
|
127
|
+
await self.download_by_photo_detail(photo)
|
|
128
|
+
finally:
|
|
129
|
+
self.finish_manifest(photo)
|
|
106
130
|
return photo
|
|
107
131
|
|
|
132
|
+
@record_download_duration('photo_started_at')
|
|
108
133
|
async def download_by_photo_detail(self, photo: JmPhotoDetail):
|
|
109
134
|
"""
|
|
110
135
|
异步下载一个章节的所有图片。
|
|
111
136
|
对齐 sync JmDownloader.download_by_photo_detail 的回调链路。
|
|
112
137
|
"""
|
|
138
|
+
photo.save_path = self.option.decide_image_save_dir(photo)
|
|
113
139
|
# _photo_semaphore 包裹整段 photo 下载(check_photo + 全部图片),
|
|
114
140
|
# 真正限制「同时下载的章节数」(对齐 sync:每个 photo 占用 photo 线程池一个槽位)。
|
|
115
141
|
# 章节内图片再由共享的 _image_semaphore 二级限流。
|
|
@@ -145,6 +171,7 @@ class JmAsyncDownloader(BaseDownloader):
|
|
|
145
171
|
jm_log('image.failed', f'图片下载失败: [{image.download_url}], 异常: [{e}]', e)
|
|
146
172
|
self.download_failed_image.append((image, e))
|
|
147
173
|
|
|
174
|
+
@record_download_duration('image_started_at')
|
|
148
175
|
async def _download_single_image(self, image: JmImageDetail):
|
|
149
176
|
"""
|
|
150
177
|
下载并解密单张图片的完整流程。
|
|
@@ -159,8 +186,8 @@ class JmAsyncDownloader(BaseDownloader):
|
|
|
159
186
|
if image.skip:
|
|
160
187
|
return
|
|
161
188
|
|
|
162
|
-
# 检查缓存,跳过下载
|
|
163
189
|
if image.cache and image.exists:
|
|
190
|
+
await self.after_image(image, img_save_path)
|
|
164
191
|
return
|
|
165
192
|
|
|
166
193
|
decode_image = self.option.decide_download_image_decode(image)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
1
2
|
from threading import Lock
|
|
2
3
|
|
|
3
4
|
from .jm_task_context import bind_jm_task_context
|
|
@@ -187,10 +188,10 @@ class AbstractJmClient(
|
|
|
187
188
|
|
|
188
189
|
result = cache.get(key, sentinel)
|
|
189
190
|
if result is not sentinel:
|
|
190
|
-
return result
|
|
191
|
+
return deepcopy(result) if isinstance(result, DetailEntity) else result
|
|
191
192
|
|
|
192
193
|
result = func(*args, **kwargs)
|
|
193
|
-
cache[key] = result
|
|
194
|
+
cache[key] = deepcopy(result) if isinstance(result, DetailEntity) else result
|
|
194
195
|
return result
|
|
195
196
|
|
|
196
197
|
setattr(self, func_name, cache_wrapper)
|
|
@@ -243,6 +244,7 @@ class JmHtmlClient(AbstractJmClient):
|
|
|
243
244
|
API_SEARCH = '/search/photos'
|
|
244
245
|
API_CATEGORY = '/albums'
|
|
245
246
|
API_ALBUM_PAGINATION = '/ajax/album_pagination'
|
|
247
|
+
API_FORUM = '/ajax/forum_more'
|
|
246
248
|
|
|
247
249
|
def add_favorite_album(self,
|
|
248
250
|
album_id,
|
|
@@ -335,9 +337,9 @@ class JmHtmlClient(AbstractJmClient):
|
|
|
335
337
|
# 因为如果搜索的是禁漫车号,会直接跳转到本子详情页面
|
|
336
338
|
if resp.redirect_count != 0 and '/album/' in resp.url:
|
|
337
339
|
album = JmcomicText.analyse_jm_album_html(resp.text)
|
|
338
|
-
return JmSearchPage.wrap_single_album(album)
|
|
340
|
+
return JmSearchPage.wrap_single_album(album, page)
|
|
339
341
|
else:
|
|
340
|
-
return JmPageTool.parse_html_to_search_page(resp.text)
|
|
342
|
+
return JmPageTool.parse_html_to_search_page(resp.text, page)
|
|
341
343
|
|
|
342
344
|
@classmethod
|
|
343
345
|
def build_search_url(cls, base: str, category: str, sub_category: Optional[str]):
|
|
@@ -378,7 +380,7 @@ class JmHtmlClient(AbstractJmClient):
|
|
|
378
380
|
allow_redirects=True,
|
|
379
381
|
)
|
|
380
382
|
|
|
381
|
-
return JmPageTool.parse_html_to_category_page(resp.text)
|
|
383
|
+
return JmPageTool.parse_html_to_category_page(resp.text, page)
|
|
382
384
|
|
|
383
385
|
# -- 帐号管理 --
|
|
384
386
|
|
|
@@ -438,7 +440,7 @@ class JmHtmlClient(AbstractJmClient):
|
|
|
438
440
|
}
|
|
439
441
|
)
|
|
440
442
|
|
|
441
|
-
return JmPageTool.parse_html_to_favorite_page(resp.text)
|
|
443
|
+
return JmPageTool.parse_html_to_favorite_page(resp.text, page)
|
|
442
444
|
|
|
443
445
|
# noinspection PyTypeChecker
|
|
444
446
|
def get_username_from_cookies(self) -> str:
|
|
@@ -553,13 +555,28 @@ class JmHtmlClient(AbstractJmClient):
|
|
|
553
555
|
|
|
554
556
|
ret = JmJsonResp(resp)
|
|
555
557
|
ret.require_success()
|
|
556
|
-
comment_page = JmPageTool.parse_html_to_album_comment_page(ret.model())
|
|
558
|
+
comment_page = JmPageTool.parse_html_to_album_comment_page(ret.model(), page)
|
|
557
559
|
if need_total:
|
|
558
560
|
album = self.get_album_detail(jm_id)
|
|
559
561
|
comment_page.total = album.comment_count
|
|
560
562
|
|
|
561
563
|
return comment_page
|
|
562
564
|
|
|
565
|
+
def forum_pagination(self,
|
|
566
|
+
page=1,
|
|
567
|
+
with_ad_wcm=1,
|
|
568
|
+
) -> JmAlbumCommentPage:
|
|
569
|
+
resp = self.post(
|
|
570
|
+
self.API_FORUM,
|
|
571
|
+
data={
|
|
572
|
+
'page': page,
|
|
573
|
+
'with_ad_wcm': with_ad_wcm,
|
|
574
|
+
},
|
|
575
|
+
)
|
|
576
|
+
ret = JmJsonResp(resp)
|
|
577
|
+
ret.require_success()
|
|
578
|
+
return JmPageTool.parse_html_to_album_comment_page(ret.model(), page)
|
|
579
|
+
|
|
563
580
|
@classmethod
|
|
564
581
|
def require_resp_success_else_raise(cls, resp, url: str):
|
|
565
582
|
"""
|
|
@@ -672,9 +689,9 @@ class JmApiClient(AbstractJmClient):
|
|
|
672
689
|
data = resp.model_data
|
|
673
690
|
if data.get('redirect_aid', None) is not None:
|
|
674
691
|
aid = data.redirect_aid
|
|
675
|
-
return JmSearchPage.wrap_single_album(self.get_album_detail(aid))
|
|
692
|
+
return JmSearchPage.wrap_single_album(self.get_album_detail(aid), page)
|
|
676
693
|
|
|
677
|
-
return JmPageTool.parse_api_to_search_page(data)
|
|
694
|
+
return JmPageTool.parse_api_to_search_page(data, page)
|
|
678
695
|
|
|
679
696
|
def categories_filter(self,
|
|
680
697
|
page: int,
|
|
@@ -698,7 +715,7 @@ class JmApiClient(AbstractJmClient):
|
|
|
698
715
|
|
|
699
716
|
resp = self.req_api(self.append_params_to_url(self.API_CATEGORIES_FILTER, params))
|
|
700
717
|
|
|
701
|
-
return JmPageTool.parse_api_to_search_page(resp.model_data)
|
|
718
|
+
return JmPageTool.parse_api_to_search_page(resp.model_data, page)
|
|
702
719
|
|
|
703
720
|
def get_album_detail(self, album_id) -> JmAlbumDetail:
|
|
704
721
|
return self.fetch_detail_entity(album_id,
|
|
@@ -883,7 +900,7 @@ class JmApiClient(AbstractJmClient):
|
|
|
883
900
|
}
|
|
884
901
|
)
|
|
885
902
|
|
|
886
|
-
return JmPageTool.parse_api_to_favorite_page(resp.model_data)
|
|
903
|
+
return JmPageTool.parse_api_to_favorite_page(resp.model_data, page)
|
|
887
904
|
|
|
888
905
|
def album_comment(self,
|
|
889
906
|
video_id,
|
|
@@ -910,7 +927,20 @@ class JmApiClient(AbstractJmClient):
|
|
|
910
927
|
'aid': JmcomicText.parse_to_jm_id(jm_id),
|
|
911
928
|
},
|
|
912
929
|
)
|
|
913
|
-
return JmPageTool.parse_api_to_album_comment_page(resp.model_data)
|
|
930
|
+
return JmPageTool.parse_api_to_album_comment_page(resp.model_data, page)
|
|
931
|
+
|
|
932
|
+
def forum_pagination(self,
|
|
933
|
+
page=1,
|
|
934
|
+
with_ad_wcm=1,
|
|
935
|
+
) -> JmAlbumCommentPage:
|
|
936
|
+
resp = self.req_api(
|
|
937
|
+
self.API_FORUM,
|
|
938
|
+
params={
|
|
939
|
+
'mode': 'all',
|
|
940
|
+
'page': page,
|
|
941
|
+
},
|
|
942
|
+
)
|
|
943
|
+
return JmPageTool.parse_api_to_album_comment_page(resp.model_data, page)
|
|
914
944
|
|
|
915
945
|
def add_favorite_album(self,
|
|
916
946
|
album_id,
|