jmcomic 2.1.16__py3-none-any.whl → 2.1.17__py3-none-any.whl

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/__init__.py CHANGED
@@ -2,6 +2,6 @@
2
2
  # 被依赖方 <--- 使用方
3
3
  # config <--- entity <--- toolkit <--- client <--- option <--- downloader
4
4
 
5
- __version__ = '2.1.16'
5
+ __version__ = '2.1.17'
6
6
 
7
7
  from .api import *
jmcomic/jm_client_impl.py CHANGED
@@ -143,7 +143,7 @@ class AbstractJmClient(
143
143
  def fallback(self, request, url, domain_index, retry_count, **kwargs):
144
144
  msg = f"请求重试全部失败: [{url}], {self.domain_list}"
145
145
  jm_debug('req.fallback', msg)
146
- raise AssertionError(msg)
146
+ raise JmModuleConfig.exception(msg)
147
147
 
148
148
 
149
149
  # 基于网页实现的JmClient
@@ -216,7 +216,7 @@ class JmHtmlClient(AbstractJmClient):
216
216
  )
217
217
 
218
218
  if resp.status_code != 301:
219
- raise AssertionError(f'登录失败,状态码为{resp.status_code}')
219
+ raise JmModuleConfig.exception(f'登录失败,状态码为{resp.status_code}')
220
220
 
221
221
  if refresh_client_cookies is True:
222
222
  self['cookies'] = resp.cookies
@@ -251,7 +251,7 @@ class JmHtmlClient(AbstractJmClient):
251
251
  + (f"响应文本=[{resp.text}]" if len(resp.text) < 200 else
252
252
  f'响应文本过长(len={len(resp.text)}),不打印'
253
253
  )
254
- raise AssertionError(msg)
254
+ raise JmModuleConfig.exception(msg)
255
255
 
256
256
  def get_jm_image(self, img_url) -> JmImageResp:
257
257
 
@@ -23,13 +23,13 @@ class JmResp(CommonResp):
23
23
  class JmImageResp(JmResp):
24
24
 
25
25
  def json(self, **kwargs) -> Dict:
26
- raise AssertionError
26
+ raise NotImplementedError
27
27
 
28
28
  def require_success(self):
29
29
  if self.is_success:
30
30
  return
31
31
 
32
- raise AssertionError(self.get_error_msg())
32
+ raise JmModuleConfig.exception(self.get_error_msg())
33
33
 
34
34
  def get_error_msg(self):
35
35
  msg = f'禁漫图片获取失败: [{self.url}]'
@@ -68,7 +68,7 @@ class JmApiResp(JmResp):
68
68
  @classmethod
69
69
  def wrap(cls, resp, key_ts):
70
70
  if isinstance(resp, JmApiResp):
71
- raise AssertionError('重复包装')
71
+ raise JmModuleConfig.exception('重复包装')
72
72
 
73
73
  return cls(resp, key_ts)
74
74
 
jmcomic/jm_config.py CHANGED
@@ -18,7 +18,11 @@ def default_postman_constructor(session, **kwargs):
18
18
 
19
19
 
20
20
  def default_raise_regex_error(msg, *_args, **_kwargs):
21
- raise AssertionError(msg)
21
+ raise JmModuleConfig.exception(msg)
22
+
23
+
24
+ class JmcomicException(Exception):
25
+ pass
22
26
 
23
27
 
24
28
  class JmModuleConfig:
@@ -60,7 +64,9 @@ class JmModuleConfig:
60
64
  CLASS_OPTION = None
61
65
  CLASS_ALBUM = None
62
66
  CLASS_PHOTO = None
67
+ CLASS_IMAGE = None
63
68
  CLASS_CLIENT_IMPL = {}
69
+ CLASS_EXCEPTION = None
64
70
 
65
71
  # 执行debug的函数
66
72
  debug_executor = default_jm_debug
@@ -104,6 +110,14 @@ class JmModuleConfig:
104
110
  from .jm_entity import JmPhotoDetail
105
111
  return JmPhotoDetail
106
112
 
113
+ @classmethod
114
+ def image_class(cls):
115
+ if cls.CLASS_IMAGE is not None:
116
+ return cls.CLASS_IMAGE
117
+
118
+ from .jm_entity import JmImageDetail
119
+ return JmImageDetail
120
+
107
121
  @classmethod
108
122
  def client_impl_class(cls, client_key: str):
109
123
  client_impl_dict = cls.CLASS_CLIENT_IMPL
@@ -114,6 +128,13 @@ class JmModuleConfig:
114
128
 
115
129
  return impl_class
116
130
 
131
+ @classmethod
132
+ def exception(cls, msg: str):
133
+ if cls.CLASS_EXCEPTION is not None:
134
+ return cls.CLASS_EXCEPTION(msg)
135
+
136
+ return JmcomicException(msg)
137
+
117
138
  @classmethod
118
139
  @field_cache("DOMAIN")
119
140
  def domain(cls, postman=None):
@@ -185,7 +206,7 @@ class JmModuleConfig:
185
206
 
186
207
  resp = postman.get(cls.JM_PUB_URL)
187
208
  if resp.status_code != 200:
188
- raise AssertionError(resp.text)
209
+ raise JmModuleConfig.exception(resp.text)
189
210
 
190
211
  from .jm_toolkit import JmcomicText
191
212
  domain_list = JmcomicText.analyse_jm_pub_html(resp.text)
jmcomic/jm_entity.py CHANGED
@@ -241,11 +241,11 @@ class JmPhotoDetail(DetailEntity):
241
241
  # 校验参数
242
242
  length = len(self.page_arr)
243
243
  if index >= length:
244
- raise AssertionError(f'创建JmImageDetail失败,{index} >= {length}')
244
+ raise JmModuleConfig.exception(f'创建JmImageDetail失败,{index} >= {length}')
245
245
 
246
246
  data_original = self.get_img_data_original(self.page_arr[index])
247
247
 
248
- return JmImageDetail.of(
248
+ return JmModuleConfig.image_class().of(
249
249
  self.photo_id,
250
250
  self.scramble_id,
251
251
  data_original,
@@ -262,7 +262,7 @@ class JmPhotoDetail(DetailEntity):
262
262
  """
263
263
  data_original_domain = self.data_original_domain
264
264
  if data_original_domain is None:
265
- raise AssertionError(f'图片域名为空: {self.__dict__}')
265
+ raise JmModuleConfig.exception(f'图片域名为空: {self.__dict__}')
266
266
 
267
267
  return f'https://{data_original_domain}/media/photos/{self.photo_id}/{img_name}'
268
268
 
@@ -330,13 +330,13 @@ class JmAlbumDetail(DetailEntity):
330
330
  length = len(self.episode_list)
331
331
 
332
332
  if index >= length:
333
- raise AssertionError(f'创建JmPhotoDetail失败,{index} >= {length}')
333
+ raise JmModuleConfig.exception(f'创建JmPhotoDetail失败,{index} >= {length}')
334
334
 
335
335
  # episode_info: ('212214', '81', '94 突然打來', '2020-08-29')
336
336
  episode_info: tuple = self.episode_list[index]
337
337
  photo_id, photo_index, photo_title, photo_pub_date = episode_info
338
338
 
339
- photo = JmPhotoDetail(
339
+ photo = JmModuleConfig.photo_class()(
340
340
  photo_id=photo_id,
341
341
  scramble_id=self.scramble_id,
342
342
  title=photo_title,
jmcomic/jm_option.py CHANGED
@@ -10,7 +10,8 @@ class DirRule:
10
10
  # 根目录 / Photo-序号&标题 /
11
11
  'Bd_Pindextitle',
12
12
  # 根目录 / Photo-自定义类属性 /
13
- 'Bd_Aauthor_Atitle_Pcustomfield', # 使用自定义类属性前,需替换 JmcomicText的 PhotoClass / AlbumClass
13
+ 'Bd_Aauthor_Atitle_Pcustomfield',
14
+ # 需要替换JmModuleConfig.CLASS_ALBUM / CLASS_PHOTO才能让自定义属性生效
14
15
  ]
15
16
 
16
17
  RuleFunc = Callable[[Union[JmAlbumDetail, JmPhotoDetail, None]], str]
@@ -45,8 +46,10 @@ class DirRule:
45
46
  path_ls.append(str(ret))
46
47
  except BaseException as e:
47
48
  # noinspection PyUnboundLocalVariable
48
- raise AssertionError(f'路径规则"{self.rule_dsl}"的第{i + 1}个解析出错: {e},'
49
- f'param is {param}')
49
+ raise JmModuleConfig.exception(
50
+ f'路径规则"{self.rule_dsl}"的第{i + 1}个解析出错: {e},'
51
+ f'param is {param}'
52
+ )
50
53
 
51
54
  return fix_filepath('/'.join(path_ls), is_dir=True)
52
55
 
@@ -214,7 +217,7 @@ class JmOption:
214
217
  filepath = self.filepath
215
218
 
216
219
  if filepath is None:
217
- raise AssertionError("未指定JmOption的保存路径")
220
+ raise JmModuleConfig.exception("未指定JmOption的保存路径")
218
221
 
219
222
  PackerUtil.pack(self.deconstruct(), filepath)
220
223
 
jmcomic/jm_toolkit.py CHANGED
@@ -52,7 +52,7 @@ class JmcomicText:
52
52
  return str(text)
53
53
 
54
54
  if not isinstance(text, str):
55
- raise AssertionError(f"无法解析jm车号, 参数类型为: {type(text)}")
55
+ raise JmModuleConfig.exception(f"无法解析jm车号, 参数类型为: {type(text)}")
56
56
 
57
57
  # 43210
58
58
  if text.isdigit():
@@ -60,7 +60,7 @@ class JmcomicText:
60
60
 
61
61
  # Jm43210
62
62
  if len(text) <= 2:
63
- raise AssertionError(f"无法解析jm车号, 文本为: {text}")
63
+ raise JmModuleConfig.exception(f"无法解析jm车号, 文本为: {text}")
64
64
 
65
65
  # text: JM12341
66
66
  c0 = text[0]
@@ -72,7 +72,7 @@ class JmcomicText:
72
72
  # https://xxx/photo/412038
73
73
  match = cls.pattern_jm_pa_id.search(text)
74
74
  if match is None:
75
- raise AssertionError(f"无法解析jm车号, 文本为: {text}")
75
+ raise JmModuleConfig.exception(f"无法解析jm车号, 文本为: {text}")
76
76
  return match[2]
77
77
 
78
78
  @classmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jmcomic
3
- Version: 2.1.16
3
+ Version: 2.1.17
4
4
  Summary: Python API For JMComic (禁漫天堂)
5
5
  Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
6
6
  Author: hect0x7
@@ -0,0 +1,14 @@
1
+ jmcomic/__init__.py,sha256=P841NJsb9rk_BcH56LkydBcqTWqLJ_2U5Ruo5tCqd2s,176
2
+ jmcomic/api.py,sha256=s1LTgpKQh5hMnl3Im6qD5nvrnusf6NHawzvJKbZxwCo,1864
3
+ jmcomic/jm_client_impl.py,sha256=CxuJEQnF9b_kfAkHVJZByn6JdxOP-noiflm67sjwCtw,14101
4
+ jmcomic/jm_client_interface.py,sha256=OhS-pC2FXQT4vuu2WejypEGns2fbL0yD8ZEItAvSLE8,8073
5
+ jmcomic/jm_config.py,sha256=g2BXvXpYIEHewaMmh4WeHc8jz3kCJFOijls2bfpgdrA,8086
6
+ jmcomic/jm_downloader.py,sha256=NrDp8q7l1-FChAsEUOnWp9Vcx-C3xn5R2Cq6kG4s2nc,5910
7
+ jmcomic/jm_entity.py,sha256=VEw4vCpsmzCJqlOuzLz7O9aeHIuGpwCLX10yzoX4ZIc,12908
8
+ jmcomic/jm_option.py,sha256=X5fOCFpk4h7wQi5pPBJUzhsEMOKgsIRiZH4cNb7gCR8,9494
9
+ jmcomic/jm_toolkit.py,sha256=p0Z6WNAwil-F9S3BRYRnPA-b8uR9a6TA9yhMWATv2KY,12053
10
+ jmcomic-2.1.17.dist-info/LICENSE,sha256=kz4coTxZxuGxisK3W00tjK57Zh3RcMGq-EnbXrK7-xA,1064
11
+ jmcomic-2.1.17.dist-info/METADATA,sha256=y2hfchFCFgIU2DzvNYd_sWUwRLgUikGbKfSkDSrX5rc,3922
12
+ jmcomic-2.1.17.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
13
+ jmcomic-2.1.17.dist-info/top_level.txt,sha256=puvVMFYJqIbd6NOTMEvOyugMTT8woBfSQyxEBan3zY4,8
14
+ jmcomic-2.1.17.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- jmcomic/__init__.py,sha256=JOMo1Tks6kqAWDXEs819OP6y6uG7ZSHyCBxg0xxCVKI,176
2
- jmcomic/api.py,sha256=s1LTgpKQh5hMnl3Im6qD5nvrnusf6NHawzvJKbZxwCo,1864
3
- jmcomic/jm_client_impl.py,sha256=t75QYCXwwpTAt6oSWaGACovfkF4rv5X8yGqT1TqFUAs,14071
4
- jmcomic/jm_client_interface.py,sha256=5cbxTVxkEsTU7O11FN2J34P67_eRbfiFqSKl8wZLim8,8048
5
- jmcomic/jm_config.py,sha256=j8bRPxKuglAgec6Sh6rPneiyfSgZi3R0PkC8t-m1lxU,7598
6
- jmcomic/jm_downloader.py,sha256=NrDp8q7l1-FChAsEUOnWp9Vcx-C3xn5R2Cq6kG4s2nc,5910
7
- jmcomic/jm_entity.py,sha256=Xh7Yl-jOro2oUtkrAcbb6S00MCttveZXhn4ZUs-nDKU,12848
8
- jmcomic/jm_option.py,sha256=1U3_Yubl7uRF31e6HAKXpzg2apCUS2tk2Wm3w7s2pHM,9442
9
- jmcomic/jm_toolkit.py,sha256=kYYK9cX2wzAL0H9wkACYqKeEVwlvryOGF_rjk2xgfPM,12023
10
- jmcomic-2.1.16.dist-info/LICENSE,sha256=kz4coTxZxuGxisK3W00tjK57Zh3RcMGq-EnbXrK7-xA,1064
11
- jmcomic-2.1.16.dist-info/METADATA,sha256=ualJ0rF867PXe8KDy6_Z55njr2PowL2BUwZ43Bel_wg,3922
12
- jmcomic-2.1.16.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
13
- jmcomic-2.1.16.dist-info/top_level.txt,sha256=puvVMFYJqIbd6NOTMEvOyugMTT8woBfSQyxEBan3zY4,8
14
- jmcomic-2.1.16.dist-info/RECORD,,