Skip to content

Commit e7e85a1

Browse files
authored
v2.0.6: 修复代理和禁漫发布页请求的一些问题 (#62)
1 parent e6df292 commit e7e85a1

File tree

7 files changed

+42
-24
lines changed

7 files changed

+42
-24
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 跑测试
22

33
on:
44
push:
5-
branches: [ "dev", "master" ]
5+
branches: [ "dev" ]
66
paths:
77
- 'assets/config/*.yml' # option配置文件
88
- 'src/**/*.py' # 源码
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
# Github Actions 下载脚本配置
2-
32
version: '2.0'
43

54
dir_rule:
65
base_dir: /home/runner/work/jmcomic/download/
76
rule: Bd_Aauthor_Atitle_Pindex
8-
9-
client:
10-
postman:
11-
meta_data:
12-
headers:
13-
referer: https://18comic.vip/

assets/config/常用配置介绍.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ client:
55
domain:
66
- jm-comic.org
77
- jm-comic2.cc
8+
- 18comic.vip
9+
- 18comic.org
810

911
postman:
1012
meta_data:
@@ -14,9 +16,9 @@ client:
1416
# proxies: v2ray
1517
# proxies: 127.0.0.1:7890
1618
# proxies:
17-
# http: http://127.0.0.1:7890
18-
# https: https://127.0.0.1:7890
19-
proxies: clash
19+
# http: 127.0.0.1:7890
20+
# https: 127.0.0.1:7890
21+
proxies: null
2022

2123
# cookies: 帐号配置,默认是 null,表示未登录状态访问JM。
2224
# 禁漫的大部分本子,下载是不需要登录的;少部分敏感题材需要登录才能看。

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 <--- option
44

5-
__version__ = '2.0.5'
5+
__version__ = '2.0.6'
66

77
from .api import *

src/jmcomic/jm_client_impl.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,18 @@ def wrap_func_cache(func_name, cache_dict_name):
9595

9696
setattr(self, func_name, wrap_func)
9797

98-
wrap_func_cache('get_photo_detail', 'album_cache_dict')
99-
wrap_func_cache('get_album_detail', 'photo_cache_dict')
100-
wrap_func_cache('search_album', 'search_album_cache_dict')
98+
for func in {
99+
'get_photo_detail',
100+
'get_album_detail',
101+
'search_album',
102+
}:
103+
wrap_func_cache(func, func + '.cache.dict')
104+
105+
def get_jmcomic_url(self, postman=None):
106+
return JmModuleConfig.get_jmcomic_url(postman or self.get_root_postman())
107+
108+
def get_jmcomic_domain_all(self, postman=None):
109+
return JmModuleConfig.get_jmcomic_domain_all(postman or self.get_root_postman())
101110

102111

103112
# 基于网页实现的JmClient

src/jmcomic/jm_config.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ def default_jm_debug(topic: str, msg: str):
33
print(f'{format_ts()}:【{topic}{msg}')
44

55

6+
def default_postman_constructor(session, **kwargs):
7+
from common import Postmans
8+
9+
kwargs.setdefault('impersonate', 'chrome110')
10+
kwargs.setdefault('headers', JmModuleConfig.headers())
11+
12+
if session is True:
13+
return Postmans.new_session(**kwargs)
14+
15+
return Postmans.new_postman(**kwargs)
16+
17+
618
class JmModuleConfig:
719
# 网站相关
820
PROT = "https://"
921
DOMAIN = None
10-
JM_REDIRECT_URL = f'{PROT}jm365.xyz/3YeBdF' # 永久網域,怕走失的小伙伴收藏起来
22+
JM_REDIRECT_URL = f'{PROT}jm365.work/3YeBdF' # 永久網域,怕走失的小伙伴收藏起来
1123
JM_PUB_URL = f'{PROT}jmcomic2.bet'
1224
JM_CDN_IMAGE_URL_TEMPLATE = PROT + 'cdn-msp.{domain}/media/photos/{photo_id}/{index:05}{suffix}' # index 从1开始
1325
JM_IMAGE_SUFFIX = ['.jpg', '.webp', '.png', '.gif']
@@ -40,6 +52,7 @@ class JmModuleConfig:
4052
# debug
4153
enable_jm_debug = True
4254
debug_executor = default_jm_debug
55+
postman_constructor = default_postman_constructor
4356

4457
@classmethod
4558
def domain(cls, postman=None):
@@ -84,15 +97,17 @@ def jm_debug(cls, topic: str, msg: str):
8497
def disable_jm_debug(cls):
8598
cls.enable_jm_debug = False
8699

100+
@classmethod
101+
def new_postman(cls, session=False, **kwargs):
102+
return cls.postman_constructor(session, **kwargs)
103+
87104
@classmethod
88105
def get_jmcomic_url(cls, postman=None):
89106
"""
90107
访问禁漫的永久网域,从而得到一个可用的禁漫网址
91108
@return: https://jm-comic2.cc
92109
"""
93-
if postman is None:
94-
from common import Postmans
95-
postman = Postmans.new_session()
110+
postman = postman or cls.new_postman(session=True)
96111

97112
resp = postman.get(cls.JM_REDIRECT_URL)
98113
url = resp.url
@@ -105,9 +120,7 @@ def get_jmcomic_domain_all(cls, postman=None):
105120
访问禁漫发布页,得到所有禁漫的域名
106121
@return:['18comic.vip', ..., 'jm365.xyz/ZNPJam'], 最后一个是【APP軟件下載】
107122
"""
108-
if postman is None:
109-
from common import Postmans
110-
postman = Postmans.get_impl_clazz('cffi').create()
123+
postman = postman or cls.new_postman(session=True)
111124

112125
resp = postman.get(cls.JM_PUB_URL)
113126
if resp.status_code != 200:

tests/test_jmcomic/test_jm_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def run(aid):
102102
)
103103

104104
def test_get_jmcomic_url(self):
105+
print(self.client.get_jmcomic_url())
106+
print(self.client.get_jmcomic_domain_all())
107+
print(JmModuleConfig.get_jmcomic_url())
105108
print(JmModuleConfig.get_jmcomic_domain_all())
106-
print(JmModuleConfig.get_jmcomic_url(self.client))
107-
print(JmModuleConfig.get_jmcomic_domain_all(self.client))

0 commit comments

Comments
 (0)