Skip to content

Commit c5810d9

Browse files
committed
v2.2.11: 修复命令行模式下option未配置的问题,优化GitHub Actions工作流,更新common依赖版本 (#134)
1 parent f6f2d27 commit c5810d9

File tree

5 files changed

+50
-37
lines changed

5 files changed

+50
-37
lines changed

.github/workflows/download_dispatch.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ on:
66
JM_ALBUM_IDS:
77
type: string
88
description: 本子id(多个id用-隔开,如 '123-456-789')
9-
required: true
9+
required: false
10+
11+
JM_PHOTO_IDS:
12+
type: string
13+
description: 章节id(可以单独下载某个本子的某个章节,多个id用-隔开(同上))
14+
required: false
1015

1116
DIR_RULE:
1217
type: string
@@ -45,6 +50,7 @@ jobs:
4550
env:
4651
# 工作流输入
4752
JM_ALBUM_IDS: ${{ github.event.inputs.JM_ALBUM_IDS }}
53+
JM_PHOTO_IDS: ${{ github.event.inputs.JM_PHOTO_IDS }}
4854
DIR_RULE: ${{ github.event.inputs.DIR_RULE }}
4955
ZIP_NAME: ${{ github.event.inputs.ZIP_NAME }}
5056
UPLOAD_NAME: ${{ github.event.inputs.UPLOAD_NAME }}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
package_dir={"": "src"},
2828
python_requires=">=3.7",
2929
install_requires=[
30-
'commonX>=0.5.3',
30+
'commonX>=0.5.6',
3131
'curl_cffi',
3232
'PyYAML',
3333
'Pillow',

src/jmcomic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# 被依赖方 <--- 使用方
33
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
44

5-
__version__ = '2.2.9'
5+
__version__ = '2.2.11'
66

77
from .api import *
88
from .jm_plugin import *

src/jmcomic/cl.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
"""
1010
import os.path
11-
from typing import List
11+
from typing import List, Optional
1212

1313

1414
def get_env(name, default):
@@ -23,7 +23,7 @@ def get_env(name, default):
2323
class JmcomicUI:
2424

2525
def __init__(self) -> None:
26-
self.option_path = None
26+
self.option_path: Optional[str] = None
2727
self.raw_id_list: List[str] = []
2828
self.album_id_list: List[str] = []
2929
self.photo_id_list: List[str] = []
@@ -42,13 +42,16 @@ def parse_arg(self):
4242
parser.add_argument(
4343
'--option',
4444
help='path to the option file, you can also specify it by env `JM_OPTION_PATH`',
45-
default=get_env('JM_OPTION_PATH', './option.yml'),
45+
default=get_env('JM_OPTION_PATH', None),
4646
)
4747

4848
args = parser.parse_args()
49-
self.option_path = os.path.abspath(args.option)
50-
self.raw_id_list = args.id_list
49+
if args.option is not None:
50+
self.option_path = os.path.abspath(args.option)
51+
else:
52+
self.option_path = None
5153

54+
self.raw_id_list = args.id_list
5255
self.parse_raw_id()
5356

5457
def parse_raw_id(self):
@@ -75,17 +78,22 @@ def main(self):
7578
from .api import jm_debug
7679
jm_debug('command_line',
7780
f'start downloading...\n'
78-
f'- using option: [{self.option_path}]\n'
81+
f'- using option: [{self.option_path or "default"}]\n'
7982
f'to be downloaded: \n'
8083
f'- album: {self.album_id_list}\n'
8184
f'- photo: {self.photo_id_list}')
82-
self.run()
8385

84-
def run(self):
85-
from .api import download_album, download_photo, create_option
86-
from common import MultiTaskLauncher
86+
from .api import create_option, JmOption
87+
if self.option_path is not None:
88+
option = create_option(self.option_path)
89+
else:
90+
option = JmOption.default()
91+
92+
self.run(option)
8793

88-
option = create_option(self.option_path)
94+
def run(self, option):
95+
from .api import download_album, download_photo
96+
from common import MultiTaskLauncher
8997

9098
if len(self.album_id_list) == 0:
9199
download_photo(self.photo_id_list, option)

usage/workflow_download.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from jmcomic import *
2+
from jmcomic.cl import get_env, JmcomicUI
23

34
# 下方填入你要下载的本子的id,一行一个。
45
# 每行的首尾可以有空白字符
@@ -12,21 +13,33 @@
1213
1314
'''
1415

16+
# 单独下载章节
17+
jm_photos = '''
1518
16-
def get_jm_album_ids():
19+
20+
'''
21+
22+
23+
def get_id_set(env_name):
1724
aid_set = set()
1825
for text in [
1926
jm_albums,
20-
(get_env('JM_ALBUM_IDS') or '').replace('-', '\n'),
27+
(get_env(env_name, '')).replace('-', '\n'),
2128
]:
2229
aid_set.update(str_to_set(text))
2330

2431
return aid_set
2532

2633

2734
def main():
28-
# 下载漫画
29-
download_album(get_jm_album_ids(), option=get_option())
35+
album_id_set = get_id_set('JM_ALBUM_IDS')
36+
photo_id_set = get_id_set('JM_PHOTO_IDS')
37+
38+
helper = JmcomicUI()
39+
helper.album_id_list = list(album_id_set)
40+
helper.photo_id_list = list(photo_id_set)
41+
42+
helper.run(get_option())
3043

3144

3245
def get_option():
@@ -39,18 +52,14 @@ def get_option():
3952
# 覆盖client实现类,实现把请求错误的html下载到文件,方便GitHub Actions下载查看日志
4053
hook_debug(option)
4154

42-
# 启用 client 的缓存
43-
client = option.build_jm_client()
44-
client.enable_cache()
45-
4655
# 登录,如果有配置的话
47-
login_if_configured(client)
56+
login_if_configured(option.build_jm_client())
4857

4958
return option
5059

5160

5261
def cover_option_config(option: JmOption):
53-
dir_rule = get_env('DIR_RULE')
62+
dir_rule = get_env('DIR_RULE', None)
5463
if dir_rule is not None:
5564
the_old = option.dir_rule
5665
the_new = DirRule(dir_rule, base_dir=the_old.base_dir)
@@ -64,16 +73,16 @@ def login_if_configured(client):
6473
# 配置的方式很简单,网页上点一点就可以了
6574
# 具体做法请去看官方教程:https://docs.github.com/en/actions/security-guides/encrypted-secrets
6675
# 萌新注意!!!如果你想 `开源` 你的禁漫帐号,你也可以直接把账号密码写到下面的代码😅
67-
username = get_env('JM_USERNAME')
68-
password = get_env('JM_PASSWORD')
76+
username = get_env('JM_USERNAME', None)
77+
password = get_env('JM_PASSWORD', None)
6978
if username is not None and password is not None:
7079
client.login(username, password, True)
7180
print_eye_catching(f'登录禁漫成功')
7281

7382

7483
# noinspection PyUnusedLocal
7584
def hook_debug(option):
76-
jm_download_dir = get_env('JM_DOWNLOAD_DIR') or workspace()
85+
jm_download_dir = get_env('JM_DOWNLOAD_DIR', workspace())
7786
mkdir_if_not_exists(jm_download_dir)
7887

7988
class RaiseErrorAwareClient(JmHtmlClient):
@@ -91,15 +100,5 @@ def raise_request_error(cls, resp, msg=None):
91100
JmModuleConfig.CLASS_CLIENT_IMPL['html'] = RaiseErrorAwareClient
92101

93102

94-
def get_env(name):
95-
import os
96-
value = os.getenv(name, None)
97-
98-
if value is None or value == '':
99-
return None
100-
101-
return value
102-
103-
104103
if __name__ == '__main__':
105104
main()

0 commit comments

Comments
 (0)