Skip to content

Commit 1ed1cac

Browse files
authored
下载本子Actions增加合并pdf的选项,更新文档 (hect0x7#489)
1 parent 92f8b26 commit 1ed1cac

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

.github/workflows/download_dispatch.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ on:
3131
default: ''
3232
required: false
3333

34+
PDF_OPTION:
35+
description: '是否要下载后将图片合并为pdf文件'
36+
required: false
37+
type: choice
38+
options:
39+
-
40+
- 是 | 本子维度合并pdf
41+
- 是 | 章节维度合并pdf
42+
3443
ZIP_NAME:
3544
type: string
3645
default: 本子.tar.gz
@@ -68,6 +77,7 @@ jobs:
6877
ZIP_NAME: ${{ github.event.inputs.ZIP_NAME }}
6978
UPLOAD_NAME: ${{ github.event.inputs.UPLOAD_NAME }}
7079
IMAGE_SUFFIX: ${{ github.event.inputs.IMAGE_SUFFIX }}
80+
PDF_OPTION: ${{ github.event.inputs.PDF_OPTION }}
7181

7282
# 登录相关secrets
7383
JM_USERNAME: ${{ secrets.JM_USERNAME }}
@@ -95,6 +105,11 @@ jobs:
95105
python -m pip install --upgrade pip
96106
pip install -r requirements-dev.txt
97107
108+
- name: Install img2pdf
109+
if: inputs.PDF_OPTION != '否'
110+
run: |
111+
pip install img2pdf
112+
98113
- name: 安装jmcomic(pip)
99114
if: ${{ github.ref != 'refs/heads/dev' }}
100115
run: |

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1-
# Python API For JMComic (禁漫天堂)
1+
<!-- 顶部标题 & 统计徽章 -->
2+
<div align="center">
3+
<h1 style="margin-top: 0" align="center">Python API for JMComic</h1>
4+
<p align="center">
5+
<strong>提供 Python API 访问禁漫天堂(网页端 & 移动端),集成 GitHub Actions 下载器🚀</strong>
6+
</p>
27

3-
本项目封装了一套可用于爬取JM的Python API.
8+
[![GitHub](https://img.shields.io/badge/-GitHub-181717?logo=github)](https://github.com/hect0x7)
9+
[![Stars](https://img.shields.io/github/stars/hect0x7/JMComic-Crawler-Python?color=orange&label=stars&style=flat)](https://github.com/hect0x7/JMComic-Crawler-Python/stargazers)
10+
[![Forks](https://img.shields.io/github/forks/hect0x7/JMComic-Crawler-Python?color=green&label=forks&style=flat)](https://github.com/hect0x7/JMComic-Crawler-Python/forks)
11+
[![GitHub latest releases](https://img.shields.io/github/v/release/hect0x7/JMComic-Crawler-Python?color=blue&label=version)](https://github.com/hect0x7/JMComic-Crawler-Python/releases/latest)
12+
[![PyPI - Downloads](https://img.shields.io/pypi/dm/jmcomic?style=flat&color=hotpink)](https://pepy.tech/projects/jmcomic)
13+
[![Licence](https://img.shields.io/github/license/hect0x7/JMComic-Crawler-Python?color=red)](https://github.com/hect0x7/JMComic-Crawler-Python)
414

5-
你可以通过简单的几行Python代码,实现下载JM上的本子到本地,并且是处理好的图片。
15+
</div>
16+
17+
18+
19+
20+
> 本项目封装了一套可用于爬取JM的Python API.
21+
>
22+
> 你可以通过简单的几行Python代码,实现下载JM上的本子到本地,并且是处理好的图片。
23+
>
24+
> **友情提示:珍爱JM,为了减轻JM的服务器压力,请不要一次性爬取太多本子,西门🙏🙏🙏**.
625
726
[【指路】教程:使用GitHub Actions下载禁漫本子](./assets/docs/sources/tutorial/1_github_actions.md)
827

928
[【指路】教程:导出并下载你的禁漫收藏夹数据](./assets/docs/sources/tutorial/10_export_favorites.md)
1029

11-
**友情提示:珍爱JM,为了减轻JM的服务器压力,请不要一次性爬取太多本子,西门🙏🙏🙏**.
1230

1331
## 项目介绍
1432

@@ -47,11 +65,11 @@
4765

4866
### 1. 下载本子方法
4967

50-
只需要使用如下代码,就可以下载本子`JM422866`的所有章节的图片:
68+
只需要使用如下代码,就可以下载本子`JM123`的所有章节的图片:
5169

5270
```python
5371
import jmcomic # 导入此模块,需要先安装.
54-
jmcomic.download_album('422866') # 传入要下载的album的id,即可下载整个album到本地.
72+
jmcomic.download_album('123') # 传入要下载的album的id,即可下载整个album到本地.
5573
```
5674

5775
上面的 `download_album`方法还有一个参数`option`,可用于控制下载配置,配置包括禁漫域名、网络代理、图片格式转换、插件等等。
@@ -80,8 +98,8 @@ import jmcomic
8098
# 创建配置对象
8199
option = jmcomic.create_option_by_file('你的配置文件路径,例如 D:/option.yml')
82100
# 使用option对象来下载本子
83-
jmcomic.download_album(422866, option)
84-
# 等价写法: option.download_album(422866)
101+
jmcomic.download_album(123, option)
102+
# 等价写法: option.download_album(123)
85103
```
86104

87105
### 3. 使用命令行
@@ -91,10 +109,10 @@ jmcomic.download_album(422866, option)
91109
92110
示例:
93111

94-
下载本子422866的命令
112+
下载本子123的命令
95113

96114
```sh
97-
jmcomic 422866
115+
jmcomic 123
98116
```
99117
同时下载本子123, 章节456的命令
100118
```sh

usage/workflow_download.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ def cover_option_config(option: JmOption):
8181
if suffix is not None:
8282
option.download.image.suffix = fix_suffix(suffix)
8383

84+
pdf_option = env('PDF_OPTION', None)
85+
if pdf_option and pdf_option != '否':
86+
call_when = 'after_album' if pdf_option == '是 | 本子维度合并pdf' else 'after_photo'
87+
plugin = [{
88+
'plugin': Img2pdfPlugin.plugin_key,
89+
'kwargs': {
90+
'pdf_dir': option.dir_rule.base_dir + '/pdf/',
91+
'filename_rule': call_when[6].upper() + 'id',
92+
'delete_original_file': True,
93+
}
94+
}]
95+
option.plugins[call_when] = plugin
96+
8497

8598
def log_before_raise():
8699
jm_download_dir = env('JM_DOWNLOAD_DIR', workspace())

0 commit comments

Comments
 (0)