mirror of
https://github.com/hect0x7/JMComic-Crawler-Python.git
synced 2025-11-04 14:49:43 +08:00
v2.0.6: 修复代理和禁漫发布页请求的一些问题 (#62)
This commit is contained in:
parent
e6df29212e
commit
e7e85a1034
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -2,7 +2,7 @@ name: 跑测试
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "dev", "master" ]
|
||||
branches: [ "dev" ]
|
||||
paths:
|
||||
- 'assets/config/*.yml' # option配置文件
|
||||
- 'src/**/*.py' # 源码
|
||||
|
||||
@ -1,13 +1,6 @@
|
||||
# Github Actions 下载脚本配置
|
||||
|
||||
version: '2.0'
|
||||
|
||||
dir_rule:
|
||||
base_dir: /home/runner/work/jmcomic/download/
|
||||
rule: Bd_Aauthor_Atitle_Pindex
|
||||
|
||||
client:
|
||||
postman:
|
||||
meta_data:
|
||||
headers:
|
||||
referer: https://18comic.vip/
|
||||
|
||||
@ -5,6 +5,8 @@ client:
|
||||
domain:
|
||||
- jm-comic.org
|
||||
- jm-comic2.cc
|
||||
- 18comic.vip
|
||||
- 18comic.org
|
||||
|
||||
postman:
|
||||
meta_data:
|
||||
@ -14,9 +16,9 @@ client:
|
||||
# proxies: v2ray
|
||||
# proxies: 127.0.0.1:7890
|
||||
# proxies:
|
||||
# http: http://127.0.0.1:7890
|
||||
# https: https://127.0.0.1:7890
|
||||
proxies: clash
|
||||
# http: 127.0.0.1:7890
|
||||
# https: 127.0.0.1:7890
|
||||
proxies: null
|
||||
|
||||
# cookies: 帐号配置,默认是 null,表示未登录状态访问JM。
|
||||
# 禁漫的大部分本子,下载是不需要登录的;少部分敏感题材需要登录才能看。
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
# 被依赖方 <--- 使用方
|
||||
# config <--- entity <--- toolkit <--- client <--- option
|
||||
|
||||
__version__ = '2.0.5'
|
||||
__version__ = '2.0.6'
|
||||
|
||||
from .api import *
|
||||
|
||||
@ -95,9 +95,18 @@ class AbstractJmClient(
|
||||
|
||||
setattr(self, func_name, wrap_func)
|
||||
|
||||
wrap_func_cache('get_photo_detail', 'album_cache_dict')
|
||||
wrap_func_cache('get_album_detail', 'photo_cache_dict')
|
||||
wrap_func_cache('search_album', 'search_album_cache_dict')
|
||||
for func in {
|
||||
'get_photo_detail',
|
||||
'get_album_detail',
|
||||
'search_album',
|
||||
}:
|
||||
wrap_func_cache(func, func + '.cache.dict')
|
||||
|
||||
def get_jmcomic_url(self, postman=None):
|
||||
return JmModuleConfig.get_jmcomic_url(postman or self.get_root_postman())
|
||||
|
||||
def get_jmcomic_domain_all(self, postman=None):
|
||||
return JmModuleConfig.get_jmcomic_domain_all(postman or self.get_root_postman())
|
||||
|
||||
|
||||
# 基于网页实现的JmClient
|
||||
|
||||
@ -3,11 +3,23 @@ def default_jm_debug(topic: str, msg: str):
|
||||
print(f'{format_ts()}:【{topic}】{msg}')
|
||||
|
||||
|
||||
def default_postman_constructor(session, **kwargs):
|
||||
from common import Postmans
|
||||
|
||||
kwargs.setdefault('impersonate', 'chrome110')
|
||||
kwargs.setdefault('headers', JmModuleConfig.headers())
|
||||
|
||||
if session is True:
|
||||
return Postmans.new_session(**kwargs)
|
||||
|
||||
return Postmans.new_postman(**kwargs)
|
||||
|
||||
|
||||
class JmModuleConfig:
|
||||
# 网站相关
|
||||
PROT = "https://"
|
||||
DOMAIN = None
|
||||
JM_REDIRECT_URL = f'{PROT}jm365.xyz/3YeBdF' # 永久網域,怕走失的小伙伴收藏起来
|
||||
JM_REDIRECT_URL = f'{PROT}jm365.work/3YeBdF' # 永久網域,怕走失的小伙伴收藏起来
|
||||
JM_PUB_URL = f'{PROT}jmcomic2.bet'
|
||||
JM_CDN_IMAGE_URL_TEMPLATE = PROT + 'cdn-msp.{domain}/media/photos/{photo_id}/{index:05}{suffix}' # index 从1开始
|
||||
JM_IMAGE_SUFFIX = ['.jpg', '.webp', '.png', '.gif']
|
||||
@ -40,6 +52,7 @@ class JmModuleConfig:
|
||||
# debug
|
||||
enable_jm_debug = True
|
||||
debug_executor = default_jm_debug
|
||||
postman_constructor = default_postman_constructor
|
||||
|
||||
@classmethod
|
||||
def domain(cls, postman=None):
|
||||
@ -84,15 +97,17 @@ class JmModuleConfig:
|
||||
def disable_jm_debug(cls):
|
||||
cls.enable_jm_debug = False
|
||||
|
||||
@classmethod
|
||||
def new_postman(cls, session=False, **kwargs):
|
||||
return cls.postman_constructor(session, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def get_jmcomic_url(cls, postman=None):
|
||||
"""
|
||||
访问禁漫的永久网域,从而得到一个可用的禁漫网址
|
||||
@return: https://jm-comic2.cc
|
||||
"""
|
||||
if postman is None:
|
||||
from common import Postmans
|
||||
postman = Postmans.new_session()
|
||||
postman = postman or cls.new_postman(session=True)
|
||||
|
||||
resp = postman.get(cls.JM_REDIRECT_URL)
|
||||
url = resp.url
|
||||
@ -105,9 +120,7 @@ class JmModuleConfig:
|
||||
访问禁漫发布页,得到所有禁漫的域名
|
||||
@return:['18comic.vip', ..., 'jm365.xyz/ZNPJam'], 最后一个是【APP軟件下載】
|
||||
"""
|
||||
if postman is None:
|
||||
from common import Postmans
|
||||
postman = Postmans.get_impl_clazz('cffi').create()
|
||||
postman = postman or cls.new_postman(session=True)
|
||||
|
||||
resp = postman.get(cls.JM_PUB_URL)
|
||||
if resp.status_code != 200:
|
||||
|
||||
@ -102,6 +102,7 @@ class Test_Api(JmTestConfigurable):
|
||||
)
|
||||
|
||||
def test_get_jmcomic_url(self):
|
||||
print(self.client.get_jmcomic_url())
|
||||
print(self.client.get_jmcomic_domain_all())
|
||||
print(JmModuleConfig.get_jmcomic_url())
|
||||
print(JmModuleConfig.get_jmcomic_domain_all())
|
||||
print(JmModuleConfig.get_jmcomic_url(self.client))
|
||||
print(JmModuleConfig.get_jmcomic_domain_all(self.client))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user