novel-downloader 1.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- novel_downloader-1.1.1/LICENSE +21 -0
- novel_downloader-1.1.1/PKG-INFO +137 -0
- novel_downloader-1.1.1/README.md +67 -0
- novel_downloader-1.1.1/novel_downloader/__init__.py +14 -0
- novel_downloader-1.1.1/novel_downloader/cli/__init__.py +14 -0
- novel_downloader-1.1.1/novel_downloader/cli/clean.py +134 -0
- novel_downloader-1.1.1/novel_downloader/cli/download.py +98 -0
- novel_downloader-1.1.1/novel_downloader/cli/interactive.py +67 -0
- novel_downloader-1.1.1/novel_downloader/cli/main.py +45 -0
- novel_downloader-1.1.1/novel_downloader/cli/settings.py +177 -0
- novel_downloader-1.1.1/novel_downloader/config/__init__.py +52 -0
- novel_downloader-1.1.1/novel_downloader/config/adapter.py +150 -0
- novel_downloader-1.1.1/novel_downloader/config/loader.py +177 -0
- novel_downloader-1.1.1/novel_downloader/config/models.py +170 -0
- novel_downloader-1.1.1/novel_downloader/config/site_rules.py +97 -0
- novel_downloader-1.1.1/novel_downloader/core/__init__.py +25 -0
- novel_downloader-1.1.1/novel_downloader/core/downloaders/__init__.py +20 -0
- novel_downloader-1.1.1/novel_downloader/core/downloaders/base_downloader.py +187 -0
- novel_downloader-1.1.1/novel_downloader/core/downloaders/common_downloader.py +192 -0
- novel_downloader-1.1.1/novel_downloader/core/downloaders/qidian_downloader.py +208 -0
- novel_downloader-1.1.1/novel_downloader/core/factory/__init__.py +21 -0
- novel_downloader-1.1.1/novel_downloader/core/factory/downloader_factory.py +62 -0
- novel_downloader-1.1.1/novel_downloader/core/factory/parser_factory.py +62 -0
- novel_downloader-1.1.1/novel_downloader/core/factory/requester_factory.py +62 -0
- novel_downloader-1.1.1/novel_downloader/core/factory/saver_factory.py +49 -0
- novel_downloader-1.1.1/novel_downloader/core/interfaces/__init__.py +28 -0
- novel_downloader-1.1.1/novel_downloader/core/interfaces/downloader_protocol.py +37 -0
- novel_downloader-1.1.1/novel_downloader/core/interfaces/parser_protocol.py +40 -0
- novel_downloader-1.1.1/novel_downloader/core/interfaces/requester_protocol.py +65 -0
- novel_downloader-1.1.1/novel_downloader/core/interfaces/saver_protocol.py +61 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/__init__.py +28 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/base_parser.py +96 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/common_parser/__init__.py +14 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/common_parser/helper.py +321 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/common_parser/main_parser.py +86 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/__init__.py +20 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/browser/__init__.py +13 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/browser/chapter_encrypted.py +498 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/browser/chapter_normal.py +97 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/browser/chapter_router.py +70 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/browser/main_parser.py +110 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/session/__init__.py +13 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/session/chapter_encrypted.py +451 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/session/chapter_normal.py +119 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/session/chapter_router.py +67 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/session/main_parser.py +113 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/session/node_decryptor.py +164 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/shared/__init__.py +38 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/shared/book_info_parser.py +95 -0
- novel_downloader-1.1.1/novel_downloader/core/parsers/qidian_parser/shared/helpers.py +133 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/__init__.py +27 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/base_browser.py +210 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/base_session.py +243 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/common_requester/__init__.py +14 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/common_requester/common_session.py +126 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/qidian_requester/__init__.py +22 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/qidian_requester/qidian_broswer.py +377 -0
- novel_downloader-1.1.1/novel_downloader/core/requesters/qidian_requester/qidian_session.py +202 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/__init__.py +20 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/base_saver.py +169 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/common_saver/__init__.py +13 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/common_saver/common_epub.py +232 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/common_saver/common_txt.py +176 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/common_saver/main_saver.py +86 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/epub_utils/__init__.py +27 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/epub_utils/css_builder.py +68 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/epub_utils/initializer.py +98 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/epub_utils/text_to_html.py +132 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/epub_utils/volume_intro.py +61 -0
- novel_downloader-1.1.1/novel_downloader/core/savers/qidian_saver.py +22 -0
- novel_downloader-1.1.1/novel_downloader/locales/en.json +91 -0
- novel_downloader-1.1.1/novel_downloader/locales/zh.json +91 -0
- novel_downloader-1.1.1/novel_downloader/resources/config/rules.toml +196 -0
- novel_downloader-1.1.1/novel_downloader/resources/config/settings.yaml +70 -0
- novel_downloader-1.1.1/novel_downloader/resources/css_styles/main.css +104 -0
- novel_downloader-1.1.1/novel_downloader/resources/css_styles/volume-intro.css +56 -0
- novel_downloader-1.1.1/novel_downloader/resources/images/volume_border.png +0 -0
- novel_downloader-1.1.1/novel_downloader/resources/js_scripts/qidian_decrypt_node.js +82 -0
- novel_downloader-1.1.1/novel_downloader/resources/json/replace_word_map.json +4 -0
- novel_downloader-1.1.1/novel_downloader/resources/text/blacklist.txt +22 -0
- novel_downloader-1.1.1/novel_downloader/utils/__init__.py +0 -0
- novel_downloader-1.1.1/novel_downloader/utils/cache.py +24 -0
- novel_downloader-1.1.1/novel_downloader/utils/constants.py +158 -0
- novel_downloader-1.1.1/novel_downloader/utils/crypto_utils.py +144 -0
- novel_downloader-1.1.1/novel_downloader/utils/file_utils/__init__.py +43 -0
- novel_downloader-1.1.1/novel_downloader/utils/file_utils/io.py +252 -0
- novel_downloader-1.1.1/novel_downloader/utils/file_utils/normalize.py +68 -0
- novel_downloader-1.1.1/novel_downloader/utils/file_utils/sanitize.py +77 -0
- novel_downloader-1.1.1/novel_downloader/utils/fontocr/__init__.py +23 -0
- novel_downloader-1.1.1/novel_downloader/utils/fontocr/ocr_v1.py +304 -0
- novel_downloader-1.1.1/novel_downloader/utils/fontocr/ocr_v2.py +658 -0
- novel_downloader-1.1.1/novel_downloader/utils/hash_store.py +288 -0
- novel_downloader-1.1.1/novel_downloader/utils/hash_utils.py +103 -0
- novel_downloader-1.1.1/novel_downloader/utils/i18n.py +41 -0
- novel_downloader-1.1.1/novel_downloader/utils/logger.py +104 -0
- novel_downloader-1.1.1/novel_downloader/utils/model_loader.py +72 -0
- novel_downloader-1.1.1/novel_downloader/utils/network.py +287 -0
- novel_downloader-1.1.1/novel_downloader/utils/state.py +156 -0
- novel_downloader-1.1.1/novel_downloader/utils/text_utils/__init__.py +27 -0
- novel_downloader-1.1.1/novel_downloader/utils/text_utils/chapter_formatting.py +46 -0
- novel_downloader-1.1.1/novel_downloader/utils/text_utils/diff_display.py +75 -0
- novel_downloader-1.1.1/novel_downloader/utils/text_utils/font_mapping.py +31 -0
- novel_downloader-1.1.1/novel_downloader/utils/text_utils/text_cleaning.py +57 -0
- novel_downloader-1.1.1/novel_downloader/utils/time_utils/__init__.py +22 -0
- novel_downloader-1.1.1/novel_downloader/utils/time_utils/datetime_utils.py +146 -0
- novel_downloader-1.1.1/novel_downloader/utils/time_utils/sleep_utils.py +49 -0
- novel_downloader-1.1.1/novel_downloader.egg-info/PKG-INFO +137 -0
- novel_downloader-1.1.1/novel_downloader.egg-info/SOURCES.txt +112 -0
- novel_downloader-1.1.1/novel_downloader.egg-info/dependency_links.txt +1 -0
- novel_downloader-1.1.1/novel_downloader.egg-info/entry_points.txt +2 -0
- novel_downloader-1.1.1/novel_downloader.egg-info/requires.txt +26 -0
- novel_downloader-1.1.1/novel_downloader.egg-info/top_level.txt +1 -0
- novel_downloader-1.1.1/pyproject.toml +113 -0
- novel_downloader-1.1.1/setup.cfg +4 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Saudade Z
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,137 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: novel-downloader
|
3
|
+
Version: 1.1.1
|
4
|
+
Summary: A command-line tool for downloading Chinese web novels from Qidian and similar platforms.
|
5
|
+
Author-email: Saudade Z <saudadez217@gmail.com>
|
6
|
+
License: MIT License
|
7
|
+
|
8
|
+
Copyright (c) 2025 Saudade Z
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
27
|
+
|
28
|
+
Project-URL: Homepage, https://github.com/BowenZ217/novel-downloader
|
29
|
+
Project-URL: Source, https://github.com/BowenZ217/novel-downloader
|
30
|
+
Keywords: novel,web novel,qidian,biquge,downloader,parser,fiction,cli,automation,ebook
|
31
|
+
Classifier: Development Status :: 3 - Alpha
|
32
|
+
Classifier: Environment :: Console
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
34
|
+
Classifier: Natural Language :: Chinese (Simplified)
|
35
|
+
Classifier: Topic :: Utilities
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
37
|
+
Classifier: Programming Language :: Python :: 3.8
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
42
|
+
Requires-Python: >=3.8
|
43
|
+
Description-Content-Type: text/markdown
|
44
|
+
License-File: LICENSE
|
45
|
+
Requires-Dist: requests
|
46
|
+
Requires-Dist: beautifulsoup4
|
47
|
+
Requires-Dist: DrissionPage
|
48
|
+
Requires-Dist: pyyaml
|
49
|
+
Requires-Dist: lxml
|
50
|
+
Requires-Dist: platformdirs
|
51
|
+
Requires-Dist: click
|
52
|
+
Requires-Dist: ebooklib
|
53
|
+
Provides-Extra: dev
|
54
|
+
Requires-Dist: black; extra == "dev"
|
55
|
+
Requires-Dist: mypy; extra == "dev"
|
56
|
+
Requires-Dist: ruff; extra == "dev"
|
57
|
+
Requires-Dist: pytest; extra == "dev"
|
58
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
59
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
60
|
+
Requires-Dist: pre-commit; extra == "dev"
|
61
|
+
Requires-Dist: commitizen; extra == "dev"
|
62
|
+
Provides-Extra: font-recovery
|
63
|
+
Requires-Dist: scipy; extra == "font-recovery"
|
64
|
+
Requires-Dist: numpy; extra == "font-recovery"
|
65
|
+
Requires-Dist: tinycss2; extra == "font-recovery"
|
66
|
+
Requires-Dist: fonttools; extra == "font-recovery"
|
67
|
+
Requires-Dist: pillow; extra == "font-recovery"
|
68
|
+
Requires-Dist: huggingface_hub; extra == "font-recovery"
|
69
|
+
Dynamic: license-file
|
70
|
+
|
71
|
+
# novel-downloader
|
72
|
+
|
73
|
+
一个基于 [DrissionPage](https://www.drissionpage.cn) 和 [requests](https://github.com/psf/requests) 的小说下载器。
|
74
|
+
|
75
|
+
---
|
76
|
+
|
77
|
+
## 项目简介
|
78
|
+
|
79
|
+
**novel-downloader** 是一个通用的小说下载库 / CLI 工具,
|
80
|
+
- 大多数支持的站点仅依赖 [`requests`](https://github.com/psf/requests) 进行 HTTP 抓取
|
81
|
+
- 对于起点中文网 (Qidian), 可在配置中选择:
|
82
|
+
- `mode: session` : 纯 Requests 模式
|
83
|
+
- `mode: browser` : 基于 DrissionPage 驱动 Chrome 的浏览器模式 (可处理更复杂的 JS/加密)。
|
84
|
+
- 如果在 `browser` 模式下且 `login_required: true`, 首次运行会自动打开浏览器, 请完成登录后继续。
|
85
|
+
|
86
|
+
**快速开始**
|
87
|
+
|
88
|
+
```bash
|
89
|
+
# 克隆 + 安装
|
90
|
+
git clone https://github.com/BowenZ217/novel-downloader.git
|
91
|
+
cd novel-downloader
|
92
|
+
pip install .
|
93
|
+
# 或 pip install .[font-recovery]
|
94
|
+
|
95
|
+
# 初始化默认配置
|
96
|
+
novel-cli settings init
|
97
|
+
|
98
|
+
# 编辑 ./settings.yaml 完成 site/book_ids 等, 可查看 docs/4-settings-schema.md
|
99
|
+
# 运行下载
|
100
|
+
novel-cli download 123456
|
101
|
+
```
|
102
|
+
|
103
|
+
更多使用方法, 查看 [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
|
104
|
+
|
105
|
+
---
|
106
|
+
|
107
|
+
## 功能特性
|
108
|
+
|
109
|
+
- 爬取起点中文网的小说章节内容 (支持免费与已订阅章节)
|
110
|
+
- 自动整合所有章节并输出为完整的 TXT 文件
|
111
|
+
- 支持活动广告过滤:
|
112
|
+
- [x] 章节标题
|
113
|
+
- [ ] 章节正文
|
114
|
+
- [ ] 作者说
|
115
|
+
|
116
|
+
---
|
117
|
+
|
118
|
+
## 文档结构
|
119
|
+
|
120
|
+
- [项目简介](#项目简介)
|
121
|
+
- [安装](https://github.com/BowenZ217/novel-downloader/blob/main/docs/1-installation.md)
|
122
|
+
- [环境准备](https://github.com/BowenZ217/novel-downloader/blob/main/docs/2-environment-setup.md)
|
123
|
+
- [配置](https://github.com/BowenZ217/novel-downloader/blob/main/docs/3-configuration.md)
|
124
|
+
- [settings.yaml 配置说明](https://github.com/BowenZ217/novel-downloader/blob/main/docs/4-settings-schema.md)
|
125
|
+
- [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
|
126
|
+
- [文件保存](https://github.com/BowenZ217/novel-downloader/blob/main/docs/file-saving.md)
|
127
|
+
- [TODO](https://github.com/BowenZ217/novel-downloader/blob/main/docs/todo.md)
|
128
|
+
- [开发](https://github.com/BowenZ217/novel-downloader/blob/main/docs/develop.md)
|
129
|
+
- [项目说明](#项目说明)
|
130
|
+
|
131
|
+
---
|
132
|
+
|
133
|
+
## 项目说明
|
134
|
+
|
135
|
+
- 本项目仅供学习和研究使用, 不得用于任何商业或违法用途。请遵守目标网站的 robots.txt 以及相关法律法规。
|
136
|
+
- 本项目开发者对因使用该工具所引起的任何法律责任不承担任何责任。
|
137
|
+
- 如果遇到网站结构变化或其他问题, 可能导致程序无法正常工作, 请自行调整代码或寻找其他解决方案。
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# novel-downloader
|
2
|
+
|
3
|
+
一个基于 [DrissionPage](https://www.drissionpage.cn) 和 [requests](https://github.com/psf/requests) 的小说下载器。
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
## 项目简介
|
8
|
+
|
9
|
+
**novel-downloader** 是一个通用的小说下载库 / CLI 工具,
|
10
|
+
- 大多数支持的站点仅依赖 [`requests`](https://github.com/psf/requests) 进行 HTTP 抓取
|
11
|
+
- 对于起点中文网 (Qidian), 可在配置中选择:
|
12
|
+
- `mode: session` : 纯 Requests 模式
|
13
|
+
- `mode: browser` : 基于 DrissionPage 驱动 Chrome 的浏览器模式 (可处理更复杂的 JS/加密)。
|
14
|
+
- 如果在 `browser` 模式下且 `login_required: true`, 首次运行会自动打开浏览器, 请完成登录后继续。
|
15
|
+
|
16
|
+
**快速开始**
|
17
|
+
|
18
|
+
```bash
|
19
|
+
# 克隆 + 安装
|
20
|
+
git clone https://github.com/BowenZ217/novel-downloader.git
|
21
|
+
cd novel-downloader
|
22
|
+
pip install .
|
23
|
+
# 或 pip install .[font-recovery]
|
24
|
+
|
25
|
+
# 初始化默认配置
|
26
|
+
novel-cli settings init
|
27
|
+
|
28
|
+
# 编辑 ./settings.yaml 完成 site/book_ids 等, 可查看 docs/4-settings-schema.md
|
29
|
+
# 运行下载
|
30
|
+
novel-cli download 123456
|
31
|
+
```
|
32
|
+
|
33
|
+
更多使用方法, 查看 [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
|
34
|
+
|
35
|
+
---
|
36
|
+
|
37
|
+
## 功能特性
|
38
|
+
|
39
|
+
- 爬取起点中文网的小说章节内容 (支持免费与已订阅章节)
|
40
|
+
- 自动整合所有章节并输出为完整的 TXT 文件
|
41
|
+
- 支持活动广告过滤:
|
42
|
+
- [x] 章节标题
|
43
|
+
- [ ] 章节正文
|
44
|
+
- [ ] 作者说
|
45
|
+
|
46
|
+
---
|
47
|
+
|
48
|
+
## 文档结构
|
49
|
+
|
50
|
+
- [项目简介](#项目简介)
|
51
|
+
- [安装](https://github.com/BowenZ217/novel-downloader/blob/main/docs/1-installation.md)
|
52
|
+
- [环境准备](https://github.com/BowenZ217/novel-downloader/blob/main/docs/2-environment-setup.md)
|
53
|
+
- [配置](https://github.com/BowenZ217/novel-downloader/blob/main/docs/3-configuration.md)
|
54
|
+
- [settings.yaml 配置说明](https://github.com/BowenZ217/novel-downloader/blob/main/docs/4-settings-schema.md)
|
55
|
+
- [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
|
56
|
+
- [文件保存](https://github.com/BowenZ217/novel-downloader/blob/main/docs/file-saving.md)
|
57
|
+
- [TODO](https://github.com/BowenZ217/novel-downloader/blob/main/docs/todo.md)
|
58
|
+
- [开发](https://github.com/BowenZ217/novel-downloader/blob/main/docs/develop.md)
|
59
|
+
- [项目说明](#项目说明)
|
60
|
+
|
61
|
+
---
|
62
|
+
|
63
|
+
## 项目说明
|
64
|
+
|
65
|
+
- 本项目仅供学习和研究使用, 不得用于任何商业或违法用途。请遵守目标网站的 robots.txt 以及相关法律法规。
|
66
|
+
- 本项目开发者对因使用该工具所引起的任何法律责任不承担任何责任。
|
67
|
+
- 如果遇到网站结构变化或其他问题, 可能导致程序无法正常工作, 请自行调整代码或寻找其他解决方案。
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
"""
|
4
|
+
novel_downloader
|
5
|
+
----------------
|
6
|
+
|
7
|
+
Core package for the Novel Downloader project.
|
8
|
+
"""
|
9
|
+
|
10
|
+
__version__ = "1.1.1"
|
11
|
+
|
12
|
+
__author__ = "Saudade Z"
|
13
|
+
__email__ = "saudadez217@gmail.com"
|
14
|
+
__license__ = "MIT"
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
"""
|
4
|
+
novel_downloader.cli.clean
|
5
|
+
-----------------------------
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
import shutil
|
10
|
+
from pathlib import Path
|
11
|
+
from typing import List, Optional
|
12
|
+
|
13
|
+
import click
|
14
|
+
|
15
|
+
from novel_downloader.utils.constants import (
|
16
|
+
CONFIG_DIR,
|
17
|
+
DATA_DIR,
|
18
|
+
JS_SCRIPT_DIR,
|
19
|
+
LOGGER_DIR,
|
20
|
+
MODEL_CACHE_DIR,
|
21
|
+
REC_CHAR_MODEL_REPO,
|
22
|
+
STATE_DIR,
|
23
|
+
)
|
24
|
+
from novel_downloader.utils.i18n import t
|
25
|
+
|
26
|
+
|
27
|
+
def delete_path(p: Path) -> None:
|
28
|
+
if p.exists():
|
29
|
+
if p.is_file():
|
30
|
+
p.unlink()
|
31
|
+
else:
|
32
|
+
shutil.rmtree(p, ignore_errors=True)
|
33
|
+
click.echo(f"[clean] {t('clean_deleted')}: {p}")
|
34
|
+
else:
|
35
|
+
click.echo(f"[clean] {t('clean_not_found')}: {p}")
|
36
|
+
|
37
|
+
|
38
|
+
def clean_model_repo_cache(repo_id: Optional[str] = None, all: bool = False) -> bool:
|
39
|
+
"""
|
40
|
+
Delete Hugging Face cache for a specific repo.
|
41
|
+
"""
|
42
|
+
from huggingface_hub import scan_cache_dir
|
43
|
+
|
44
|
+
cache_info = scan_cache_dir()
|
45
|
+
|
46
|
+
if all:
|
47
|
+
targets = cache_info.repos
|
48
|
+
elif repo_id:
|
49
|
+
targets = [r for r in cache_info.repos if r.repo_id == repo_id]
|
50
|
+
else:
|
51
|
+
return False
|
52
|
+
|
53
|
+
strategy = cache_info.delete_revisions(
|
54
|
+
*[rev.commit_hash for r in targets for rev in r.revisions]
|
55
|
+
)
|
56
|
+
print(f"[clean] Will free {strategy.expected_freed_size_str}")
|
57
|
+
strategy.execute()
|
58
|
+
return True
|
59
|
+
|
60
|
+
|
61
|
+
@click.command(name="clean", help=t("help_clean")) # type: ignore
|
62
|
+
@click.option("--logs", is_flag=True, help=t("clean_logs")) # type: ignore
|
63
|
+
@click.option("--cache", is_flag=True, help=t("clean_cache")) # type: ignore
|
64
|
+
@click.option("--state", is_flag=True, help=t("clean_state")) # type: ignore
|
65
|
+
@click.option("--data", is_flag=True, help=t("clean_data")) # type: ignore
|
66
|
+
@click.option("--config", is_flag=True, help=t("clean_config")) # type: ignore
|
67
|
+
@click.option("--models", is_flag=True, help=t("clean_models")) # type: ignore
|
68
|
+
@click.option("--hf-cache", is_flag=True, help=t("clean_hf_cache")) # type: ignore
|
69
|
+
@click.option("--hf-cache-all", is_flag=True, help=t("clean_hf_cache_all")) # type: ignore
|
70
|
+
@click.option("--all", is_flag=True, help=t("clean_all")) # type: ignore
|
71
|
+
@click.option("--yes", is_flag=True, help=t("clean_yes")) # type: ignore
|
72
|
+
def clean_cli(
|
73
|
+
logs: bool,
|
74
|
+
cache: bool,
|
75
|
+
state: bool,
|
76
|
+
data: bool,
|
77
|
+
config: bool,
|
78
|
+
models: bool,
|
79
|
+
hf_cache: bool,
|
80
|
+
hf_cache_all: bool,
|
81
|
+
all: bool,
|
82
|
+
yes: bool,
|
83
|
+
) -> None:
|
84
|
+
targets: List[Path] = []
|
85
|
+
|
86
|
+
if all:
|
87
|
+
if not yes:
|
88
|
+
confirm = click.prompt(t("clean_confirm"), default="n")
|
89
|
+
if confirm.lower() != "y":
|
90
|
+
click.echo(t("clean_cancelled"))
|
91
|
+
return
|
92
|
+
targets = [
|
93
|
+
LOGGER_DIR,
|
94
|
+
JS_SCRIPT_DIR,
|
95
|
+
STATE_DIR,
|
96
|
+
DATA_DIR,
|
97
|
+
CONFIG_DIR,
|
98
|
+
MODEL_CACHE_DIR,
|
99
|
+
]
|
100
|
+
else:
|
101
|
+
if logs:
|
102
|
+
targets.append(LOGGER_DIR)
|
103
|
+
if cache:
|
104
|
+
targets.append(JS_SCRIPT_DIR)
|
105
|
+
if state:
|
106
|
+
targets.append(STATE_DIR)
|
107
|
+
if data:
|
108
|
+
targets.append(DATA_DIR)
|
109
|
+
if config:
|
110
|
+
targets.append(CONFIG_DIR)
|
111
|
+
if models:
|
112
|
+
targets.append(MODEL_CACHE_DIR)
|
113
|
+
|
114
|
+
if hf_cache_all:
|
115
|
+
try:
|
116
|
+
if clean_model_repo_cache(all=True):
|
117
|
+
click.echo(t("clean_hf_cache_all_done"))
|
118
|
+
except Exception as e:
|
119
|
+
click.echo(t("clean_hf_cache_all_fail", err=e))
|
120
|
+
elif hf_cache:
|
121
|
+
try:
|
122
|
+
if clean_model_repo_cache(REC_CHAR_MODEL_REPO):
|
123
|
+
click.echo(t("clean_hf_model_done", repo=REC_CHAR_MODEL_REPO))
|
124
|
+
else:
|
125
|
+
click.echo(t("clean_hf_model_not_found", repo=REC_CHAR_MODEL_REPO))
|
126
|
+
except Exception as e:
|
127
|
+
click.echo(t("clean_hf_model_fail", err=e))
|
128
|
+
|
129
|
+
if not targets and not hf_cache and not hf_cache_all:
|
130
|
+
click.echo(t("clean_nothing"))
|
131
|
+
return
|
132
|
+
|
133
|
+
for path in targets:
|
134
|
+
delete_path(path)
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
"""
|
4
|
+
novel_downloader.cli.download
|
5
|
+
-----------------------------
|
6
|
+
|
7
|
+
Download full novels by book IDs
|
8
|
+
(supports config files, site switching, and localization prompts).
|
9
|
+
"""
|
10
|
+
|
11
|
+
from typing import List
|
12
|
+
|
13
|
+
import click
|
14
|
+
from click import Context
|
15
|
+
|
16
|
+
from novel_downloader.config import ConfigAdapter, load_config
|
17
|
+
from novel_downloader.core import (
|
18
|
+
get_downloader,
|
19
|
+
get_parser,
|
20
|
+
get_requester,
|
21
|
+
get_saver,
|
22
|
+
)
|
23
|
+
from novel_downloader.utils.i18n import t
|
24
|
+
from novel_downloader.utils.logger import setup_logging
|
25
|
+
|
26
|
+
|
27
|
+
@click.command(
|
28
|
+
name="download",
|
29
|
+
help=t("download_help"),
|
30
|
+
short_help=t("download_short_help"),
|
31
|
+
) # type: ignore
|
32
|
+
@click.argument("book_ids", nargs=-1) # type: ignore
|
33
|
+
@click.option(
|
34
|
+
"--site",
|
35
|
+
default="qidian",
|
36
|
+
show_default=True,
|
37
|
+
help=t("download_option_site", default="qidian"),
|
38
|
+
) # type: ignore
|
39
|
+
@click.pass_context # type: ignore
|
40
|
+
def download_cli(ctx: Context, book_ids: List[str], site: str) -> None:
|
41
|
+
"""Download full novels by book IDs."""
|
42
|
+
config_path = ctx.obj.get("config_path")
|
43
|
+
|
44
|
+
click.echo(t("download_using_config", path=config_path))
|
45
|
+
click.echo(t("download_site_info", site=site))
|
46
|
+
|
47
|
+
config_data = load_config(config_path)
|
48
|
+
adapter = ConfigAdapter(config=config_data, site=site)
|
49
|
+
|
50
|
+
# Retrieve each sub-component's configuration from the adapter
|
51
|
+
requester_cfg = adapter.get_requester_config()
|
52
|
+
downloader_cfg = adapter.get_downloader_config()
|
53
|
+
parser_cfg = adapter.get_parser_config()
|
54
|
+
saver_cfg = adapter.get_saver_config()
|
55
|
+
|
56
|
+
# If no book_ids provided on the command line, try to load them from config
|
57
|
+
if not book_ids:
|
58
|
+
try:
|
59
|
+
book_ids = adapter.get_book_ids()
|
60
|
+
except Exception as e:
|
61
|
+
click.echo(t("download_fail_get_ids", err=e))
|
62
|
+
return
|
63
|
+
|
64
|
+
# Filter out placeholder/example IDs
|
65
|
+
invalid_ids = {"0000000000"}
|
66
|
+
valid_book_ids = [bid for bid in book_ids if bid not in invalid_ids]
|
67
|
+
|
68
|
+
if not book_ids:
|
69
|
+
click.echo(t("download_no_ids"))
|
70
|
+
return
|
71
|
+
|
72
|
+
if not valid_book_ids:
|
73
|
+
click.echo(t("download_only_example", example="0000000000"))
|
74
|
+
click.echo(t("download_edit_config"))
|
75
|
+
return
|
76
|
+
|
77
|
+
# Initialize the requester, parser, saver, and downloader components
|
78
|
+
curr_requester = get_requester(site, requester_cfg)
|
79
|
+
curr_parser = get_parser(site, parser_cfg)
|
80
|
+
curr_saver = get_saver(site, saver_cfg)
|
81
|
+
setup_logging()
|
82
|
+
curr_downloader = get_downloader(
|
83
|
+
requester=curr_requester,
|
84
|
+
parser=curr_parser,
|
85
|
+
saver=curr_saver,
|
86
|
+
site=site,
|
87
|
+
config=downloader_cfg,
|
88
|
+
)
|
89
|
+
|
90
|
+
# Perform the download for each valid book ID
|
91
|
+
for book_id in book_ids:
|
92
|
+
click.echo(t("download_downloading", book_id=book_id, site=site))
|
93
|
+
curr_downloader.download_one(book_id)
|
94
|
+
|
95
|
+
# Prompt for parsing and wait for user input before shutting down
|
96
|
+
if requester_cfg.auto_close:
|
97
|
+
input(t("download_prompt_parse"))
|
98
|
+
curr_requester.shutdown()
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
"""
|
4
|
+
novel_downloader.cli.interactive
|
5
|
+
--------------------------------
|
6
|
+
|
7
|
+
Interactive CLI mode for novel_downloader.
|
8
|
+
Supports multilingual prompt, input validation, and quit control.
|
9
|
+
"""
|
10
|
+
|
11
|
+
import click
|
12
|
+
from click import Context
|
13
|
+
|
14
|
+
from novel_downloader.cli.download import download_cli
|
15
|
+
from novel_downloader.utils.i18n import t
|
16
|
+
|
17
|
+
|
18
|
+
@click.group( # type: ignore
|
19
|
+
name="interactive", help=t("interactive_help"), invoke_without_command=True
|
20
|
+
)
|
21
|
+
@click.pass_context # type: ignore
|
22
|
+
def interactive_cli(ctx: Context) -> None:
|
23
|
+
"""Interactive mode for novel selection and preview."""
|
24
|
+
if ctx.invoked_subcommand is None:
|
25
|
+
click.echo(t("interactive_no_sub"))
|
26
|
+
|
27
|
+
options = [
|
28
|
+
t("interactive_option_download"),
|
29
|
+
t("interactive_option_browse"),
|
30
|
+
t("interactive_option_preview"),
|
31
|
+
t("interactive_option_exit"),
|
32
|
+
]
|
33
|
+
for idx, opt in enumerate(options, 1):
|
34
|
+
click.echo(f"{idx}. {opt}")
|
35
|
+
|
36
|
+
choice = click.prompt(t("interactive_prompt_choice"), type=int)
|
37
|
+
|
38
|
+
if choice == 1:
|
39
|
+
default_site = "qidian"
|
40
|
+
site: str = click.prompt(
|
41
|
+
t("download_option_site", default=default_site),
|
42
|
+
default_site,
|
43
|
+
)
|
44
|
+
ids_input: str = click.prompt(t("interactive_prompt_book_ids"))
|
45
|
+
book_ids = ids_input.strip().split()
|
46
|
+
ctx.invoke(download_cli, book_ids=book_ids, site=site)
|
47
|
+
elif choice == 2:
|
48
|
+
ctx.invoke(browse)
|
49
|
+
elif choice == 3:
|
50
|
+
ctx.invoke(preview)
|
51
|
+
else:
|
52
|
+
click.echo(t("interactive_exit"))
|
53
|
+
return
|
54
|
+
|
55
|
+
|
56
|
+
@interactive_cli.command(help=t("interactive_browse_help")) # type: ignore
|
57
|
+
@click.pass_context # type: ignore
|
58
|
+
def browse(ctx: Context) -> None:
|
59
|
+
"""Browse available novels interactively."""
|
60
|
+
click.echo(t("interactive_browse_start"))
|
61
|
+
|
62
|
+
|
63
|
+
@interactive_cli.command(help=t("interactive_preview_help")) # type: ignore
|
64
|
+
@click.pass_context # type: ignore
|
65
|
+
def preview(ctx: Context) -> None:
|
66
|
+
"""Preview chapters before downloading."""
|
67
|
+
click.echo(t("interactive_preview_start"))
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
"""
|
4
|
+
novel_downloader.cli.main
|
5
|
+
--------------------------
|
6
|
+
|
7
|
+
Unified CLI entry point. Parses arguments and delegates to parser or interactive.
|
8
|
+
"""
|
9
|
+
|
10
|
+
from typing import Optional
|
11
|
+
|
12
|
+
import click
|
13
|
+
from click import Context
|
14
|
+
|
15
|
+
from novel_downloader.cli import clean, download, interactive, settings
|
16
|
+
from novel_downloader.utils.i18n import t
|
17
|
+
|
18
|
+
|
19
|
+
@click.group(help=t("cli_help"), invoke_without_command=True) # type: ignore
|
20
|
+
@click.option(
|
21
|
+
"--config",
|
22
|
+
type=click.Path(exists=True, dir_okay=False, resolve_path=True),
|
23
|
+
default=None,
|
24
|
+
help=t("help_config"),
|
25
|
+
) # type: ignore
|
26
|
+
@click.pass_context # type: ignore
|
27
|
+
def cli_main(ctx: Context, config: Optional[str]) -> None:
|
28
|
+
"""Novel Downloader CLI."""
|
29
|
+
ctx.ensure_object(dict)
|
30
|
+
ctx.obj["config_path"] = config
|
31
|
+
|
32
|
+
if ctx.invoked_subcommand is None:
|
33
|
+
click.echo(t("main_no_command"))
|
34
|
+
ctx.invoke(interactive.interactive_cli)
|
35
|
+
|
36
|
+
|
37
|
+
# Register subcommands
|
38
|
+
cli_main.add_command(clean.clean_cli)
|
39
|
+
cli_main.add_command(download.download_cli)
|
40
|
+
cli_main.add_command(interactive.interactive_cli)
|
41
|
+
cli_main.add_command(settings.settings_cli)
|
42
|
+
|
43
|
+
|
44
|
+
if __name__ == "__main__":
|
45
|
+
cli_main()
|