novel-downloader 1.1.0__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.
Files changed (120) hide show
  1. novel_downloader-1.1.0/LICENSE +21 -0
  2. novel_downloader-1.1.0/PKG-INFO +157 -0
  3. novel_downloader-1.1.0/README.md +85 -0
  4. novel_downloader-1.1.0/novel_downloader/__init__.py +14 -0
  5. novel_downloader-1.1.0/novel_downloader/cli/__init__.py +14 -0
  6. novel_downloader-1.1.0/novel_downloader/cli/clean.py +134 -0
  7. novel_downloader-1.1.0/novel_downloader/cli/download.py +132 -0
  8. novel_downloader-1.1.0/novel_downloader/cli/interactive.py +67 -0
  9. novel_downloader-1.1.0/novel_downloader/cli/main.py +45 -0
  10. novel_downloader-1.1.0/novel_downloader/cli/settings.py +177 -0
  11. novel_downloader-1.1.0/novel_downloader/config/__init__.py +52 -0
  12. novel_downloader-1.1.0/novel_downloader/config/adapter.py +153 -0
  13. novel_downloader-1.1.0/novel_downloader/config/loader.py +177 -0
  14. novel_downloader-1.1.0/novel_downloader/config/models.py +173 -0
  15. novel_downloader-1.1.0/novel_downloader/config/site_rules.py +97 -0
  16. novel_downloader-1.1.0/novel_downloader/core/__init__.py +25 -0
  17. novel_downloader-1.1.0/novel_downloader/core/downloaders/__init__.py +22 -0
  18. novel_downloader-1.1.0/novel_downloader/core/downloaders/base_async_downloader.py +157 -0
  19. novel_downloader-1.1.0/novel_downloader/core/downloaders/base_downloader.py +187 -0
  20. novel_downloader-1.1.0/novel_downloader/core/downloaders/common_asynb_downloader.py +207 -0
  21. novel_downloader-1.1.0/novel_downloader/core/downloaders/common_downloader.py +191 -0
  22. novel_downloader-1.1.0/novel_downloader/core/downloaders/qidian_downloader.py +208 -0
  23. novel_downloader-1.1.0/novel_downloader/core/factory/__init__.py +33 -0
  24. novel_downloader-1.1.0/novel_downloader/core/factory/downloader_factory.py +149 -0
  25. novel_downloader-1.1.0/novel_downloader/core/factory/parser_factory.py +62 -0
  26. novel_downloader-1.1.0/novel_downloader/core/factory/requester_factory.py +106 -0
  27. novel_downloader-1.1.0/novel_downloader/core/factory/saver_factory.py +49 -0
  28. novel_downloader-1.1.0/novel_downloader/core/interfaces/__init__.py +32 -0
  29. novel_downloader-1.1.0/novel_downloader/core/interfaces/async_downloader_protocol.py +37 -0
  30. novel_downloader-1.1.0/novel_downloader/core/interfaces/async_requester_protocol.py +68 -0
  31. novel_downloader-1.1.0/novel_downloader/core/interfaces/downloader_protocol.py +37 -0
  32. novel_downloader-1.1.0/novel_downloader/core/interfaces/parser_protocol.py +40 -0
  33. novel_downloader-1.1.0/novel_downloader/core/interfaces/requester_protocol.py +65 -0
  34. novel_downloader-1.1.0/novel_downloader/core/interfaces/saver_protocol.py +61 -0
  35. novel_downloader-1.1.0/novel_downloader/core/parsers/__init__.py +28 -0
  36. novel_downloader-1.1.0/novel_downloader/core/parsers/base_parser.py +96 -0
  37. novel_downloader-1.1.0/novel_downloader/core/parsers/common_parser/__init__.py +14 -0
  38. novel_downloader-1.1.0/novel_downloader/core/parsers/common_parser/helper.py +321 -0
  39. novel_downloader-1.1.0/novel_downloader/core/parsers/common_parser/main_parser.py +86 -0
  40. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/__init__.py +20 -0
  41. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/browser/__init__.py +13 -0
  42. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/browser/chapter_encrypted.py +498 -0
  43. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/browser/chapter_normal.py +97 -0
  44. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/browser/chapter_router.py +70 -0
  45. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/browser/main_parser.py +110 -0
  46. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/session/__init__.py +13 -0
  47. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/session/chapter_encrypted.py +451 -0
  48. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/session/chapter_normal.py +119 -0
  49. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/session/chapter_router.py +67 -0
  50. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/session/main_parser.py +113 -0
  51. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/session/node_decryptor.py +164 -0
  52. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/shared/__init__.py +38 -0
  53. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/shared/book_info_parser.py +95 -0
  54. novel_downloader-1.1.0/novel_downloader/core/parsers/qidian_parser/shared/helpers.py +133 -0
  55. novel_downloader-1.1.0/novel_downloader/core/requesters/__init__.py +31 -0
  56. novel_downloader-1.1.0/novel_downloader/core/requesters/base_async_session.py +297 -0
  57. novel_downloader-1.1.0/novel_downloader/core/requesters/base_browser.py +210 -0
  58. novel_downloader-1.1.0/novel_downloader/core/requesters/base_session.py +243 -0
  59. novel_downloader-1.1.0/novel_downloader/core/requesters/common_requester/__init__.py +18 -0
  60. novel_downloader-1.1.0/novel_downloader/core/requesters/common_requester/common_async_session.py +96 -0
  61. novel_downloader-1.1.0/novel_downloader/core/requesters/common_requester/common_session.py +126 -0
  62. novel_downloader-1.1.0/novel_downloader/core/requesters/qidian_requester/__init__.py +22 -0
  63. novel_downloader-1.1.0/novel_downloader/core/requesters/qidian_requester/qidian_broswer.py +377 -0
  64. novel_downloader-1.1.0/novel_downloader/core/requesters/qidian_requester/qidian_session.py +202 -0
  65. novel_downloader-1.1.0/novel_downloader/core/savers/__init__.py +20 -0
  66. novel_downloader-1.1.0/novel_downloader/core/savers/base_saver.py +169 -0
  67. novel_downloader-1.1.0/novel_downloader/core/savers/common_saver/__init__.py +13 -0
  68. novel_downloader-1.1.0/novel_downloader/core/savers/common_saver/common_epub.py +232 -0
  69. novel_downloader-1.1.0/novel_downloader/core/savers/common_saver/common_txt.py +176 -0
  70. novel_downloader-1.1.0/novel_downloader/core/savers/common_saver/main_saver.py +86 -0
  71. novel_downloader-1.1.0/novel_downloader/core/savers/epub_utils/__init__.py +27 -0
  72. novel_downloader-1.1.0/novel_downloader/core/savers/epub_utils/css_builder.py +68 -0
  73. novel_downloader-1.1.0/novel_downloader/core/savers/epub_utils/initializer.py +98 -0
  74. novel_downloader-1.1.0/novel_downloader/core/savers/epub_utils/text_to_html.py +132 -0
  75. novel_downloader-1.1.0/novel_downloader/core/savers/epub_utils/volume_intro.py +61 -0
  76. novel_downloader-1.1.0/novel_downloader/core/savers/qidian_saver.py +22 -0
  77. novel_downloader-1.1.0/novel_downloader/locales/en.json +91 -0
  78. novel_downloader-1.1.0/novel_downloader/locales/zh.json +91 -0
  79. novel_downloader-1.1.0/novel_downloader/resources/config/rules.toml +196 -0
  80. novel_downloader-1.1.0/novel_downloader/resources/config/settings.yaml +73 -0
  81. novel_downloader-1.1.0/novel_downloader/resources/css_styles/main.css +104 -0
  82. novel_downloader-1.1.0/novel_downloader/resources/css_styles/volume-intro.css +56 -0
  83. novel_downloader-1.1.0/novel_downloader/resources/images/volume_border.png +0 -0
  84. novel_downloader-1.1.0/novel_downloader/resources/js_scripts/qidian_decrypt_node.js +82 -0
  85. novel_downloader-1.1.0/novel_downloader/resources/json/replace_word_map.json +4 -0
  86. novel_downloader-1.1.0/novel_downloader/resources/text/blacklist.txt +22 -0
  87. novel_downloader-1.1.0/novel_downloader/utils/__init__.py +0 -0
  88. novel_downloader-1.1.0/novel_downloader/utils/cache.py +24 -0
  89. novel_downloader-1.1.0/novel_downloader/utils/constants.py +158 -0
  90. novel_downloader-1.1.0/novel_downloader/utils/crypto_utils.py +144 -0
  91. novel_downloader-1.1.0/novel_downloader/utils/file_utils/__init__.py +43 -0
  92. novel_downloader-1.1.0/novel_downloader/utils/file_utils/io.py +252 -0
  93. novel_downloader-1.1.0/novel_downloader/utils/file_utils/normalize.py +68 -0
  94. novel_downloader-1.1.0/novel_downloader/utils/file_utils/sanitize.py +77 -0
  95. novel_downloader-1.1.0/novel_downloader/utils/fontocr/__init__.py +23 -0
  96. novel_downloader-1.1.0/novel_downloader/utils/fontocr/ocr_v1.py +304 -0
  97. novel_downloader-1.1.0/novel_downloader/utils/fontocr/ocr_v2.py +658 -0
  98. novel_downloader-1.1.0/novel_downloader/utils/hash_store.py +288 -0
  99. novel_downloader-1.1.0/novel_downloader/utils/hash_utils.py +103 -0
  100. novel_downloader-1.1.0/novel_downloader/utils/i18n.py +41 -0
  101. novel_downloader-1.1.0/novel_downloader/utils/logger.py +104 -0
  102. novel_downloader-1.1.0/novel_downloader/utils/model_loader.py +72 -0
  103. novel_downloader-1.1.0/novel_downloader/utils/network.py +287 -0
  104. novel_downloader-1.1.0/novel_downloader/utils/state.py +156 -0
  105. novel_downloader-1.1.0/novel_downloader/utils/text_utils/__init__.py +27 -0
  106. novel_downloader-1.1.0/novel_downloader/utils/text_utils/chapter_formatting.py +46 -0
  107. novel_downloader-1.1.0/novel_downloader/utils/text_utils/diff_display.py +75 -0
  108. novel_downloader-1.1.0/novel_downloader/utils/text_utils/font_mapping.py +31 -0
  109. novel_downloader-1.1.0/novel_downloader/utils/text_utils/text_cleaning.py +57 -0
  110. novel_downloader-1.1.0/novel_downloader/utils/time_utils/__init__.py +22 -0
  111. novel_downloader-1.1.0/novel_downloader/utils/time_utils/datetime_utils.py +146 -0
  112. novel_downloader-1.1.0/novel_downloader/utils/time_utils/sleep_utils.py +49 -0
  113. novel_downloader-1.1.0/novel_downloader.egg-info/PKG-INFO +157 -0
  114. novel_downloader-1.1.0/novel_downloader.egg-info/SOURCES.txt +118 -0
  115. novel_downloader-1.1.0/novel_downloader.egg-info/dependency_links.txt +1 -0
  116. novel_downloader-1.1.0/novel_downloader.egg-info/entry_points.txt +2 -0
  117. novel_downloader-1.1.0/novel_downloader.egg-info/requires.txt +29 -0
  118. novel_downloader-1.1.0/novel_downloader.egg-info/top_level.txt +1 -0
  119. novel_downloader-1.1.0/pyproject.toml +115 -0
  120. novel_downloader-1.1.0/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,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: novel-downloader
3
+ Version: 1.1.0
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
+ Provides-Extra: async
70
+ Requires-Dist: aiohttp; extra == "async"
71
+ Dynamic: license-file
72
+
73
+ # novel-downloader
74
+
75
+ 一个基于 [DrissionPage](https://www.drissionpage.cn) 和 [requests](https://github.com/psf/requests) 的小说下载器。
76
+
77
+ ---
78
+
79
+ ## 项目简介
80
+
81
+ **novel-downloader** 是一个通用的小说下载库 / CLI 工具,
82
+ - 大多数支持的站点仅依赖 [`requests`](https://github.com/psf/requests) 进行 HTTP 抓取
83
+ - 对于起点中文网 (Qidian), 可在配置中选择:
84
+ - `mode: session` : 纯 Requests 模式
85
+ - `mode: browser` : 基于 DrissionPage 驱动 Chrome 的浏览器模式 (可处理更复杂的 JS/加密)。
86
+ - 如果在 `browser` 模式下且 `login_required: true`, 首次运行会自动打开浏览器, 请完成登录后继续。
87
+
88
+ **快速开始**
89
+
90
+ ```bash
91
+ # 克隆 + 安装
92
+ pip install novel-downloader
93
+
94
+ # 如需支持字体解密功能 (decode_font), 请使用:
95
+ # pip install novel-downloader[font-recovery]
96
+
97
+ # 如需启用异步抓取模式 (mode=async), 请使用:
98
+ # pip install novel-downloader[async]
99
+
100
+ # 初始化默认配置 (生成 settings.yaml)
101
+ novel-cli settings init
102
+
103
+ # 编辑 ./settings.yaml 完成 site/book_ids 等
104
+ # 可查看 docs/4-settings-schema.md
105
+
106
+ # 运行下载
107
+ novel-cli download 123456
108
+ ```
109
+
110
+ **从 GitHub 安装 (开发版)**
111
+
112
+ 如需体验开发中的最新功能, 可通过 GitHub 安装:
113
+
114
+ ```bash
115
+ git clone https://github.com/BowenZ217/novel-downloader.git
116
+ cd novel-downloader
117
+ pip install .
118
+ # 或安装带可选功能:
119
+ # pip install .[font-recovery]
120
+ # pip install .[async]
121
+ ```
122
+
123
+ 更多使用方法, 查看 [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
124
+
125
+ ---
126
+
127
+ ## 功能特性
128
+
129
+ - 爬取起点中文网的小说章节内容 (支持免费与已订阅章节)
130
+ - 自动整合所有章节并输出为完整的 TXT 文件
131
+ - 支持活动广告过滤:
132
+ - [x] 章节标题
133
+ - [ ] 章节正文
134
+ - [ ] 作者说
135
+
136
+ ---
137
+
138
+ ## 文档结构
139
+
140
+ - [项目简介](#项目简介)
141
+ - [安装](https://github.com/BowenZ217/novel-downloader/blob/main/docs/1-installation.md)
142
+ - [环境准备](https://github.com/BowenZ217/novel-downloader/blob/main/docs/2-environment-setup.md)
143
+ - [配置](https://github.com/BowenZ217/novel-downloader/blob/main/docs/3-configuration.md)
144
+ - [settings.yaml 配置说明](https://github.com/BowenZ217/novel-downloader/blob/main/docs/4-settings-schema.md)
145
+ - [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
146
+ - [文件保存](https://github.com/BowenZ217/novel-downloader/blob/main/docs/file-saving.md)
147
+ - [TODO](https://github.com/BowenZ217/novel-downloader/blob/main/docs/todo.md)
148
+ - [开发](https://github.com/BowenZ217/novel-downloader/blob/main/docs/develop.md)
149
+ - [项目说明](#项目说明)
150
+
151
+ ---
152
+
153
+ ## 项目说明
154
+
155
+ - 本项目仅供学习和研究使用, 不得用于任何商业或违法用途。请遵守目标网站的 robots.txt 以及相关法律法规。
156
+ - 本项目开发者对因使用该工具所引起的任何法律责任不承担任何责任。
157
+ - 如果遇到网站结构变化或其他问题, 可能导致程序无法正常工作, 请自行调整代码或寻找其他解决方案。
@@ -0,0 +1,85 @@
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
+ pip install novel-downloader
21
+
22
+ # 如需支持字体解密功能 (decode_font), 请使用:
23
+ # pip install novel-downloader[font-recovery]
24
+
25
+ # 如需启用异步抓取模式 (mode=async), 请使用:
26
+ # pip install novel-downloader[async]
27
+
28
+ # 初始化默认配置 (生成 settings.yaml)
29
+ novel-cli settings init
30
+
31
+ # 编辑 ./settings.yaml 完成 site/book_ids 等
32
+ # 可查看 docs/4-settings-schema.md
33
+
34
+ # 运行下载
35
+ novel-cli download 123456
36
+ ```
37
+
38
+ **从 GitHub 安装 (开发版)**
39
+
40
+ 如需体验开发中的最新功能, 可通过 GitHub 安装:
41
+
42
+ ```bash
43
+ git clone https://github.com/BowenZ217/novel-downloader.git
44
+ cd novel-downloader
45
+ pip install .
46
+ # 或安装带可选功能:
47
+ # pip install .[font-recovery]
48
+ # pip install .[async]
49
+ ```
50
+
51
+ 更多使用方法, 查看 [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
52
+
53
+ ---
54
+
55
+ ## 功能特性
56
+
57
+ - 爬取起点中文网的小说章节内容 (支持免费与已订阅章节)
58
+ - 自动整合所有章节并输出为完整的 TXT 文件
59
+ - 支持活动广告过滤:
60
+ - [x] 章节标题
61
+ - [ ] 章节正文
62
+ - [ ] 作者说
63
+
64
+ ---
65
+
66
+ ## 文档结构
67
+
68
+ - [项目简介](#项目简介)
69
+ - [安装](https://github.com/BowenZ217/novel-downloader/blob/main/docs/1-installation.md)
70
+ - [环境准备](https://github.com/BowenZ217/novel-downloader/blob/main/docs/2-environment-setup.md)
71
+ - [配置](https://github.com/BowenZ217/novel-downloader/blob/main/docs/3-configuration.md)
72
+ - [settings.yaml 配置说明](https://github.com/BowenZ217/novel-downloader/blob/main/docs/4-settings-schema.md)
73
+ - [使用示例](https://github.com/BowenZ217/novel-downloader/blob/main/docs/5-usage-examples.md)
74
+ - [文件保存](https://github.com/BowenZ217/novel-downloader/blob/main/docs/file-saving.md)
75
+ - [TODO](https://github.com/BowenZ217/novel-downloader/blob/main/docs/todo.md)
76
+ - [开发](https://github.com/BowenZ217/novel-downloader/blob/main/docs/develop.md)
77
+ - [项目说明](#项目说明)
78
+
79
+ ---
80
+
81
+ ## 项目说明
82
+
83
+ - 本项目仅供学习和研究使用, 不得用于任何商业或违法用途。请遵守目标网站的 robots.txt 以及相关法律法规。
84
+ - 本项目开发者对因使用该工具所引起的任何法律责任不承担任何责任。
85
+ - 如果遇到网站结构变化或其他问题, 可能导致程序无法正常工作, 请自行调整代码或寻找其他解决方案。
@@ -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.0"
11
+
12
+ __author__ = "Saudade Z"
13
+ __email__ = "saudadez217@gmail.com"
14
+ __license__ = "MIT"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ novel_downloader.cli
5
+ --------------------
6
+
7
+ This module exposes the CLI entry point.
8
+ """
9
+
10
+ from .main import cli_main
11
+
12
+ __all__ = [
13
+ "cli_main",
14
+ ]
@@ -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,132 @@
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.factory import (
18
+ get_async_downloader,
19
+ get_async_requester,
20
+ # get_downloader,
21
+ get_parser,
22
+ # get_requester,
23
+ get_saver,
24
+ get_sync_downloader,
25
+ get_sync_requester,
26
+ )
27
+ from novel_downloader.utils.i18n import t
28
+ from novel_downloader.utils.logger import setup_logging
29
+
30
+
31
+ @click.command(
32
+ name="download",
33
+ help=t("download_help"),
34
+ short_help=t("download_short_help"),
35
+ ) # type: ignore
36
+ @click.argument("book_ids", nargs=-1) # type: ignore
37
+ @click.option(
38
+ "--site",
39
+ default="qidian",
40
+ show_default=True,
41
+ help=t("download_option_site", default="qidian"),
42
+ ) # type: ignore
43
+ @click.pass_context # type: ignore
44
+ def download_cli(ctx: Context, book_ids: List[str], site: str) -> None:
45
+ """Download full novels by book IDs."""
46
+ config_path = ctx.obj.get("config_path")
47
+
48
+ click.echo(t("download_using_config", path=config_path))
49
+ click.echo(t("download_site_info", site=site))
50
+
51
+ config_data = load_config(config_path)
52
+ adapter = ConfigAdapter(config=config_data, site=site)
53
+
54
+ # Retrieve each sub-component's configuration from the adapter
55
+ requester_cfg = adapter.get_requester_config()
56
+ downloader_cfg = adapter.get_downloader_config()
57
+ parser_cfg = adapter.get_parser_config()
58
+ saver_cfg = adapter.get_saver_config()
59
+
60
+ # If no book_ids provided on the command line, try to load them from config
61
+ if not book_ids:
62
+ try:
63
+ book_ids = adapter.get_book_ids()
64
+ except Exception as e:
65
+ click.echo(t("download_fail_get_ids", err=e))
66
+ return
67
+
68
+ # Filter out placeholder/example IDs
69
+ invalid_ids = {"0000000000"}
70
+ valid_book_ids = [bid for bid in book_ids if bid not in invalid_ids]
71
+
72
+ if not book_ids:
73
+ click.echo(t("download_no_ids"))
74
+ return
75
+
76
+ if not valid_book_ids:
77
+ click.echo(t("download_only_example", example="0000000000"))
78
+ click.echo(t("download_edit_config"))
79
+ return
80
+
81
+ # Initialize the requester, parser, saver, and downloader components
82
+ if downloader_cfg.mode == "async":
83
+ import asyncio
84
+
85
+ async_requester = get_async_requester(site, requester_cfg)
86
+ async_parser = get_parser(site, parser_cfg)
87
+ async_saver = get_saver(site, saver_cfg)
88
+ setup_logging()
89
+ async_downloader = get_async_downloader(
90
+ requester=async_requester,
91
+ parser=async_parser,
92
+ saver=async_saver,
93
+ site=site,
94
+ config=downloader_cfg,
95
+ )
96
+
97
+ async def async_download_all() -> None:
98
+ prepare = getattr(async_downloader, "prepare", None)
99
+ if prepare and asyncio.iscoroutinefunction(prepare):
100
+ await prepare()
101
+
102
+ for book_id in valid_book_ids:
103
+ click.echo(t("download_downloading", book_id=book_id, site=site))
104
+ await async_downloader.download_one(book_id)
105
+
106
+ if requester_cfg.auto_close:
107
+ input(t("download_prompt_parse"))
108
+ await async_requester.shutdown()
109
+
110
+ asyncio.run(async_download_all())
111
+ else:
112
+ sync_requester = get_sync_requester(site, requester_cfg)
113
+ sync_parser = get_parser(site, parser_cfg)
114
+ sync_saver = get_saver(site, saver_cfg)
115
+ setup_logging()
116
+ sync_downloader = get_sync_downloader(
117
+ requester=sync_requester,
118
+ parser=sync_parser,
119
+ saver=sync_saver,
120
+ site=site,
121
+ config=downloader_cfg,
122
+ )
123
+
124
+ for book_id in book_ids:
125
+ click.echo(t("download_downloading", book_id=book_id, site=site))
126
+ sync_downloader.download_one(book_id)
127
+
128
+ if requester_cfg.auto_close:
129
+ input(t("download_prompt_parse"))
130
+ sync_requester.shutdown()
131
+
132
+ return
@@ -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()