v1.8.0: 增加 album_missing 情况的友好提示 (#18)

This commit is contained in:
hect0x7 2023-04-27 14:38:03 +08:00 committed by GitHub
parent 56c72b96e3
commit 0c8b3f4cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 14 deletions

View File

@ -14,7 +14,7 @@ permissions:
contents: read
jobs:
build:
crawler:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

View File

@ -20,7 +20,7 @@ permissions:
contents: read
jobs:
build:
crawler:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

View File

@ -2,6 +2,6 @@
# 被依赖方 <--- 使用方
# config <--- entity <--- toolkit <--- client <--- service <--- option
__version__ = '1.7.0'
__version__ = '1.8.0'
from .api import *

View File

@ -141,9 +141,12 @@ class JmcomicClient(PostmanProxy):
(f"响应文本=[{resp.text}]" if len(resp.text) < 50 else
f'响应文本过长(len={len(resp.text)}),不打印')
)
# 图片请求,直接返回
if is_api is False:
return resp
if is_api is True:
JmModuleConfig.check_html(resp.text.strip(), url)
# 检查请求是否成功
self.require_resp_success_else_raise(resp, url)
return resp
@ -189,6 +192,27 @@ class JmcomicClient(PostmanProxy):
def get_jmcomic_url_all(self, postman=None):
return JmModuleConfig.get_jmcomic_url_all(postman or self)
@classmethod
def require_resp_success_else_raise(cls, resp, url):
# 1. 是否 album_missing
if resp.url.endswith('/error/album_missing'):
raise AssertionError(f'请求的本子不存在!({url})\n'
'原因可能为:\n'
'1. id有误检查你的本子/章节id\n'
'2. 该漫画只对登录用户可见请配置你的cookies\n')
# 2. 是否是特殊html页
cls.check_special_html(resp.text.strip(), url)
@classmethod
def check_special_html(cls, html: str, url=None):
html = html.strip()
error_msg = JmModuleConfig.JM_ERROR_RESPONSE_HTML.get(html, None)
if error_msg is None:
return
raise AssertionError(f'{error_msg}' + f': {url}' if url is not None else '')
# 爬取策略
class FetchStrategy:

View File

@ -102,15 +102,6 @@ class JmModuleConfig:
from .jm_toolkit import JmcomicText
return JmcomicText.analyse_jm_pub_html(resp.text)
@classmethod
def check_html(cls, html: str, url=None):
html = html.strip()
error_msg = cls.JM_ERROR_RESPONSE_HTML.get(html, None)
if error_msg is None:
return
raise AssertionError(f'{error_msg}' + f': {url}' if url is not None else '')
jm_debug = JmModuleConfig.jm_debug
disable_jm_debug = JmModuleConfig.disable_jm_debug

View File

@ -58,3 +58,10 @@ class Test_Client(JmTestConfigurable):
image = photo_detail[3000]
print(image.img_url)
self.client.download_by_image_detail(image, workspace('3000.png'))
def test_album_missing(self):
self.assertRaises(
AssertionError,
self.client.get_album_detail,
'332583'
)