Skip to content

Commit fb260f2

Browse files
authored
v2.5.17: 更新禁漫APP端图片请求headers (#272)
1 parent 710b229 commit fb260f2

File tree

6 files changed

+64
-51
lines changed

6 files changed

+64
-51
lines changed

assets/option/option_test_api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ client:
88
retry_times: 3
99
postman:
1010
meta_data:
11-
timeout: 7
11+
timeout: 15
1212
domain:
1313
html:
1414
- jmcomic1.me

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.5.16'
5+
__version__ = '2.5.17'
66

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

src/jmcomic/jm_client_impl.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def request_with_retry(self,
9292
jm_log(self.log_topic(), self.decode(url))
9393
else:
9494
# 图片url
95-
pass
95+
self.update_request_with_specify_domain(kwargs, None, True)
9696

9797
if domain_index != 0 or retry_count != 0:
9898
jm_log(f'req.retry',
@@ -133,7 +133,7 @@ def raise_if_resp_should_retry(self, resp):
133133
"""
134134
return resp
135135

136-
def update_request_with_specify_domain(self, kwargs: dict, domain: str):
136+
def update_request_with_specify_domain(self, kwargs: dict, domain: Optional[str], is_image: bool = False):
137137
"""
138138
域名自动切换时,用于更新请求参数的回调
139139
"""
@@ -463,7 +463,10 @@ def get_jm_html(self, url, require_200=True, **kwargs):
463463

464464
return resp
465465

466-
def update_request_with_specify_domain(self, kwargs: dict, domain: Optional[str]):
466+
def update_request_with_specify_domain(self, kwargs: dict, domain: Optional[str], is_image=False):
467+
if is_image:
468+
return
469+
467470
latest_headers = kwargs.get('headers', None)
468471
base_headers = self.get_meta_data('headers', None) or JmModuleConfig.new_html_headers(domain)
469472
base_headers.update(latest_headers or {})
@@ -909,8 +912,10 @@ def req_api(self, url, get=True, require_success=True, **kwargs) -> JmApiResp:
909912

910913
return resp
911914

912-
def update_request_with_specify_domain(self, kwargs: dict, domain: str):
913-
pass
915+
def update_request_with_specify_domain(self, kwargs: dict, domain: Optional[str], is_image=False):
916+
if is_image:
917+
# 设置APP端的图片请求headers
918+
kwargs['headers'] = {**JmModuleConfig.APP_HEADERS_TEMPLATE, **JmModuleConfig.APP_HEADERS_IMAGE}
914919

915920
# noinspection PyMethodMayBeStatic
916921
def decide_headers_and_ts(self, kwargs, url):
@@ -930,7 +935,7 @@ def decide_headers_and_ts(self, kwargs, url):
930935
token, tokenparam = JmCryptoTool.token_and_tokenparam(ts)
931936

932937
# 设置headers
933-
headers = kwargs.get('headers', None) or JmMagicConstants.APP_HEADERS_TEMPLATE.copy()
938+
headers = kwargs.get('headers', None) or JmModuleConfig.APP_HEADERS_TEMPLATE.copy()
934939
headers.update({
935940
'token': token,
936941
'tokenparam': tokenparam,

src/jmcomic/jm_config.py

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,50 +59,16 @@ class JmMagicConstants:
5959
SUB_SINGLE_JAPANESE = SUB_JAPANESE
6060
SUB_SINGLE_YOUTH = 'youth'
6161

62-
# 分页大小
63-
PAGE_SIZE_SEARCH = 80
64-
PAGE_SIZE_FAVORITE = 20
65-
6662
# 图片分割参数
6763
SCRAMBLE_220980 = 220980
6864
SCRAMBLE_268850 = 268850
6965
SCRAMBLE_421926 = 421926 # 2023-02-08后改了图片切割算法
7066

71-
# 当本子没有作者名字时,顶替作者名字
72-
DEFAULT_AUTHOR = 'default_author'
73-
7467
# 移动端API密钥
7568
APP_TOKEN_SECRET = '18comicAPP'
7669
APP_TOKEN_SECRET_2 = '18comicAPPContent'
7770
APP_DATA_SECRET = '185Hcomic3PAPP7R'
78-
APP_VERSION = '1.7.0'
79-
APP_HEADERS_TEMPLATE = {
80-
'Accept-Encoding': 'gzip',
81-
'user-agent': 'Mozilla/5.0 (Linux; Android 9; V1938CT Build/PQ3A.190705.11211812; wv) AppleWebKit/537.36 (KHTML, '
82-
'like Gecko) Version/4.0 Chrome/91.0.4472.114 Safari/537.36',
83-
}
84-
85-
# 网页端headers
86-
HTML_HEADERS_TEMPLATE = {
87-
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
88-
'application/signed-exchange;v=b3;q=0.7',
89-
'accept-language': 'zh-CN,zh;q=0.9',
90-
'cache-control': 'no-cache',
91-
'dnt': '1',
92-
'pragma': 'no-cache',
93-
'priority': 'u=0, i',
94-
'referer': 'https://18comic.vip/',
95-
'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
96-
'sec-ch-ua-mobile': '?0',
97-
'sec-ch-ua-platform': '"Windows"',
98-
'sec-fetch-dest': 'document',
99-
'sec-fetch-mode': 'navigate',
100-
'sec-fetch-site': 'none',
101-
'sec-fetch-user': '?1',
102-
'upgrade-insecure-requests': '1',
103-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 '
104-
'Safari/537.36',
105-
}
71+
APP_VERSION = '1.7.1'
10672

10773

10874
# 模块级别共用配置
@@ -123,14 +89,55 @@ class JmModuleConfig:
12389
# JM的异常网页code
12490
JM_ERROR_STATUS_CODE = {
12591
403: 'ip地区禁止访问/爬虫被识别',
126-
500: '500: 禁漫服务器内部异常(可能是服务器过载,可以换个ip或稍后重试)',
92+
500: '500: 禁漫服务器内部异常(可能是服务器过载,可以切换ip或稍后重试)',
12793
520: '520: Web server is returning an unknown error (禁漫服务器内部报错)',
12894
524: '524: The origin web server timed out responding to this request. (禁漫服务器处理超时)',
12995
}
13096

97+
# 分页大小
98+
PAGE_SIZE_SEARCH = 80
99+
PAGE_SIZE_FAVORITE = 20
100+
131101
# 图片分隔相关
132102
SCRAMBLE_CACHE = {}
133103

104+
# 当本子没有作者名字时,顶替作者名字
105+
DEFAULT_AUTHOR = 'default_author'
106+
107+
APP_HEADERS_TEMPLATE = {
108+
'Accept-Encoding': 'gzip, deflate',
109+
'user-agent': 'Mozilla/5.0 (Linux; Android 9; V1938CT Build/PQ3A.190705.11211812; wv) AppleWebKit/537.36 (KHTML, '
110+
'like Gecko) Version/4.0 Chrome/91.0.4472.114 Safari/537.36',
111+
}
112+
113+
APP_HEADERS_IMAGE = {
114+
'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
115+
'X-Requested-With': 'com.jiaohua_browser',
116+
'Referer': 'https://www.jmfreedomproxy.xyz/',
117+
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
118+
}
119+
120+
# 网页端headers
121+
HTML_HEADERS_TEMPLATE = {
122+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
123+
'application/signed-exchange;v=b3;q=0.7',
124+
'accept-language': 'zh-CN,zh;q=0.9',
125+
'cache-control': 'no-cache',
126+
'dnt': '1',
127+
'pragma': 'no-cache',
128+
'priority': 'u=0, i',
129+
'referer': 'https://18comic.vip/',
130+
'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
131+
'sec-ch-ua-mobile': '?0',
132+
'sec-ch-ua-platform': '"Windows"',
133+
'sec-fetch-dest': 'document',
134+
'sec-fetch-mode': 'navigate',
135+
'sec-fetch-site': 'none',
136+
'sec-fetch-user': '?1',
137+
'upgrade-insecure-requests': '1',
138+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 '
139+
'Safari/537.36',
140+
}
134141
# cookies,目前只在移动端使用,因为移动端请求接口须携带,但不会校验cookies的内容。
135142
APP_COOKIES = None
136143

@@ -336,7 +343,7 @@ def new_html_headers(cls, domain='18comic.vip'):
336343
"""
337344
网页端的headers
338345
"""
339-
headers = JmMagicConstants.HTML_HEADERS_TEMPLATE.copy()
346+
headers = cls.HTML_HEADERS_TEMPLATE.copy()
340347
headers.update({
341348
'authority': domain,
342349
'origin': f'https://{domain}',

src/jmcomic/jm_entity.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ def __init__(self,
305305
# 2. 值目前在网页端只在photo页面的图片标签的data-original属性出现
306306
# 这里的模拟思路是,获取到第一个图片标签的data-original,
307307
# 取出其query参数 → self.data_original_query_params, 该值未来会传递给 JmImageDetail
308-
self.data_original_query_params = self.get_data_original_query_params(data_original_0)
308+
# self.data_original_query_params = self.get_data_original_query_params(data_original_0)
309+
self.data_original_query_params = None
309310

310311
@property
311312
def is_single_album(self) -> bool:
@@ -355,7 +356,7 @@ def author(self) -> str:
355356
return self._author.strip()
356357

357358
# 使用默认
358-
return JmMagicConstants.DEFAULT_AUTHOR
359+
return JmModuleConfig.DEFAULT_AUTHOR
359360

360361
def create_image_detail(self, index) -> JmImageDetail:
361362
# 校验参数
@@ -475,7 +476,7 @@ def author(self):
475476
if len(self.authors) >= 1:
476477
return self.authors[0]
477478

478-
return JmMagicConstants.DEFAULT_AUTHOR
479+
return JmModuleConfig.DEFAULT_AUTHOR
479480

480481
@property
481482
def id(self):
@@ -612,7 +613,7 @@ class JmSearchPage(JmPageContent):
612613

613614
@property
614615
def page_size(self) -> int:
615-
return JmMagicConstants.PAGE_SIZE_SEARCH
616+
return JmModuleConfig.PAGE_SIZE_SEARCH
616617

617618
# 下面的方法是对单个album的包装
618619

@@ -653,7 +654,7 @@ def __init__(self, content, folder_list, total):
653654

654655
@property
655656
def page_size(self) -> int:
656-
return JmMagicConstants.PAGE_SIZE_FAVORITE
657+
return JmModuleConfig.PAGE_SIZE_FAVORITE
657658

658659
def iter_folder_id_name(self) -> Generator[Tuple[str, str], None, None]:
659660
"""

src/jmcomic/jm_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def save_folder_page_data_to_file(self, page_data: List[JmFavoritePage], fid: st
601601
for page in page_data:
602602
for aid, extra in page.content:
603603
data.append(
604-
(aid, extra.get('author', '') or JmMagicConstants.DEFAULT_AUTHOR, extra['name'])
604+
(aid, extra.get('author', '') or JmModuleConfig.DEFAULT_AUTHOR, extra['name'])
605605
)
606606

607607
if len(data) == 0:

0 commit comments

Comments
 (0)