Skip to content

Commit 7b2e997

Browse files
authored
v2.1.4: 工作流优化,支持在Actions页面直接提交要下载的本子 (#80)
1 parent 36f02c4 commit 7b2e997

File tree

7 files changed

+115
-10
lines changed

7 files changed

+115
-10
lines changed

.github/workflows/download.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: 下载JM本子
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches-ignore:
67
- 'master' # master专门用于发布pip和repo介绍
@@ -40,6 +41,7 @@ jobs:
4041
pip install -e ./
4142
4243
- name: 运行下载脚本
44+
continue-on-error: true
4345
run: |
4446
cd ./usage/
4547
python workflow_download.py
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: 下载JM本子(dispatch)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
JM_ALBUM_IDS:
7+
type: string
8+
description: 本子id(多个id用-隔开,如 '123-456-789')
9+
required: true
10+
default: ''
11+
12+
ZIP_NAME:
13+
type: string
14+
default: 本子.tar.gz
15+
description: 压缩文件名称
16+
required: false
17+
18+
UPLOAD_NAME:
19+
type: string
20+
default: 下载完成的本子
21+
description: 上传文件名称
22+
required: false
23+
24+
# JM_USERNAME:
25+
# type: string
26+
# default: ''
27+
# description: '禁漫帐号(不建议使用,用户名和密码会泄露在日志中。最好用secrets)'
28+
# required: false
29+
#
30+
# JM_PASSWORD:
31+
# type: string
32+
# default: ''
33+
# description: '禁漫密码(不建议使用,用户名和密码会泄露在日志中。最好用secrets)'
34+
# required: false
35+
36+
37+
jobs:
38+
crawler:
39+
runs-on: ubuntu-latest
40+
env:
41+
# 工作流输入
42+
JM_ALBUM_IDS: ${{ github.event.inputs.JM_ALBUM_IDS }}
43+
JM_USERNAME: ${{ secrets.JM_USERNAME }}
44+
JM_PASSWORD: ${{ secrets.JM_PASSWORD }}
45+
ZIP_NAME: ${{ github.event.inputs.ZIP_NAME }}
46+
UPLOAD_NAME: ${{ github.event.inputs.UPLOAD_NAME }}
47+
# JM_USERNAME: ${{ github.event.inputs.JM_USERNAME }}
48+
# JM_PASSWORD: ${{ github.event.inputs.JM_PASSWORD }}
49+
50+
# 固定值
51+
JM_DOWNLOAD_DIR: /home/runner/work/jmcomic/download/
52+
53+
steps:
54+
- uses: actions/checkout@v3
55+
- name: Set up Python 3.11
56+
uses: actions/setup-python@v4
57+
with:
58+
python-version: "3.11"
59+
60+
- name: 安装依赖项(pip)
61+
if: ${{ github.ref != 'refs/heads/dev' }}
62+
run: |
63+
python -m pip install --upgrade pip
64+
pip install jmcomic -i https://pypi.org/project --upgrade
65+
66+
- name: 安装依赖项(local)
67+
if: ${{ github.ref == 'refs/heads/dev' }}
68+
run: |
69+
python -m pip install --upgrade pip
70+
pip install commonX -i https://pypi.org/project --upgrade
71+
pip install -e ./
72+
73+
- name: 运行下载脚本
74+
continue-on-error: true
75+
run: |
76+
cd ./usage/
77+
python workflow_download.py
78+
79+
- name: 压缩文件
80+
run: |
81+
cd $JM_DOWNLOAD_DIR
82+
tar -zcvf ../$ZIP_NAME ./
83+
mv ../$ZIP_NAME .
84+
85+
- name: 上传结果
86+
uses: actions/upload-artifact@v3
87+
with:
88+
name: ${{ env.UPLOAD_NAME }}
89+
path: ${{ env.JM_DOWNLOAD_DIR }}/${{ env.ZIP_NAME }}
90+
if-no-files-found: error
91+
retention-days: 90

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: 发布PYPI
22

33
on:
4+
workflow_dispatch:
45
release:
56
types: [ published ]
67

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: 跑测试
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches: [ "dev" ]
67
paths-ignore:

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.1.3'
5+
__version__ = '2.1.4'
66

77
from .api import *

src/jmcomic/api.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,17 @@ def download_image(index, image: JmImageDetail, debug_topic='image'):
116116
f'图片下载完成: {debug_tag}, [{image.img_url}] → [{img_save_path}]'
117117
)
118118

119-
length = len(photo_detail)
120-
# 根据图片数,决定下载策略
121-
if length <= option.download_threading_batch_count:
122-
# 如果图片数小的话,直接使用多线程下载,一张图一个线程。
119+
batch = option.download_threading_batch_count
120+
if batch <= 0:
123121
multi_thread_launcher(
124122
iter_objs=enumerate(photo_detail),
125123
apply_each_obj_func=download_image,
126124
)
127125
else:
128-
# 如果图片数多的话,还是分批下载。
129-
multi_task_launcher_batch(
126+
thread_pool_executor(
130127
iter_objs=enumerate(photo_detail),
131128
apply_each_obj_func=download_image,
132-
batch_size=option.download_threading_batch_count
129+
max_workers=batch,
133130
)
134131

135132

usage/workflow_download.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@
99
'''
1010

1111

12+
def get_jm_album_ids():
13+
from common import str_to_set
14+
15+
aid_set = set()
16+
for text in [
17+
jm_albums,
18+
(get_env('JM_ALBUM_IDS') or '').replace('-', '\n'),
19+
]:
20+
aid_set.update(str_to_set(text))
21+
22+
return aid_set
23+
24+
1225
def main():
13-
from jmcomic import str_to_list, download_album
26+
from jmcomic import download_album
1427
# 下载漫画
15-
download_album(str_to_list(jm_albums), option=get_option())
28+
download_album(get_jm_album_ids(), option=get_option())
1629

1730

1831
def get_option():

0 commit comments

Comments
 (0)