Skip to content

Commit 0c8b3f4

Browse files
authored
v1.8.0: 增加 album_missing 情况的友好提示 (#18)
1 parent 56c72b9 commit 0c8b3f4

File tree

6 files changed

+36
-14
lines changed

6 files changed

+36
-14
lines changed

.github/workflows/action_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permissions:
1414
contents: read
1515

1616
jobs:
17-
build:
17+
crawler:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v3

.github/workflows/action_workflow_local.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ permissions:
2020
contents: read
2121

2222
jobs:
23-
build:
23+
crawler:
2424
runs-on: ubuntu-latest
2525
steps:
2626
- uses: actions/checkout@v3

src/jmcomic/__init__.py

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

5-
__version__ = '1.7.0'
5+
__version__ = '1.8.0'
66

77
from .api import *

src/jmcomic/jm_client.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ def jm_get(self, url, is_api=True, require_200=True, **kwargs):
141141
(f"响应文本=[{resp.text}]" if len(resp.text) < 50 else
142142
f'响应文本过长(len={len(resp.text)}),不打印')
143143
)
144+
# 图片请求,直接返回
145+
if is_api is False:
146+
return resp
144147

145-
if is_api is True:
146-
JmModuleConfig.check_html(resp.text.strip(), url)
148+
# 检查请求是否成功
149+
self.require_resp_success_else_raise(resp, url)
147150

148151
return resp
149152

@@ -189,6 +192,27 @@ def get_jmcomic_url(self, postman=None):
189192
def get_jmcomic_url_all(self, postman=None):
190193
return JmModuleConfig.get_jmcomic_url_all(postman or self)
191194

195+
@classmethod
196+
def require_resp_success_else_raise(cls, resp, url):
197+
# 1. 是否 album_missing
198+
if resp.url.endswith('/error/album_missing'):
199+
raise AssertionError(f'请求的本子不存在!({url})\n'
200+
'原因可能为:\n'
201+
'1. id有误,检查你的本子/章节id\n'
202+
'2. 该漫画只对登录用户可见,请配置你的cookies\n')
203+
204+
# 2. 是否是特殊html页
205+
cls.check_special_html(resp.text.strip(), url)
206+
207+
@classmethod
208+
def check_special_html(cls, html: str, url=None):
209+
html = html.strip()
210+
error_msg = JmModuleConfig.JM_ERROR_RESPONSE_HTML.get(html, None)
211+
if error_msg is None:
212+
return
213+
214+
raise AssertionError(f'{error_msg}' + f': {url}' if url is not None else '')
215+
192216

193217
# 爬取策略
194218
class FetchStrategy:

src/jmcomic/jm_config.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@ def get_jmcomic_url_all(cls, postman=None):
102102
from .jm_toolkit import JmcomicText
103103
return JmcomicText.analyse_jm_pub_html(resp.text)
104104

105-
@classmethod
106-
def check_html(cls, html: str, url=None):
107-
html = html.strip()
108-
error_msg = cls.JM_ERROR_RESPONSE_HTML.get(html, None)
109-
if error_msg is None:
110-
return
111-
112-
raise AssertionError(f'{error_msg}' + f': {url}' if url is not None else '')
113-
114105

115106
jm_debug = JmModuleConfig.jm_debug
116107
disable_jm_debug = JmModuleConfig.disable_jm_debug

tests/test_jmcomic/test_jm_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ def test_gt_300_photo(self):
5858
image = photo_detail[3000]
5959
print(image.img_url)
6060
self.client.download_by_image_detail(image, workspace('3000.png'))
61+
62+
def test_album_missing(self):
63+
self.assertRaises(
64+
AssertionError,
65+
self.client.get_album_detail,
66+
'332583'
67+
)

0 commit comments

Comments
 (0)