Skip to content

Commit 1b38daf

Browse files
authored
v.2.0.4: 优化debug和工作流,增加配置文件的介绍,实现工作流的请求失败内容上传 (#53)
1 parent 85b6bdc commit 1b38daf

File tree

5 files changed

+68
-13
lines changed

5 files changed

+68
-13
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
client:
2+
# domain: 域名配置,默认是 [],表示运行时自动获取域名。
3+
# 可配置特定域名,如下:
4+
# 程序会先用第一个域名,如果第一个域名重试n次失败,则换下一个域名重试,以此类推。
5+
domain:
6+
- jm-comic.org
7+
- jm-comic2.cc
8+
9+
postman:
10+
meta_data:
11+
# proxies: 代理配置,默认是 null,表示不使用代理。
12+
# 以下的写法都可以:
13+
# proxies: clash
14+
# proxies: v2ray
15+
# proxies: 127.0.0.1:7890
16+
# proxies:
17+
# http: http://127.0.0.1:7890
18+
# https: https://127.0.0.1:7890
19+
proxies: clash
20+
21+
# cookies: 帐号配置,默认是 null,表示未登录状态访问JM。
22+
# 禁漫的大部分本子,下载是不需要登录的;少部分敏感题材需要登录才能看。
23+
# 如果你希望以登录状态下载本子,最简单的方式是配置一下浏览器的cookies,
24+
# 不用全部cookies,只要那个叫 AVS 就行。
25+
cookies:
26+
AVS: qkwehjjasdowqeq # 这个值是乱打的,不能用
27+
28+
# 下载配置
29+
download:
30+
cache: true # 如果要下载的文件在磁盘上已存在,不用再下一遍了吧?
31+
image:
32+
decode: true # JM的原图是混淆过的,要不要还原?
33+
suffix: .jpg # 把图片都转为.jpg格式
34+
threading:
35+
# batch_count: 章节的批量下载图片线程数
36+
# 数值大,下得快,配置要求高,对禁漫压力大
37+
# 数值小,下得慢,配置要求低,对禁漫压力小
38+
# PS: 禁漫网页一般是一次请求50张图
39+
batch_count: 30
40+
41+
42+
43+
# 文件夹规则配置,决定图片文件存放在你的电脑上的哪个文件夹
44+
dir_rule:
45+
# base_dir: 根目录。
46+
base_dir: D:/a/b/c/
47+
48+
# rule: 规则dsl。
49+
# 本项只建议了解编程的朋友定制,实现在这个类: jmcomic.jm_option.DirRule
50+
# 写法:
51+
# 1. 以'Bd'开头,表示根目录
52+
# 2. 文件夹每增加一层,使用'_'区隔
53+
# 3. 文件夹名字表示为 Pxxx/Ayyy,意思是 JmPhotoDetail.xxx / JmAlbumDetail的.yyy。xxx和yyy可以写什么需要看源码。
54+
# 下面是示例,表示使用禁漫网站的默认下载方式 [根目录 / 本子id / 章节序号 / 图片文件]
55+
# rule: Bd_Aid_Pindex
56+
57+
# 默认规则是: 根目录 / 章节标题 / 图片文件
58+
rule: Bd_Ptitle

assets/config/禁漫域名配置示例.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

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.3'
5+
__version__ = '2.0.4'
66

77
from .api import *

src/jmcomic/api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ def download_album(jm_album_id, option=None):
1717

1818
jm_debug('album',
1919
f'本子获取成功: [{album.id}], '
20-
f'标题: [{album.title}], '
2120
f'作者: [{album.author}], '
22-
f'章节数: [{len(album)}]')
21+
f'章节数: [{len(album)}]'
22+
f'标题: [{album.title}], '
23+
)
2324

2425
def download_photo(photo: JmPhotoDetail,
2526
debug_topic='photo',
@@ -92,11 +93,12 @@ def download_by_photo_detail(photo_detail: JmPhotoDetail,
9293
# 下载每个图片的函数
9394
def download_image(index, image: JmImageDetail, debug_topic='image'):
9495
img_save_path = option.decide_image_filepath(photo_detail, index)
96+
debug_tag = f'{image.aid}/{image.filename} [{index + 1}/{len(photo_detail)}]'
9597

9698
# 已下载过,缓存命中
9799
if use_cache is True and file_exists(img_save_path):
98100
jm_debug(debug_topic,
99-
f'图片已存在: {image.aid}[{image.filename}] → {img_save_path}')
101+
f'图片已存在: {debug_tag} ← [{img_save_path}]')
100102
return
101103

102104
# 开始下载
@@ -107,8 +109,7 @@ def download_image(index, image: JmImageDetail, debug_topic='image'):
107109
)
108110

109111
jm_debug(debug_topic,
110-
f'图片下载完成: {image.aid}/{image.filename}, '
111-
f'[{image.img_url}] → [{img_save_path}]')
112+
f'图片下载完成: {debug_tag}, [{image.img_url}] → [{img_save_path}]')
112113

113114
length = len(photo_detail)
114115
# 根据图片数,决定下载策略

usage/workflow_download.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 下方填入你要下载的本子的id,一行一个。
22
# 每行的首尾可以有空白字符
33
jm_albums = '''
4-
438696
4+
452859
55
66
77
'''
@@ -18,6 +18,7 @@ def get_option():
1818

1919
# 读取 option 配置文件
2020
option = create_option('../assets/config/option_workflow_download.yml')
21+
hook_debug(option)
2122

2223
# 启用 client 的缓存
2324
client = option.build_jm_client()
@@ -38,7 +39,6 @@ def get_option():
3839
client.login(username, password, True)
3940
print_eye_catching(f'登录禁漫成功')
4041

41-
hook_debug(option)
4242
return option
4343

4444

@@ -54,7 +54,7 @@ class HookDebugClient(JmHtmlClient):
5454
def raise_request_error(cls, resp, msg):
5555
from common import write_text, fix_windir_name, format_ts
5656
write_text(
57-
f'{jm_download_dir}/[请求禁漫失败时的网页内容]_[{format_ts}]_[{fix_windir_name(resp.url)}].html',
57+
f'{jm_download_dir}/[请求失败的响应内容]_[{format_ts()}]_[{fix_windir_name(resp.url)}].html',
5858
resp.text
5959
)
6060

0 commit comments

Comments
 (0)