v2.1.18: 修复对模块域名全局配置的支持 (#108)

This commit is contained in:
hect0x7 2023-08-29 09:31:11 +08:00 committed by GitHub
parent 4d9b8175aa
commit affadd9ffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 39 deletions

View File

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

View File

@ -146,6 +146,38 @@ class JmModuleConfig:
from .jm_toolkit import JmcomicText
return JmcomicText.parse_to_jm_domain(cls.get_jmcomic_url(postman))
@classmethod
def get_jmcomic_url(cls, postman=None):
"""
访问禁漫的永久网域从而得到一个可用的禁漫网址
@return: https://jm-comic2.cc
"""
postman = postman or cls.new_postman(session=True)
url = postman.with_redirect_catching().get(cls.JM_REDIRECT_URL)
cls.jm_debug('获取禁漫URL', f'[{cls.JM_REDIRECT_URL}] → [{url}]')
return url
@classmethod
@field_cache("DOMAIN_LIST")
def get_jmcomic_domain_all(cls, postman=None):
"""
访问禁漫发布页得到所有禁漫的域名
@return: ['18comic.vip', ..., 'jm365.xyz/ZNPJam'], 最后一个是APP軟件下載
"""
postman = postman or cls.new_postman(session=True)
resp = postman.get(cls.JM_PUB_URL)
if resp.status_code != 200:
raise JmModuleConfig.exception(resp.text)
from .jm_toolkit import JmcomicText
domain_list = JmcomicText.analyse_jm_pub_html(resp.text)
cls.jm_debug('获取禁漫全部域名', f'[{resp.url}] → {domain_list}')
return domain_list
@classmethod
def headers(cls, domain='18comic.vip'):
return {
@ -182,38 +214,6 @@ class JmModuleConfig:
kwargs.setdefault('headers', JmModuleConfig.headers())
return cls.postman_constructor(session, **kwargs)
@classmethod
def get_jmcomic_url(cls, postman=None):
"""
访问禁漫的永久网域从而得到一个可用的禁漫网址
@return: https://jm-comic2.cc
"""
postman = postman or cls.new_postman(session=True)
url = postman.with_redirect_catching().get(cls.JM_REDIRECT_URL)
cls.jm_debug('获取禁漫URL', f'[{cls.JM_REDIRECT_URL}] → [{url}]')
return url
@classmethod
@field_cache("DOMAIN_LIST")
def get_jmcomic_domain_all(cls, postman=None):
"""
访问禁漫发布页得到所有禁漫的域名
@return: ['18comic.vip', ..., 'jm365.xyz/ZNPJam'], 最后一个是APP軟件下載
"""
postman = postman or cls.new_postman(session=True)
resp = postman.get(cls.JM_PUB_URL)
if resp.status_code != 200:
raise JmModuleConfig.exception(resp.text)
from .jm_toolkit import JmcomicText
domain_list = JmcomicText.analyse_jm_pub_html(resp.text)
cls.jm_debug('获取禁漫全部域名', f'[{resp.url}] → {domain_list}')
return domain_list
album_comment_headers = {
'authority': '18comic.vip',
'accept': 'application/json, text/javascript, */*; q=0.01',

View File

@ -249,7 +249,7 @@ class JmOption:
# domain_list
domain_list = self.client.domain
if len(domain_list) == 0:
domain_list = [JmcomicText.parse_to_jm_domain(JmModuleConfig.get_jmcomic_url(postman))]
domain_list = [JmModuleConfig.domain()]
# client
client = JmModuleConfig.client_impl_class(self.client.impl)(

View File

@ -162,10 +162,8 @@ class JmcomicText:
return cls.format_url(f'/album/{cls.parse_to_album_id(album_id)}', domain)
@classmethod
def format_url(cls, path, domain=None):
if domain is None:
domain = JmModuleConfig.domain()
def format_url(cls, path, domain):
assert isinstance(domain, str) and len(domain) != 0
return f'{JmModuleConfig.PROT}{domain}{path}'

View File

@ -64,6 +64,10 @@ jmcomic.download_album(aid for aid in ('422866', '1', '2', '3')) # 生成器
url_ls = jmcomic.JmModuleConfig.get_jmcomic_url_all()
print(url_ls)
# 方式2(可能会报错,需要你自己配置梯子)
# 方式2: 访问禁漫的永久网域
url = jmcomic.JmModuleConfig.get_jmcomic_url()
print(url)
# 配置jmcomic模块的默认域名
# 默认域名仅在option没有配置domain时被使用
jmcomic.JmModuleConfig.DOMAIN = '18comic.vip'