jmcomic 2.3.6__tar.gz → 2.3.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jmcomic
3
- Version: 2.3.6
3
+ Version: 2.3.8
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,29 @@
1
+ # 模块依赖关系如下:
2
+ # 被依赖方 <--- 使用方
3
+ # config <--- entity <--- toolkit <--- client <--- option <--- downloader
4
+
5
+ __version__ = '2.3.8'
6
+
7
+ from .api import *
8
+ from .jm_plugin import *
9
+
10
+ # 下面进行注册组件(客户端、插件)
11
+ gb = dict(filter(lambda pair: isinstance(pair[1], type), globals().items()))
12
+
13
+
14
+ def register_jmcomic_component(gb: dict, method, valid_interface: type):
15
+ for v in gb.values():
16
+ if v != valid_interface and issubclass(v, valid_interface):
17
+ method(v)
18
+
19
+
20
+ # 注册客户端
21
+ register_jmcomic_component(gb,
22
+ JmModuleConfig.register_client,
23
+ JmcomicClient,
24
+ )
25
+ # 注册插件
26
+ register_jmcomic_component(gb,
27
+ JmModuleConfig.register_plugin,
28
+ JmOptionPlugin,
29
+ )
@@ -6,7 +6,7 @@ class AbstractJmClient(
6
6
  JmcomicClient,
7
7
  PostmanProxy,
8
8
  ):
9
- client_key = None
9
+ client_key = '__just_for_placeholder_do_not_use_me__'
10
10
  func_to_cache = []
11
11
 
12
12
  def __init__(self,
@@ -324,7 +324,7 @@ class JmHtmlClient(AbstractJmClient):
324
324
  (f' to ({comment_id})' if comment_id is not None else '')
325
325
  )
326
326
 
327
- resp = self.post('https://18comic.vip/ajax/album_comment',
327
+ resp = self.post('/ajax/album_comment',
328
328
  headers=JmModuleConfig.album_comment_headers,
329
329
  data=data,
330
330
  )
@@ -679,8 +679,3 @@ class FutureClientProxy(JmcomicClient):
679
679
  cache_key = f'search_query_{search_query}_page_{page}_main_tag_{main_tag}_order_by_{order_by}_time_{time}'
680
680
  future = self.get_future(cache_key, task=lambda: self.client.search(search_query, page, main_tag, order_by, time))
681
681
  return future.result()
682
-
683
-
684
- JmModuleConfig.register_client(JmHtmlClient)
685
- JmModuleConfig.register_client(JmApiClient)
686
- JmModuleConfig.register_client(FutureClientProxy)
@@ -271,7 +271,14 @@ class JmImageClient:
271
271
  raise NotImplementedError
272
272
 
273
273
  @classmethod
274
- def img_is_not_need_to_decode(cls, data_original: str, _resp):
274
+ def img_is_not_need_to_decode(cls, data_original: str, _resp) -> bool:
275
+ # https://cdn-msp2.18comic.vip/media/photos/498976/00027.gif?v=1697541064
276
+ query_params_index = data_original.find('?')
277
+
278
+ if query_params_index != -1:
279
+ data_original = data_original[:query_params_index]
280
+
281
+ # https://cdn-msp2.18comic.vip/media/photos/498976/00027.gif
275
282
  return data_original.endswith('.gif')
276
283
 
277
284
 
@@ -78,11 +78,11 @@ class JmModuleConfig:
78
78
  CLASS_ALBUM = None
79
79
  CLASS_PHOTO = None
80
80
  CLASS_IMAGE = None
81
- CLASS_CLIENT_IMPL = {}
82
81
  CLASS_EXCEPTION = JmcomicException
83
-
82
+ # 客户端注册表
83
+ REGISTRY_CLIENT = {}
84
84
  # 插件注册表
85
- PLUGIN_REGISTRY = {}
85
+ REGISTRY_PLUGIN = {}
86
86
 
87
87
  # 执行debug的函数
88
88
  debug_executor = default_jm_debug
@@ -140,7 +140,7 @@ class JmModuleConfig:
140
140
 
141
141
  @classmethod
142
142
  def client_impl_class(cls, client_key: str):
143
- clazz_dict = cls.CLASS_CLIENT_IMPL
143
+ clazz_dict = cls.REGISTRY_CLIENT
144
144
 
145
145
  clazz = clazz_dict.get(client_key, None)
146
146
  if clazz is None:
@@ -320,16 +320,17 @@ class JmModuleConfig:
320
320
 
321
321
  @classmethod
322
322
  def register_plugin(cls, plugin_class):
323
- cls.PLUGIN_REGISTRY[plugin_class.plugin_key] = plugin_class
323
+ from .jm_toolkit import ExceptionTool
324
+ ExceptionTool.require_true(getattr(plugin_class, 'plugin_key', None) is not None,
325
+ f'未配置plugin_key, class: {plugin_class}')
326
+ cls.REGISTRY_PLUGIN[plugin_class.plugin_key] = plugin_class
324
327
 
325
328
  @classmethod
326
329
  def register_client(cls, client_class):
327
- client_key = getattr(client_class, 'client_key', None)
328
- if client_key is None:
329
- from .jm_toolkit import ExceptionTool
330
- ExceptionTool.raises(f'未配置client_key, class: {client_class}')
331
-
332
- cls.CLASS_CLIENT_IMPL[client_key] = client_class
330
+ from .jm_toolkit import ExceptionTool
331
+ ExceptionTool.require_true(getattr(client_class, 'client_key', None) is not None,
332
+ f'未配置client_key, class: {client_class}')
333
+ cls.REGISTRY_CLIENT[client_class.client_key] = client_class
333
334
 
334
335
 
335
336
  jm_debug = JmModuleConfig.jm_debug
@@ -84,7 +84,7 @@ class JmImageDetail(JmBaseEntity):
84
84
  ) -> None:
85
85
  if scramble_id is None or (isinstance(scramble_id, str) and scramble_id == ''):
86
86
  from .jm_toolkit import ExceptionTool
87
- ExceptionTool.raises(f'图片的scramble_id不能为空D')
87
+ ExceptionTool.raises(f'图片的scramble_id不能为空')
88
88
 
89
89
  self.aid: str = str(aid)
90
90
  self.scramble_id: str = str(scramble_id)
@@ -298,21 +298,27 @@ class JmOption:
298
298
  """
299
299
  return self.new_jm_client(**kwargs)
300
300
 
301
- def new_jm_client(self, domain_list=None, impl=None, **kwargs) -> JmcomicClient:
302
- postman_conf: dict = self.client.postman.src_dict
303
- impl = impl or self.client.impl
301
+ def new_jm_client(self, domain=None, impl=None, **kwargs) -> JmcomicClient:
302
+ # 所有需要用到的 self.client 配置项如下
303
+ postman_conf: dict = self.client.postman.src_dict # postman dsl 配置
304
+ impl: str = impl or self.client.impl # client_key
305
+ retry_times: int = self.client.retry_times # 重试次数
306
+ cache: str = self.client.cache # 启用缓存
304
307
 
305
- # domain_list
306
- if domain_list is None:
307
- domain_list = self.client.domain
308
+ # domain
309
+ def decide_domain():
310
+ domain_list: Union[List[str], DictModel, dict] = domain if domain is not None \
311
+ else self.client.domain # 域名
308
312
 
309
- domain_list: Union[List[str], DictModel]
310
- if not isinstance(domain_list, list):
311
- domain_list_dict: DictModel = domain_list
312
- domain_list = domain_list_dict.get(impl, [])
313
+ if not isinstance(domain_list, list):
314
+ domain_list = domain_list.get(impl, [])
313
315
 
314
- if len(domain_list) == 0:
315
- domain_list = self.decide_client_domain(impl)
316
+ if len(domain_list) == 0:
317
+ domain_list = self.decide_client_domain(impl)
318
+
319
+ return domain_list
320
+
321
+ domain: List[str] = decide_domain()
316
322
 
317
323
  # support kwargs overwrite meta_data
318
324
  if len(kwargs) != 0:
@@ -321,20 +327,23 @@ class JmOption:
321
327
  # headers
322
328
  meta_data = postman_conf['meta_data']
323
329
  if meta_data['headers'] is None:
324
- meta_data['headers'] = JmModuleConfig.headers(domain_list[0])
330
+ meta_data['headers'] = JmModuleConfig.headers(domain[0])
325
331
 
326
332
  # postman
327
333
  postman = Postmans.create(data=postman_conf)
328
334
 
329
335
  # client
330
- client = JmModuleConfig.client_impl_class(impl)(
336
+ clazz = JmModuleConfig.client_impl_class(impl)
337
+ if clazz == AbstractJmClient or not issubclass(clazz, AbstractJmClient):
338
+ raise NotImplementedError(clazz)
339
+ client = clazz(
331
340
  postman,
332
- self.client.retry_times,
333
- fallback_domain_list=domain_list,
341
+ retry_times,
342
+ fallback_domain_list=decide_domain(),
334
343
  )
335
344
 
336
345
  # enable cache
337
- if self.client.cache is True:
346
+ if cache is True:
338
347
  client.enable_cache()
339
348
 
340
349
  return client
@@ -396,7 +405,7 @@ class JmOption:
396
405
  # 保证 jm_plugin.py 被加载
397
406
  from .jm_plugin import JmOptionPlugin
398
407
 
399
- plugin_registry = JmModuleConfig.PLUGIN_REGISTRY
408
+ plugin_registry = JmModuleConfig.REGISTRY_PLUGIN
400
409
  for pinfo in plugin_list:
401
410
  key, kwargs = pinfo['plugin'], pinfo['kwargs']
402
411
  plugin_class: Optional[Type[JmOptionPlugin]] = plugin_registry.get(key, None)
@@ -1,5 +1,5 @@
1
1
  """
2
- 该文件存放的是option扩展功能类
2
+ 该文件存放的是option插件
3
3
  """
4
4
 
5
5
  from .jm_option import *
@@ -335,9 +335,7 @@ class ClientProxyPlugin(JmOptionPlugin):
335
335
  whitelist=None,
336
336
  **kwargs,
337
337
  ) -> None:
338
- if whitelist is None:
339
- whitelist = set()
340
- else:
338
+ if whitelist is not None:
341
339
  whitelist = set(whitelist)
342
340
 
343
341
  clazz = JmModuleConfig.client_impl_class(proxy_client_key)
@@ -346,17 +344,10 @@ class ClientProxyPlugin(JmOptionPlugin):
346
344
 
347
345
  def hook_new_jm_client(*args, **kwargs):
348
346
  client = new_jm_client(*args, **kwargs)
349
- if client.client_key not in whitelist:
347
+ if whitelist is not None and client.client_key not in whitelist:
350
348
  return client
351
349
 
352
- jm_debug('plugin.client_proxy', f'proxy client {client} with {clazz}')
350
+ jm_debug('plugin.client_proxy', f'proxy client {client} with {proxy_client_key}')
353
351
  return clazz(client, **clazz_init_kwargs)
354
352
 
355
353
  self.option.new_jm_client = hook_new_jm_client
356
-
357
-
358
- JmModuleConfig.register_plugin(JmLoginPlugin)
359
- JmModuleConfig.register_plugin(UsageLogPlugin)
360
- JmModuleConfig.register_plugin(FindUpdatePlugin)
361
- JmModuleConfig.register_plugin(ZipPlugin)
362
- JmModuleConfig.register_plugin(ClientProxyPlugin)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jmcomic
3
- Version: 2.3.6
3
+ Version: 2.3.8
4
4
  Summary: Python API For JMComic (禁漫天堂)
5
5
  Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
6
6
  Author: hect0x7
@@ -1,8 +0,0 @@
1
- # 模块依赖关系如下:
2
- # 被依赖方 <--- 使用方
3
- # config <--- entity <--- toolkit <--- client <--- option <--- downloader
4
-
5
- __version__ = '2.3.6'
6
-
7
- from .api import *
8
- from .jm_plugin import *
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes