jmcomic 2.3.6__py3-none-any.whl → 2.3.8__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 +22 -1
- jmcomic/jm_client_impl.py +2 -7
- jmcomic/jm_client_interface.py +8 -1
- jmcomic/jm_config.py +12 -11
- jmcomic/jm_entity.py +1 -1
- jmcomic/jm_option.py +27 -18
- jmcomic/jm_plugin.py +4 -13
- {jmcomic-2.3.6.dist-info → jmcomic-2.3.8.dist-info}/METADATA +1 -1
- jmcomic-2.3.8.dist-info/RECORD +17 -0
- jmcomic-2.3.6.dist-info/RECORD +0 -17
- {jmcomic-2.3.6.dist-info → jmcomic-2.3.8.dist-info}/LICENSE +0 -0
- {jmcomic-2.3.6.dist-info → jmcomic-2.3.8.dist-info}/WHEEL +0 -0
- {jmcomic-2.3.6.dist-info → jmcomic-2.3.8.dist-info}/entry_points.txt +0 -0
- {jmcomic-2.3.6.dist-info → jmcomic-2.3.8.dist-info}/top_level.txt +0 -0
jmcomic/__init__.py
CHANGED
|
@@ -2,7 +2,28 @@
|
|
|
2
2
|
# 被依赖方 <--- 使用方
|
|
3
3
|
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
|
|
4
4
|
|
|
5
|
-
__version__ = '2.3.
|
|
5
|
+
__version__ = '2.3.8'
|
|
6
6
|
|
|
7
7
|
from .api import *
|
|
8
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
|
+
)
|
jmcomic/jm_client_impl.py
CHANGED
|
@@ -6,7 +6,7 @@ class AbstractJmClient(
|
|
|
6
6
|
JmcomicClient,
|
|
7
7
|
PostmanProxy,
|
|
8
8
|
):
|
|
9
|
-
client_key =
|
|
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('
|
|
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)
|
jmcomic/jm_client_interface.py
CHANGED
|
@@ -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
|
|
jmcomic/jm_config.py
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
jmcomic/jm_entity.py
CHANGED
|
@@ -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不能为空
|
|
87
|
+
ExceptionTool.raises(f'图片的scramble_id不能为空')
|
|
88
88
|
|
|
89
89
|
self.aid: str = str(aid)
|
|
90
90
|
self.scramble_id: str = str(scramble_id)
|
jmcomic/jm_option.py
CHANGED
|
@@ -298,21 +298,27 @@ class JmOption:
|
|
|
298
298
|
"""
|
|
299
299
|
return self.new_jm_client(**kwargs)
|
|
300
300
|
|
|
301
|
-
def new_jm_client(self,
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
#
|
|
306
|
-
|
|
307
|
-
domain_list =
|
|
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
|
-
|
|
310
|
-
|
|
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
|
-
|
|
315
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
333
|
-
fallback_domain_list=
|
|
341
|
+
retry_times,
|
|
342
|
+
fallback_domain_list=decide_domain(),
|
|
334
343
|
)
|
|
335
344
|
|
|
336
345
|
# enable cache
|
|
337
|
-
if
|
|
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.
|
|
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)
|
jmcomic/jm_plugin.py
CHANGED
|
@@ -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 {
|
|
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)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
jmcomic/__init__.py,sha256=YgAlwq0VGqg_usY_Haf_m0JRMrOmpNE0p0r5KCy3Has,878
|
|
2
|
+
jmcomic/api.py,sha256=EIIOvL_n2MWNeUZObIG9dm6Vi03JysOhE-HlKyZlrYw,2460
|
|
3
|
+
jmcomic/cl.py,sha256=ArDxQvt4G2YungPUqYHG5zWkUxQh71nY-T_IS2jzIV8,3489
|
|
4
|
+
jmcomic/jm_client_impl.py,sha256=lzvkR7_IGGUlcL8A4fpa8LmPCbfDfNLXokUaw7qyJ1c,22480
|
|
5
|
+
jmcomic/jm_client_interface.py,sha256=-h6cfRH_1rfVm2Q35GvE3txRJpD4KTLVJbrRlkZGexs,11549
|
|
6
|
+
jmcomic/jm_config.py,sha256=rPxtr9UjqTr2QHYbL6cfkenVCqB2XI5nLFb2zKrur0M,11284
|
|
7
|
+
jmcomic/jm_downloader.py,sha256=iDeSp4NbmSP_7QoB6pguIlRMRt5cYvJOnONvicVvyQU,7125
|
|
8
|
+
jmcomic/jm_entity.py,sha256=kwbSZTuQFzs_IuOexOefEeeOX8F-Ucl0cRCz6R_IPkM,14629
|
|
9
|
+
jmcomic/jm_option.py,sha256=4LFfPgLbBzas5Zyw187Ro87F__k5d5VilvHP0-OTfTQ,15615
|
|
10
|
+
jmcomic/jm_plugin.py,sha256=6vfi6dioDcO-dg0NAY6FA5R8l7WAACBK1TbtV4WCLq8,11443
|
|
11
|
+
jmcomic/jm_toolkit.py,sha256=SFERf87Kmxik24VGPj90ehAYTINKW0qdJajhehhxeYY,20844
|
|
12
|
+
jmcomic-2.3.8.dist-info/LICENSE,sha256=kz4coTxZxuGxisK3W00tjK57Zh3RcMGq-EnbXrK7-xA,1064
|
|
13
|
+
jmcomic-2.3.8.dist-info/METADATA,sha256=TMLtTFhvlHVuOBVCn7vrkYZQ_UCEiF_bJSwayoJzsaI,5583
|
|
14
|
+
jmcomic-2.3.8.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
15
|
+
jmcomic-2.3.8.dist-info/entry_points.txt,sha256=tRbQltaGSBjejI0c9jYt-4SXQMd5nSDHcMvHmuTy4ow,44
|
|
16
|
+
jmcomic-2.3.8.dist-info/top_level.txt,sha256=puvVMFYJqIbd6NOTMEvOyugMTT8woBfSQyxEBan3zY4,8
|
|
17
|
+
jmcomic-2.3.8.dist-info/RECORD,,
|
jmcomic-2.3.6.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
jmcomic/__init__.py,sha256=gOVLCfA_JelAlSuKCKSll1_WgUDjKWH6m65hg_ACITM,200
|
|
2
|
-
jmcomic/api.py,sha256=EIIOvL_n2MWNeUZObIG9dm6Vi03JysOhE-HlKyZlrYw,2460
|
|
3
|
-
jmcomic/cl.py,sha256=ArDxQvt4G2YungPUqYHG5zWkUxQh71nY-T_IS2jzIV8,3489
|
|
4
|
-
jmcomic/jm_client_impl.py,sha256=OKb6NsMNn6PnXEMDzhRVdFDZR9k_JQ0eOlPKPjPjWCY,22604
|
|
5
|
-
jmcomic/jm_client_interface.py,sha256=dAl-_rchCJ5vmAcBE6Z_V7CCDSXAfjPjEicXdf-Y8KY,11235
|
|
6
|
-
jmcomic/jm_config.py,sha256=AF7hKvc4LK_QA5h4yGve-zXeilEdGt6-QIsznn-NIVY,11042
|
|
7
|
-
jmcomic/jm_downloader.py,sha256=iDeSp4NbmSP_7QoB6pguIlRMRt5cYvJOnONvicVvyQU,7125
|
|
8
|
-
jmcomic/jm_entity.py,sha256=iWxsikHxmOgWRKnfuq9mEZEmkv5llpzlKwcfSfkOEpg,14630
|
|
9
|
-
jmcomic/jm_option.py,sha256=lC6sk5gilqxn1pz5-Oo0qnpnLDMjKvhNaqUM6mz0new,15200
|
|
10
|
-
jmcomic/jm_plugin.py,sha256=A55DSBDiLhFDLwqm7OCNw3R7jIIf5lp9sftu-Apsm9I,11691
|
|
11
|
-
jmcomic/jm_toolkit.py,sha256=SFERf87Kmxik24VGPj90ehAYTINKW0qdJajhehhxeYY,20844
|
|
12
|
-
jmcomic-2.3.6.dist-info/LICENSE,sha256=kz4coTxZxuGxisK3W00tjK57Zh3RcMGq-EnbXrK7-xA,1064
|
|
13
|
-
jmcomic-2.3.6.dist-info/METADATA,sha256=zH6fj0mT2rwO7Kh6AvsnPrRUO2aNPNJXR5OI26waHoY,5583
|
|
14
|
-
jmcomic-2.3.6.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
15
|
-
jmcomic-2.3.6.dist-info/entry_points.txt,sha256=tRbQltaGSBjejI0c9jYt-4SXQMd5nSDHcMvHmuTy4ow,44
|
|
16
|
-
jmcomic-2.3.6.dist-info/top_level.txt,sha256=puvVMFYJqIbd6NOTMEvOyugMTT8woBfSQyxEBan3zY4,8
|
|
17
|
-
jmcomic-2.3.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|