jmcomic 2.7.0__tar.gz → 2.7.2__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.
Files changed (28) hide show
  1. {jmcomic-2.7.0/src/jmcomic.egg-info → jmcomic-2.7.2}/PKG-INFO +2 -2
  2. {jmcomic-2.7.0 → jmcomic-2.7.2}/README.md +1 -1
  3. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/__init__.py +1 -1
  4. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/api.py +50 -26
  5. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_async_client.py +69 -31
  6. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_async_downloader.py +12 -1
  7. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_client_interface.py +25 -0
  8. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_config.py +16 -32
  9. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_downloader.py +34 -0
  10. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_entity.py +7 -4
  11. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_option.py +13 -2
  12. {jmcomic-2.7.0 → jmcomic-2.7.2/src/jmcomic.egg-info}/PKG-INFO +2 -2
  13. {jmcomic-2.7.0 → jmcomic-2.7.2}/LICENSE +0 -0
  14. {jmcomic-2.7.0 → jmcomic-2.7.2}/pyproject.toml +0 -0
  15. {jmcomic-2.7.0 → jmcomic-2.7.2}/setup.cfg +0 -0
  16. {jmcomic-2.7.0 → jmcomic-2.7.2}/setup.py +0 -0
  17. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/cl.py +0 -0
  18. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/cli.py +0 -0
  19. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_client_impl.py +0 -0
  20. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_exception.py +0 -0
  21. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_feature.py +0 -0
  22. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_plugin.py +0 -0
  23. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic/jm_toolkit.py +0 -0
  24. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic.egg-info/SOURCES.txt +0 -0
  25. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic.egg-info/dependency_links.txt +0 -0
  26. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic.egg-info/entry_points.txt +0 -0
  27. {jmcomic-2.7.0 → jmcomic-2.7.2}/src/jmcomic.egg-info/requires.txt +0 -0
  28. {jmcomic-2.7.0 → jmcomic-2.7.2}/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.0
3
+ Version: 2.7.2
4
4
  Summary: Python API For JMComic (禁漫天堂)
5
5
  Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
6
6
  Author: hect0x7
@@ -94,7 +94,7 @@ Dynamic: requires-python
94
94
  >
95
95
 
96
96
 
97
- ![introduction.jpg](./assets/docs/sources/images/introduction.jpg)
97
+ ![introduction.jpg](https://raw.githubusercontent.com/hect0x7/hect0x7/master/images/jmcomic-intro-main.png)
98
98
 
99
99
 
100
100
  ## 项目介绍
@@ -37,7 +37,7 @@
37
37
  >
38
38
 
39
39
 
40
- ![introduction.jpg](./assets/docs/sources/images/introduction.jpg)
40
+ ![introduction.jpg](https://raw.githubusercontent.com/hect0x7/hect0x7/master/images/jmcomic-intro-main.png)
41
41
 
42
42
 
43
43
  ## 项目介绍
@@ -2,7 +2,7 @@
2
2
  # 被依赖方 <--- 使用方
3
3
  # config <--- entity <--- toolkit <--- client <--- option <--- downloader
4
4
 
5
- __version__ = '2.7.0'
5
+ __version__ = '2.7.2'
6
6
 
7
7
  from .api import *
8
8
  from .jm_plugin import *
@@ -1,8 +1,26 @@
1
1
  import asyncio
2
+ import inspect
2
3
 
3
4
  from .jm_downloader import *
4
5
 
5
- __DOWNLOAD_API_RET = Tuple[JmAlbumDetail, JmDownloader]
6
+ __DOWNLOAD_API_RET = DownloadResult
7
+
8
+
9
+ async def _invoke_async_callback(callback, entity, downloader):
10
+ if callback is None:
11
+ return None
12
+
13
+ is_async_callback = (
14
+ inspect.iscoroutinefunction(callback)
15
+ or inspect.iscoroutinefunction(getattr(callback, '__call__', None))
16
+ )
17
+ if is_async_callback:
18
+ return await callback(entity, downloader)
19
+
20
+ result = await asyncio.to_thread(callback, entity, downloader)
21
+ if inspect.isawaitable(result):
22
+ return await result
23
+ return result
6
24
 
7
25
 
8
26
  def download_batch(download_api,
@@ -10,11 +28,13 @@ def download_batch(download_api,
10
28
  option=None,
11
29
  downloader=None,
12
30
  **kwargs,
13
- ) -> Set[__DOWNLOAD_API_RET]:
31
+ ) -> BatchResult:
14
32
  """
15
33
  批量下载 album / photo
16
34
 
17
- 一个album/photo,对应一个线程,对应一个option
35
+ 一个album/photo,对应一个线程,对应一个option。
36
+ 返回 BatchResult(set),支持 for album, dler in result 遍历。
37
+ 失败项收集在 result.failed 中,不会静默丢失。
18
38
 
19
39
  :param download_api: 下载api
20
40
  :param jm_id_iter: jmid (album_id, photo_id) 的迭代器
@@ -26,22 +46,23 @@ def download_batch(download_api,
26
46
  if option is None:
27
47
  option = JmModuleConfig.option_class().default()
28
48
 
29
- result = set()
49
+ result = BatchResult()
30
50
 
31
- def callback(*ret):
32
- result.add(ret)
51
+ def _safe_download(aid):
52
+ """batch 内部的单任务包装:确保异常被收集而非静默丢失"""
53
+ try:
54
+ ret = download_api(aid, option, downloader, **kwargs)
55
+ result.add(ret)
56
+ except Exception as e:
57
+ jm_log('batch.failed', f'批量下载失败: [{aid}], 异常: [{e}]', e)
58
+ result.failed[str(aid)] = e
33
59
 
34
60
  multi_thread_launcher(
35
61
  iter_objs=set(
36
62
  JmcomicText.parse_to_jm_id(jmid)
37
63
  for jmid in jm_id_iter
38
64
  ),
39
- apply_each_obj_func=lambda aid: download_api(aid,
40
- option,
41
- downloader,
42
- callback=callback,
43
- **kwargs,
44
- ),
65
+ apply_each_obj_func=_safe_download,
45
66
  wait_finish=True
46
67
  )
47
68
 
@@ -81,7 +102,7 @@ def download_album(jm_album_id,
81
102
  callback(album, dler)
82
103
  if check_exception:
83
104
  dler.raise_if_has_exception()
84
- return album, dler
105
+ return DownloadResult(album, dler)
85
106
 
86
107
 
87
108
  def download_photo(jm_photo_id,
@@ -106,7 +127,7 @@ def download_photo(jm_photo_id,
106
127
  callback(photo, dler)
107
128
  if check_exception:
108
129
  dler.raise_if_has_exception()
109
- return photo, dler
130
+ return DownloadResult(photo, dler)
110
131
 
111
132
 
112
133
  def new_downloader(option=None, downloader=None) -> JmDownloader:
@@ -164,7 +185,8 @@ async def download_album_async(jm_album_id,
164
185
  异步下载一个本子(album),包含其所有的章节(photo)。
165
186
 
166
187
  - 支持批量下载(当 jm_album_id 为可迭代对象时)
167
- - 返回 (album, downloader) 元组
188
+ - callback 支持同步函数和异步函数
189
+ - 返回 (album, downloader) 元组,其中 downloader 的网络和线程池资源已关闭,仅用于读取下载结果
168
190
  """
169
191
  if not isinstance(jm_album_id, (str, int)):
170
192
  return await download_batch_async(download_album_async,
@@ -178,12 +200,11 @@ async def download_album_async(jm_album_id,
178
200
  dler.add_features(extra, 'download_album')
179
201
  album = await dler.download_album(jm_album_id)
180
202
 
181
- if callback is not None:
182
- callback(album, dler)
203
+ await _invoke_async_callback(callback, album, dler)
183
204
  if check_exception:
184
205
  dler.raise_if_has_exception()
185
206
 
186
- return album, dler
207
+ return DownloadResult(album, dler)
187
208
 
188
209
 
189
210
  async def download_photo_async(jm_photo_id,
@@ -195,6 +216,8 @@ async def download_photo_async(jm_photo_id,
195
216
  ):
196
217
  """
197
218
  异步下载一个章节(photo)。
219
+ callback 支持同步函数和异步函数。
220
+ 返回的 downloader 已关闭网络和线程池资源,仅用于读取下载结果。
198
221
  """
199
222
  if not isinstance(jm_photo_id, (str, int)):
200
223
  return await download_batch_async(download_photo_async,
@@ -208,12 +231,11 @@ async def download_photo_async(jm_photo_id,
208
231
  dler.add_features(extra, 'download_photo')
209
232
  photo = await dler.download_photo(jm_photo_id)
210
233
 
211
- if callback is not None:
212
- callback(photo, dler)
234
+ await _invoke_async_callback(callback, photo, dler)
213
235
  if check_exception:
214
236
  dler.raise_if_has_exception()
215
237
 
216
- return photo, dler
238
+ return DownloadResult(photo, dler)
217
239
 
218
240
 
219
241
  async def download_batch_async(download_api,
@@ -221,10 +243,11 @@ async def download_batch_async(download_api,
221
243
  option=None,
222
244
  downloader=None,
223
245
  **kwargs,
224
- ):
246
+ ) -> BatchResult:
225
247
  """
226
248
  异步批量下载 album / photo。
227
249
  - 容错机制:单个 album/photo 失败不会中止整批,也不会丢失其它已完成结果。
250
+ - 返回 BatchResult(set),失败项收集在 result.failed 中。
228
251
  """
229
252
  if option is None:
230
253
  option = JmModuleConfig.option_class().default()
@@ -236,12 +259,13 @@ async def download_batch_async(download_api,
236
259
  return_exceptions=True,
237
260
  )
238
261
 
239
- # 失败不抛出,但要记录,便于排查
240
- result_set = set()
262
+ # 失败不抛出,但要记录到 result.failed,便于调用者排查
263
+ result = BatchResult()
241
264
  for jmid, r in zip(jm_ids, results):
242
265
  if isinstance(r, BaseException):
243
266
  jm_log('async.batch.failed', f'批量下载失败: [{jmid}], 异常: [{r}]', r)
267
+ result.failed[str(jmid)] = r
244
268
  else:
245
- result_set.add(r)
269
+ result.add(r)
246
270
 
247
- return result_set
271
+ return result
@@ -7,6 +7,7 @@ from __future__ import annotations
7
7
 
8
8
  import asyncio
9
9
  import json
10
+ from typing import Sequence
10
11
  from urllib.parse import urlencode
11
12
 
12
13
  from curl_cffi.requests import AsyncSession
@@ -51,13 +52,17 @@ class AsyncJmApiClient(AsyncJmcomicClient):
51
52
  _SENTINEL = object()
52
53
 
53
54
  # 类级别初始化标记与锁,防止并发更新域名
54
- _has_setup_domain_and_cookies = False
55
+ _has_setup_domain = False
55
56
  _setup_lock = asyncio.Lock()
56
57
 
57
- def __init__(self, option: JmOption, max_clients=None, **kwargs):
58
+ def __init__(self, option: JmOption, max_clients=None, domain_list=None, **kwargs):
59
+ if 'domain_retry_strategy' in kwargs:
60
+ raise TypeError('Async client does not support domain_retry_strategy')
61
+
58
62
  self.option = option
59
- self._domain_list = self._resolve_domain_list()
60
- self._retry_times = option.client.get('retry_times', 5) or 5
63
+ self._domain_list = self._resolve_domain_list(domain_list)
64
+ retry_times = option.client.get('retry_times')
65
+ self._retry_times = retry_times if retry_times is not None else 5
61
66
  self._timeout = option.client.get('timeout', 30) or 30
62
67
  # AsyncSession 句柄池大小:优先用调用方(下载器)传入的实际图片并发,
63
68
  # 否则回退到 option 配置;避免因默认限制导致真实并发被隐式压低。
@@ -83,22 +88,41 @@ class AsyncJmApiClient(AsyncJmcomicClient):
83
88
  # 域名管理
84
89
  # ======================================================================
85
90
 
86
- def _resolve_domain_list(self) -> list[str]:
91
+ @staticmethod
92
+ def _normalize_domain_list(domain_list) -> list[str]:
93
+ if isinstance(domain_list, str):
94
+ return [domain.strip() for domain in domain_list.splitlines() if domain.strip()]
95
+
96
+ if isinstance(domain_list, Sequence):
97
+ result = []
98
+ for domain in domain_list:
99
+ if not isinstance(domain, str):
100
+ raise TypeError(f'domain must be str, got {type(domain)}')
101
+ domain = domain.strip()
102
+ if domain:
103
+ result.append(domain)
104
+ return result
105
+
106
+ raise TypeError('domain_list must be str, Sequence[str], or None')
107
+
108
+ def _resolve_domain_list(self, domain_list=None) -> list[str]:
87
109
  """解析并返回可用的 API 域名列表"""
88
- updated = JmModuleConfig.DOMAIN_API_UPDATED_LIST
89
- if updated:
90
- return list(updated)
110
+ if domain_list is not None:
111
+ resolved = self._normalize_domain_list(domain_list)
112
+ if resolved:
113
+ return resolved
114
+
91
115
  domain = self.option.client.domain
92
116
  if hasattr(domain, 'get'):
93
117
  domain_list = domain.get('api', [])
94
- elif isinstance(domain, list):
95
- domain_list = domain
96
- elif isinstance(domain, str):
97
- domain_list = [d.strip() for d in domain.split('\n') if d.strip()]
98
118
  else:
99
- domain_list = []
100
- if domain_list:
101
- return domain_list
119
+ domain_list = domain
120
+
121
+ if domain_list is not None:
122
+ resolved = self._normalize_domain_list(domain_list)
123
+ if resolved:
124
+ return resolved
125
+
102
126
  return list(JmModuleConfig.DOMAIN_API_LIST)
103
127
 
104
128
  def get_domain_list(self) -> list[str]:
@@ -107,6 +131,20 @@ class AsyncJmApiClient(AsyncJmcomicClient):
107
131
  def set_domain_list(self, domain_list: list[str]):
108
132
  self._domain_list = domain_list
109
133
 
134
+ def update_old_api_domain(self, new_server_list: list[str]):
135
+ if not new_server_list:
136
+ return
137
+
138
+ if sorted(self._domain_list) != sorted(JmModuleConfig.DOMAIN_API_LIST):
139
+ return
140
+
141
+ old_server_list = self._domain_list
142
+ self._domain_list = list(new_server_list)
143
+ jm_log(
144
+ 'api.update_domain.replace',
145
+ f'替换异步客户端的内置API域名:(old){old_server_list} ---→ (new){self._domain_list}',
146
+ )
147
+
110
148
  # ======================================================================
111
149
  # 缓存
112
150
  # ======================================================================
@@ -658,8 +696,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
658
696
  return
659
697
 
660
698
  if JmModuleConfig.DOMAIN_API_UPDATED_LIST is not None:
661
- if JmModuleConfig.DOMAIN_API_UPDATED_LIST:
662
- self._domain_list = list(JmModuleConfig.DOMAIN_API_UPDATED_LIST)
699
+ self.update_old_api_domain(JmModuleConfig.DOMAIN_API_UPDATED_LIST)
663
700
  return
664
701
 
665
702
  # 尝试从域名服务器获取最新域名
@@ -682,8 +719,7 @@ class AsyncJmApiClient(AsyncJmcomicClient):
682
719
  jm_log('api.update_domain.success',
683
720
  f'获取到最新的API域名: {new_server_list}')
684
721
  JmModuleConfig.DOMAIN_API_UPDATED_LIST = new_server_list
685
- if sorted(self._domain_list) == sorted(JmModuleConfig.DOMAIN_API_LIST):
686
- self._domain_list = new_server_list
722
+ self.update_old_api_domain(new_server_list)
687
723
  return
688
724
  except Exception as e:
689
725
  jm_log('api.update_domain.error', f'通过[{url}]自动更新API域名失败: {e}')
@@ -707,20 +743,22 @@ class AsyncJmApiClient(AsyncJmcomicClient):
707
743
 
708
744
  cls = self.__class__
709
745
  async with cls._setup_lock:
710
- if not cls._has_setup_domain_and_cookies:
746
+ if self._has_setup:
747
+ return
748
+
749
+ if not cls._has_setup_domain:
711
750
  await self.auto_update_domain()
712
- if JmModuleConfig.FLAG_API_CLIENT_REQUIRE_COOKIES:
713
- await self.ensure_have_cookies()
714
- cls._has_setup_domain_and_cookies = True
751
+ cls._has_setup_domain = True
715
752
  else:
716
- # 即使已经初始化过域名和 cookie,也需要将已保存的全局 DOMAIN 和 COOKIES 赋值到当前 client
717
- if JmModuleConfig.DOMAIN_API_UPDATED_LIST:
718
- self._domain_list = list(JmModuleConfig.DOMAIN_API_UPDATED_LIST)
719
- if JmModuleConfig.FLAG_API_CLIENT_REQUIRE_COOKIES and JmModuleConfig.APP_COOKIES:
720
- # noinspection PyUnresolvedReferences
721
- self._session.cookies.update(JmModuleConfig.APP_COOKIES)
722
-
723
- self._has_setup = True
753
+ # 即使已经初始化过域名,也需要将已保存的全局 DOMAIN 赋值到当前 client
754
+ if JmModuleConfig.FLAG_API_CLIENT_AUTO_UPDATE_DOMAIN:
755
+ self.update_old_api_domain(JmModuleConfig.DOMAIN_API_UPDATED_LIST)
756
+
757
+ # Cookie 属于 session 状态,每个 client 都需要独立确认。
758
+ if JmModuleConfig.FLAG_API_CLIENT_REQUIRE_COOKIES:
759
+ await self.ensure_have_cookies()
760
+
761
+ self._has_setup = True
724
762
 
725
763
  # ======================================================================
726
764
  # 生命周期
@@ -257,7 +257,18 @@ class JmAsyncDownloader(BaseDownloader):
257
257
  async def __aenter__(self):
258
258
  # 创建并独占一个 async client(含 AsyncSession)。
259
259
  self.client = self.option.new_jm_async_client(max_clients=self._image_concurrency)
260
- await self.client.setup()
260
+ try:
261
+ await self.client.setup()
262
+ except BaseException:
263
+ try:
264
+ await self.client.close()
265
+ except BaseException as cleanup_error:
266
+ jm_log('dler.cleanup.exception',
267
+ f'初始化失败后的资源清理也发生异常: {cleanup_error}', cleanup_error)
268
+ finally:
269
+ self.client = None
270
+ self.shutdown()
271
+ raise
261
272
  return self
262
273
 
263
274
  async def __aexit__(self, exc_type, exc_val, exc_tb):
@@ -514,6 +514,7 @@ class JmcomicClient(
514
514
  return JmModuleConfig.get_html_domain_all(self.get_root_postman())
515
515
 
516
516
  def get_html_domain_all_via_github(self):
517
+ """已废弃,请使用 get_html_domain_all。"""
517
518
  return JmModuleConfig.get_html_domain_all_via_github(self.get_root_postman())
518
519
 
519
520
  # noinspection PyMethodMayBeStatic
@@ -815,6 +816,30 @@ class AsyncJmcomicClient:
815
816
  ) -> JmCategoryPage:
816
817
  raise NotImplementedError
817
818
 
819
+ async def categories_filter_gen(self,
820
+ page: int = 1,
821
+ time: str = JmMagicConstants.TIME_ALL,
822
+ category: str = JmMagicConstants.CATEGORY_ALL,
823
+ order_by: str = JmMagicConstants.ORDER_BY_LATEST,
824
+ sub_category: Optional[str] = None,
825
+ ):
826
+ """异步分类结果生成器,支持通过 asend 动态更新分页参数。"""
827
+ params = {
828
+ 'time': time,
829
+ 'category': category,
830
+ 'order_by': order_by,
831
+ 'sub_category': sub_category,
832
+ }
833
+
834
+ aiter = self.do_page_iter(params, page, self.categories_filter)
835
+ value = None
836
+ while True:
837
+ try:
838
+ page_content = await aiter.asend(value)
839
+ value = yield page_content
840
+ except StopAsyncIteration:
841
+ break
842
+
818
843
  async def month_ranking(self,
819
844
  page: int = 1,
820
845
  category: str = JmMagicConstants.CATEGORY_ALL,
@@ -103,7 +103,7 @@ class JmMagicConstants:
103
103
  APP_TOKEN_SECRET_2 = '18comicAPPContent'
104
104
  APP_DATA_SECRET = '185Hcomic3PAPP7R'
105
105
  API_DOMAIN_SERVER_SECRET = 'diosfjckwpqpdfjkvnqQjsik'
106
- APP_VERSION = '2.0.26'
106
+ APP_VERSION = '2.0.28'
107
107
 
108
108
 
109
109
  # 模块级别共用配置
@@ -154,10 +154,10 @@ class JmModuleConfig:
154
154
 
155
155
  # 移动端API域名
156
156
  DOMAIN_API_LIST = shuffled('''
157
- www.cdnaspa.club
158
- www.cdnaspa.vip
159
- www.cdnplaystation6.cc
160
- www.cdnplaystation6.vip
157
+ www.cdnhjk.net
158
+ www.cdngwc.cc
159
+ www.cdngwc.net
160
+ www.cdngwc.club
161
161
  ''')
162
162
 
163
163
  DOMAIN_API_UPDATED_LIST = None
@@ -370,37 +370,21 @@ class JmModuleConfig:
370
370
  @classmethod
371
371
  def get_html_domain_all_via_github(cls,
372
372
  postman=None,
373
- template='https://jmcmomic.github.io/go/{}.html',
374
- index_range=(300, 309)
373
+ *deprecated_args,
374
+ **deprecated_kwargs,
375
375
  ):
376
376
  """
377
- 通过禁漫官方的github号的repo获取最新的禁漫域名
378
- https://github.com/jmcmomic/jmcmomic.github.io
377
+ 已废弃:原 GitHub 仓库不再提供禁漫域名。
378
+ 为保持兼容,当前转发到 get_html_domain_all;该方法将在未来版本移除。
379
379
  """
380
- postman = postman or cls.new_postman(headers={
381
- 'authority': 'github.com',
382
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 '
383
- 'Safari/537.36'
384
- })
385
- domain_set = set()
386
-
387
- def fetch_domain(url):
388
- resp = postman.get(url, allow_redirects=False)
389
- text = resp.text
390
- from .jm_toolkit import JmcomicText
391
- for domain in JmcomicText.analyse_jm_pub_html(text):
392
- if domain.startswith('jm365'):
393
- continue
394
- domain_set.add(domain)
395
-
396
- from common import multi_thread_launcher
397
-
398
- multi_thread_launcher(
399
- iter_objs=[template.format(i) for i in range(*index_range)],
400
- apply_each_obj_func=fetch_domain,
380
+ import warnings
381
+ warnings.warn(
382
+ 'get_html_domain_all_via_github is deprecated because the GitHub repository no longer provides '
383
+ 'JMComic domains; use get_html_domain_all instead.',
384
+ DeprecationWarning,
385
+ stacklevel=2,
401
386
  )
402
-
403
- return domain_set
387
+ return cls.get_html_domain_all(postman)
404
388
 
405
389
  @classmethod
406
390
  def new_html_headers(cls, domain='18comic.vip'):
@@ -1,3 +1,5 @@
1
+ from typing import NamedTuple
2
+
1
3
  from .jm_option import *
2
4
 
3
5
 
@@ -240,6 +242,38 @@ class BaseDownloader(DownloadCallback):
240
242
  )
241
243
 
242
244
 
245
+ class DownloadResult(NamedTuple):
246
+ """单个下载结果。
247
+
248
+ 支持解包:album, dler = download_album(id)
249
+ 也支持属性访问:result.detail, result.downloader
250
+ NamedTuple 是 tuple 子类,isinstance(result, tuple) 为 True。
251
+ """
252
+ detail: DetailEntity
253
+ downloader: BaseDownloader
254
+
255
+
256
+ class BatchResult(set):
257
+ """批量下载结果集。
258
+
259
+ 继承 set,完全兼容旧写法 for album, dler in result。
260
+ 新增 .failed 属性,记录失败的 jm_id 和对应异常。
261
+ """
262
+
263
+ def __init__(self):
264
+ super().__init__()
265
+ self.failed: Dict[str, BaseException] = {}
266
+
267
+ @property
268
+ def all_succeeded(self) -> bool:
269
+ return len(self.failed) == 0
270
+
271
+ @property
272
+ def total(self) -> int:
273
+ """预期总数(成功 + 失败)"""
274
+ return len(self) + len(self.failed)
275
+
276
+
243
277
  class JmDownloader(BaseDownloader):
244
278
  """
245
279
  JmDownloader = BaseDownloader + 同步 I/O 调度逻辑
@@ -1,3 +1,4 @@
1
+ from collections.abc import Sequence
1
2
  from functools import lru_cache
2
3
 
3
4
  from common import *
@@ -37,7 +38,7 @@ class JmBaseEntity:
37
38
  return False
38
39
 
39
40
 
40
- class IndexedEntity:
41
+ class IndexedEntity(Sequence):
41
42
  def getindex(self, index: int):
42
43
  raise NotImplementedError
43
44
 
@@ -46,12 +47,14 @@ class IndexedEntity:
46
47
 
47
48
  def __getitem__(self, item) -> Any:
48
49
  if isinstance(item, slice):
49
- start = item.start or 0
50
- stop = item.stop or len(self)
51
- step = item.step or 1
50
+ start, stop, step = item.indices(len(self))
52
51
  return [self.getindex(index) for index in range(start, stop, step)]
53
52
 
54
53
  elif isinstance(item, int):
54
+ if item < 0:
55
+ item += len(self)
56
+ if item < 0 or item >= len(self):
57
+ raise IndexError(f"index {item} out of range")
55
58
  return self.getindex(item)
56
59
 
57
60
  else:
@@ -1,4 +1,5 @@
1
1
  from .jm_client_impl import *
2
+ from typing import Optional, Sequence, Union
2
3
 
3
4
 
4
5
  class CacheRegistry:
@@ -594,7 +595,11 @@ class JmOption:
594
595
  from .api import download_photo
595
596
  return download_photo(photo_id, self, *args, **kwargs)
596
597
 
597
- def new_jm_async_client(self, cache=None, **kwargs) -> AsyncJmcomicClient:
598
+ def new_jm_async_client(self,
599
+ cache=None,
600
+ domain_list: Optional[Union[str, Sequence[str]]] = None,
601
+ **kwargs,
602
+ ) -> AsyncJmcomicClient:
598
603
  """
599
604
  通过 Option 配置创建异步客户端。
600
605
  从 REGISTRY_ASYNC_CLIENT 注册表查找实现类(配置项: client.async_impl),
@@ -603,9 +608,15 @@ class JmOption:
603
608
  缓存:与同步版本 new_jm_client 相同,依据 client.cache 配置决定是否启用缓存
604
609
  (默认 None 即为不缓存),并通过 CacheRegistry.enable_client_cache_on_condition 下发配置。
605
610
  """
611
+ if 'domain_retry_strategy' in kwargs:
612
+ raise TypeError('Async client does not support domain_retry_strategy')
613
+
606
614
  async_impl = self.client.get('async_impl', 'async_api') or 'async_api'
607
615
  clazz = JmModuleConfig.async_client_impl_class(async_impl)
608
- client = clazz(self, **kwargs)
616
+ if domain_list is None:
617
+ client = clazz(self, **kwargs)
618
+ else:
619
+ client = clazz(self, domain_list=domain_list, **kwargs)
609
620
 
610
621
  # 启用缓存(与同步版本保持一致):默认不缓存,由 client.cache 配置决定
611
622
  cache = cache if cache is not None else self.client.cache
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jmcomic
3
- Version: 2.7.0
3
+ Version: 2.7.2
4
4
  Summary: Python API For JMComic (禁漫天堂)
5
5
  Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
6
6
  Author: hect0x7
@@ -94,7 +94,7 @@ Dynamic: requires-python
94
94
  >
95
95
 
96
96
 
97
- ![introduction.jpg](./assets/docs/sources/images/introduction.jpg)
97
+ ![introduction.jpg](https://raw.githubusercontent.com/hect0x7/hect0x7/master/images/jmcomic-intro-main.png)
98
98
 
99
99
 
100
100
  ## 项目介绍
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes