Skip to content

Commit a0e8af9

Browse files
authored
v2.3.11: 更新禁漫移动端的域名、headers (#153)
1 parent 4eeee1e commit a0e8af9

File tree

5 files changed

+70
-33
lines changed

5 files changed

+70
-33
lines changed

src/jmcomic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# 被依赖方 <--- 使用方
33
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
44

5-
__version__ = '2.3.10'
5+
__version__ = '2.3.11'
66

77
from .api import *
88
from .jm_plugin import *

src/jmcomic/jm_client_impl.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def fetch_scramble_id(self, photo_id):
484484
"id": photo_id,
485485
"mode": "vertical",
486486
"page": "0",
487-
"app_img_shunt": "NaN",
487+
"app_img_shunt": "1",
488488
}
489489
)
490490

@@ -528,14 +528,7 @@ def get_decode(self, url, **kwargs) -> JmApiResp:
528528
@property
529529
def headers_key_ts(self):
530530
key_ts = time_stamp()
531-
import hashlib
532-
token = hashlib.md5(f"{key_ts}{JmModuleConfig.MAGIC_18COMICAPPCONTENT}".encode()).hexdigest()
533-
return {
534-
"token": token,
535-
"tokenparam": f"{key_ts},1.5.2",
536-
"user-agent": "okhttp/3.12.1",
537-
"accept-encoding": "gzip",
538-
}, key_ts
531+
return JmModuleConfig.new_api_headers(key_ts), key_ts
539532

540533
def debug_topic_request(self):
541534
return 'api'

src/jmcomic/jm_config.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ class JmModuleConfig:
6565
# 图片域名
6666
DOMAIN_API_IMAGE_LIST = [f"cdn-msp.jmapiproxy{i}.cc" for i in range(1, 4)]
6767
# API域名
68-
DOMAIN_API_LIST = [
69-
"www.jmapinode1.cc",
70-
"www.jmapinode2.cc",
71-
"www.jmapinode3.cc",
72-
"www.jmapibranch2.cc",
73-
]
68+
DOMAIN_API_LIST = [f'www.jmapinode{i}.top' for i in range(1, 4)]
7469

7570
# 域名配置 - 网页端
7671
# 无需配置,默认为None,需要的时候会发起请求获得
@@ -199,7 +194,10 @@ def get_html_domain_all(cls, postman=None):
199194
return domain_list
200195

201196
@classmethod
202-
def headers(cls, domain='18comic.vip'):
197+
def new_html_headers(cls, domain='18comic.vip'):
198+
"""
199+
网页端的headers
200+
"""
203201
return {
204202
'authority': domain,
205203
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
@@ -218,6 +216,33 @@ def headers(cls, domain='18comic.vip'):
218216
'Safari/537.36',
219217
}
220218

219+
@classmethod
220+
def new_api_headers(cls, key_ts):
221+
"""
222+
根据key_ts生成移动端的headers
223+
"""
224+
if key_ts is None:
225+
from common import time_stamp
226+
key_ts = time_stamp()
227+
228+
import hashlib
229+
token = hashlib.md5(f"{key_ts}{cls.MAGIC_18COMICAPPCONTENT}".encode()).hexdigest()
230+
231+
return {
232+
'token': token,
233+
'tokenparam': f"{key_ts},1.6.0",
234+
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; V1938CT Build/PQ3A.190705.09211555; wv) AppleWebKit/537.36 (KHTML, '
235+
'like Gecko) Version/4.0 Chrome/91.0.4472.114 Safari/537.36',
236+
'X-Requested-With': 'com.jiaohua_browser',
237+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
238+
'application/signed-exchange;v=b3;q=0.9',
239+
'Sec-Fetch-Site': 'none',
240+
'Sec-Fetch-Mode': 'navigate',
241+
'Sec-Fetch-User': '?1',
242+
'Sec-Fetch-Dest': 'document',
243+
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
244+
}
245+
221246
# noinspection PyUnusedLocal
222247
@classmethod
223248
def jm_debug(cls, topic: str, msg: str):
@@ -231,7 +256,7 @@ def disable_jm_debug(cls):
231256
@classmethod
232257
def new_postman(cls, session=False, **kwargs):
233258
kwargs.setdefault('impersonate', 'chrome110')
234-
kwargs.setdefault('headers', JmModuleConfig.headers())
259+
kwargs.setdefault('headers', JmModuleConfig.new_html_headers())
235260
kwargs.setdefault('proxies', JmModuleConfig.DEFAULT_PROXIES)
236261
return cls.postman_constructor(session, **kwargs)
237262

src/jmcomic/jm_option.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__(self,
128128
self.version = JmModuleConfig.JM_OPTION_VER
129129
# 路径规则配置
130130
self.dir_rule = DirRule(**dir_rule)
131-
# 请求配置
131+
# 客户端配置
132132
self.client = AdvancedEasyAccessDict(client)
133133
# 下载配置
134134
self.download = AdvancedEasyAccessDict(download)
@@ -340,7 +340,7 @@ def decide_domain():
340340
# headers
341341
meta_data = postman_conf['meta_data']
342342
if meta_data['headers'] is None:
343-
meta_data['headers'] = JmModuleConfig.headers(domain[0])
343+
meta_data['headers'] = self.decide_postman_headers(impl, domain[0])
344344

345345
# postman
346346
postman = Postmans.create(data=postman_conf)
@@ -363,15 +363,7 @@ def decide_domain():
363363

364364
# noinspection PyMethodMayBeStatic
365365
def decide_client_domain(self, client_key: str) -> List[str]:
366-
def is_client_type(ct: Type[JmcomicClient]):
367-
if client_key == ct:
368-
return True
369-
370-
clazz = JmModuleConfig.client_impl_class(client_key)
371-
if issubclass(clazz, ct):
372-
return True
373-
374-
return False
366+
is_client_type = lambda ctype: self.client_key_is_given_type(client_key, ctype)
375367

376368
if is_client_type(JmApiClient):
377369
# 移动端
@@ -383,6 +375,31 @@ def is_client_type(ct: Type[JmcomicClient]):
383375

384376
ExceptionTool.raises(f'没有配置域名,且是无法识别的client类型: {client_key}')
385377

378+
def decide_postman_headers(self, client_key, domain):
379+
is_client_type = lambda ctype: self.client_key_is_given_type(client_key, ctype)
380+
381+
if is_client_type(JmApiClient):
382+
# 移动端
383+
# 不配置headers,由client每次请求前创建headers
384+
return {}
385+
386+
if is_client_type(JmHtmlClient):
387+
# 网页端
388+
return JmModuleConfig.new_html_headers(domain)
389+
390+
ExceptionTool.raises(f'没有配置域名,且是无法识别的client类型: {client_key}')
391+
392+
@classmethod
393+
def client_key_is_given_type(cls, client_key, ctype: Type[JmcomicClient]):
394+
if client_key == ctype.client_key:
395+
return True
396+
397+
clazz = JmModuleConfig.client_impl_class(client_key)
398+
if issubclass(clazz, ctype):
399+
return True
400+
401+
return False
402+
386403
@classmethod
387404
def merge_default_dict(cls, user_dict, default_dict=None):
388405
"""

tests/test_jmcomic/test_jm_client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def test_detail_property_list(self):
7878

7979
def test_photo_sort(self):
8080
client = self.option.build_jm_client()
81+
get_photo_detail = lambda *args: client.get_photo_detail(*args, fetch_album=False, fetch_scramble_id=False)
82+
get_album_detail = client.get_album_detail
8183

8284
# 测试用例 - 单章本子
8385
single_photo_album_is = str_to_list('''
@@ -92,8 +94,8 @@ def test_photo_sort(self):
9294
122061
9395
''')
9496

95-
photo_dict: Dict[str, JmPhotoDetail] = multi_call(client.get_photo_detail, single_photo_album_is)
96-
album_dict: Dict[str, JmAlbumDetail] = multi_call(client.get_album_detail, single_photo_album_is)
97+
photo_dict: Dict[str, JmPhotoDetail] = multi_call(get_photo_detail, single_photo_album_is)
98+
album_dict: Dict[str, JmAlbumDetail] = multi_call(get_album_detail, single_photo_album_is)
9799

98100
for each in photo_dict.values():
99101
each: JmPhotoDetail
@@ -107,10 +109,10 @@ def test_photo_sort(self):
107109
multi_photo_album_dict: Dict[JmAlbumDetail, List[JmPhotoDetail]] = {}
108110

109111
def run(aid):
110-
album = client.get_album_detail(aid)
112+
album = get_album_detail(aid)
111113

112114
photo_dict = multi_call(
113-
client.get_photo_detail,
115+
get_photo_detail,
114116
(photo.photo_id for photo in album),
115117
launcher=thread_pool_executor,
116118
)

0 commit comments

Comments
 (0)