novel-downloader 1.4.5__py3-none-any.whl → 2.0.0__py3-none-any.whl
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/__init__.py +1 -1
- novel_downloader/cli/__init__.py +2 -4
- novel_downloader/cli/clean.py +21 -88
- novel_downloader/cli/config.py +27 -104
- novel_downloader/cli/download.py +78 -66
- novel_downloader/cli/export.py +20 -21
- novel_downloader/cli/main.py +3 -1
- novel_downloader/cli/search.py +120 -0
- novel_downloader/cli/ui.py +156 -0
- novel_downloader/config/__init__.py +10 -14
- novel_downloader/config/adapter.py +195 -99
- novel_downloader/config/{loader.py → file_io.py} +53 -27
- novel_downloader/core/__init__.py +14 -13
- novel_downloader/core/archived/deqixs/fetcher.py +115 -0
- novel_downloader/core/archived/deqixs/parser.py +132 -0
- novel_downloader/core/archived/deqixs/searcher.py +89 -0
- novel_downloader/core/archived/qidian/searcher.py +79 -0
- novel_downloader/core/archived/wanbengo/searcher.py +98 -0
- novel_downloader/core/archived/xshbook/searcher.py +93 -0
- novel_downloader/core/downloaders/__init__.py +8 -30
- novel_downloader/core/downloaders/base.py +182 -30
- novel_downloader/core/downloaders/common.py +217 -384
- novel_downloader/core/downloaders/qianbi.py +332 -4
- novel_downloader/core/downloaders/qidian.py +250 -290
- novel_downloader/core/downloaders/registry.py +69 -0
- novel_downloader/core/downloaders/signals.py +46 -0
- novel_downloader/core/exporters/__init__.py +8 -26
- novel_downloader/core/exporters/base.py +107 -31
- novel_downloader/core/exporters/common/__init__.py +3 -4
- novel_downloader/core/exporters/common/epub.py +92 -171
- novel_downloader/core/exporters/common/main_exporter.py +14 -67
- novel_downloader/core/exporters/common/txt.py +90 -86
- novel_downloader/core/exporters/epub_util.py +184 -1327
- novel_downloader/core/exporters/linovelib/__init__.py +3 -2
- novel_downloader/core/exporters/linovelib/epub.py +165 -222
- novel_downloader/core/exporters/linovelib/main_exporter.py +10 -71
- novel_downloader/core/exporters/linovelib/txt.py +76 -66
- novel_downloader/core/exporters/qidian.py +15 -11
- novel_downloader/core/exporters/registry.py +55 -0
- novel_downloader/core/exporters/txt_util.py +67 -0
- novel_downloader/core/fetchers/__init__.py +57 -56
- novel_downloader/core/fetchers/aaatxt.py +83 -0
- novel_downloader/core/fetchers/{biquge/session.py → b520.py} +10 -10
- novel_downloader/core/fetchers/{base/session.py → base.py} +63 -47
- novel_downloader/core/fetchers/biquyuedu.py +83 -0
- novel_downloader/core/fetchers/dxmwx.py +110 -0
- novel_downloader/core/fetchers/eightnovel.py +139 -0
- novel_downloader/core/fetchers/{esjzone/session.py → esjzone.py} +23 -11
- novel_downloader/core/fetchers/guidaye.py +85 -0
- novel_downloader/core/fetchers/hetushu.py +92 -0
- novel_downloader/core/fetchers/{qianbi/browser.py → i25zw.py} +22 -26
- novel_downloader/core/fetchers/ixdzs8.py +113 -0
- novel_downloader/core/fetchers/jpxs123.py +101 -0
- novel_downloader/core/fetchers/{biquge/browser.py → lewenn.py} +15 -15
- novel_downloader/core/fetchers/{linovelib/session.py → linovelib.py} +16 -12
- novel_downloader/core/fetchers/piaotia.py +105 -0
- novel_downloader/core/fetchers/qbtr.py +101 -0
- novel_downloader/core/fetchers/{qianbi/session.py → qianbi.py} +9 -9
- novel_downloader/core/fetchers/{qidian/session.py → qidian.py} +55 -40
- novel_downloader/core/fetchers/quanben5.py +92 -0
- novel_downloader/core/fetchers/{base/rate_limiter.py → rate_limiter.py} +2 -2
- novel_downloader/core/fetchers/registry.py +60 -0
- novel_downloader/core/fetchers/{sfacg/session.py → sfacg.py} +11 -9
- novel_downloader/core/fetchers/shencou.py +106 -0
- novel_downloader/core/fetchers/{common/browser.py → shuhaige.py} +24 -19
- novel_downloader/core/fetchers/tongrenquan.py +84 -0
- novel_downloader/core/fetchers/ttkan.py +95 -0
- novel_downloader/core/fetchers/{common/session.py → wanbengo.py} +21 -17
- novel_downloader/core/fetchers/xiaoshuowu.py +106 -0
- novel_downloader/core/fetchers/xiguashuwu.py +177 -0
- novel_downloader/core/fetchers/xs63b.py +171 -0
- novel_downloader/core/fetchers/xshbook.py +85 -0
- novel_downloader/core/fetchers/{yamibo/session.py → yamibo.py} +23 -11
- novel_downloader/core/fetchers/yibige.py +114 -0
- novel_downloader/core/interfaces/__init__.py +8 -14
- novel_downloader/core/interfaces/downloader.py +6 -2
- novel_downloader/core/interfaces/exporter.py +7 -7
- novel_downloader/core/interfaces/fetcher.py +4 -17
- novel_downloader/core/interfaces/parser.py +5 -6
- novel_downloader/core/interfaces/searcher.py +26 -0
- novel_downloader/core/parsers/__init__.py +58 -22
- novel_downloader/core/parsers/aaatxt.py +132 -0
- novel_downloader/core/parsers/b520.py +116 -0
- novel_downloader/core/parsers/base.py +63 -12
- novel_downloader/core/parsers/biquyuedu.py +133 -0
- novel_downloader/core/parsers/dxmwx.py +162 -0
- novel_downloader/core/parsers/eightnovel.py +224 -0
- novel_downloader/core/parsers/{esjzone/main_parser.py → esjzone.py} +67 -67
- novel_downloader/core/parsers/guidaye.py +128 -0
- novel_downloader/core/parsers/hetushu.py +139 -0
- novel_downloader/core/parsers/i25zw.py +137 -0
- novel_downloader/core/parsers/ixdzs8.py +186 -0
- novel_downloader/core/parsers/jpxs123.py +137 -0
- novel_downloader/core/parsers/lewenn.py +142 -0
- novel_downloader/core/parsers/{linovelib/main_parser.py → linovelib.py} +54 -65
- novel_downloader/core/parsers/piaotia.py +189 -0
- novel_downloader/core/parsers/qbtr.py +136 -0
- novel_downloader/core/parsers/{qianbi/main_parser.py → qianbi.py} +54 -51
- novel_downloader/core/parsers/qidian/__init__.py +2 -2
- novel_downloader/core/parsers/qidian/book_info_parser.py +58 -59
- novel_downloader/core/parsers/qidian/chapter_encrypted.py +290 -346
- novel_downloader/core/parsers/qidian/chapter_normal.py +25 -56
- novel_downloader/core/parsers/qidian/main_parser.py +19 -57
- novel_downloader/core/parsers/qidian/utils/__init__.py +12 -11
- novel_downloader/core/parsers/qidian/utils/decryptor_fetcher.py +6 -7
- novel_downloader/core/parsers/qidian/utils/fontmap_recover.py +143 -0
- novel_downloader/core/parsers/qidian/utils/helpers.py +0 -4
- novel_downloader/core/parsers/qidian/utils/node_decryptor.py +2 -2
- novel_downloader/core/parsers/quanben5.py +103 -0
- novel_downloader/core/parsers/registry.py +57 -0
- novel_downloader/core/parsers/{sfacg/main_parser.py → sfacg.py} +46 -48
- novel_downloader/core/parsers/shencou.py +215 -0
- novel_downloader/core/parsers/shuhaige.py +111 -0
- novel_downloader/core/parsers/tongrenquan.py +116 -0
- novel_downloader/core/parsers/ttkan.py +132 -0
- novel_downloader/core/parsers/wanbengo.py +191 -0
- novel_downloader/core/parsers/xiaoshuowu.py +173 -0
- novel_downloader/core/parsers/xiguashuwu.py +435 -0
- novel_downloader/core/parsers/xs63b.py +161 -0
- novel_downloader/core/parsers/xshbook.py +134 -0
- novel_downloader/core/parsers/yamibo.py +155 -0
- novel_downloader/core/parsers/yibige.py +166 -0
- novel_downloader/core/searchers/__init__.py +51 -0
- novel_downloader/core/searchers/aaatxt.py +107 -0
- novel_downloader/core/searchers/b520.py +84 -0
- novel_downloader/core/searchers/base.py +168 -0
- novel_downloader/core/searchers/dxmwx.py +105 -0
- novel_downloader/core/searchers/eightnovel.py +84 -0
- novel_downloader/core/searchers/esjzone.py +102 -0
- novel_downloader/core/searchers/hetushu.py +92 -0
- novel_downloader/core/searchers/i25zw.py +93 -0
- novel_downloader/core/searchers/ixdzs8.py +107 -0
- novel_downloader/core/searchers/jpxs123.py +107 -0
- novel_downloader/core/searchers/piaotia.py +100 -0
- novel_downloader/core/searchers/qbtr.py +106 -0
- novel_downloader/core/searchers/qianbi.py +165 -0
- novel_downloader/core/searchers/quanben5.py +144 -0
- novel_downloader/core/searchers/registry.py +79 -0
- novel_downloader/core/searchers/shuhaige.py +124 -0
- novel_downloader/core/searchers/tongrenquan.py +110 -0
- novel_downloader/core/searchers/ttkan.py +92 -0
- novel_downloader/core/searchers/xiaoshuowu.py +122 -0
- novel_downloader/core/searchers/xiguashuwu.py +95 -0
- novel_downloader/core/searchers/xs63b.py +104 -0
- novel_downloader/locales/en.json +36 -79
- novel_downloader/locales/zh.json +37 -80
- novel_downloader/models/__init__.py +23 -50
- novel_downloader/models/book.py +44 -0
- novel_downloader/models/config.py +16 -43
- novel_downloader/models/login.py +1 -1
- novel_downloader/models/search.py +21 -0
- novel_downloader/resources/config/settings.toml +39 -74
- novel_downloader/resources/css_styles/intro.css +83 -0
- novel_downloader/resources/css_styles/main.css +30 -89
- novel_downloader/resources/json/xiguashuwu.json +718 -0
- novel_downloader/utils/__init__.py +43 -0
- novel_downloader/utils/chapter_storage.py +247 -226
- novel_downloader/utils/constants.py +5 -50
- novel_downloader/utils/cookies.py +6 -18
- novel_downloader/utils/crypto_utils/__init__.py +13 -0
- novel_downloader/utils/crypto_utils/aes_util.py +90 -0
- novel_downloader/utils/crypto_utils/aes_v1.py +619 -0
- novel_downloader/utils/crypto_utils/aes_v2.py +1143 -0
- novel_downloader/utils/{crypto_utils.py → crypto_utils/rc4.py} +3 -10
- novel_downloader/utils/epub/__init__.py +34 -0
- novel_downloader/utils/epub/builder.py +377 -0
- novel_downloader/utils/epub/constants.py +118 -0
- novel_downloader/utils/epub/documents.py +297 -0
- novel_downloader/utils/epub/models.py +120 -0
- novel_downloader/utils/epub/utils.py +179 -0
- novel_downloader/utils/file_utils/__init__.py +5 -30
- novel_downloader/utils/file_utils/io.py +9 -150
- novel_downloader/utils/file_utils/normalize.py +2 -2
- novel_downloader/utils/file_utils/sanitize.py +2 -7
- novel_downloader/utils/fontocr.py +207 -0
- novel_downloader/utils/i18n.py +2 -0
- novel_downloader/utils/logger.py +10 -16
- novel_downloader/utils/network.py +111 -252
- novel_downloader/utils/state.py +5 -90
- novel_downloader/utils/text_utils/__init__.py +16 -21
- novel_downloader/utils/text_utils/diff_display.py +6 -9
- novel_downloader/utils/text_utils/numeric_conversion.py +253 -0
- novel_downloader/utils/text_utils/text_cleaner.py +179 -0
- novel_downloader/utils/text_utils/truncate_utils.py +62 -0
- novel_downloader/utils/time_utils/__init__.py +6 -12
- novel_downloader/utils/time_utils/datetime_utils.py +23 -33
- novel_downloader/utils/time_utils/sleep_utils.py +5 -10
- novel_downloader/web/__init__.py +13 -0
- novel_downloader/web/components/__init__.py +11 -0
- novel_downloader/web/components/navigation.py +35 -0
- novel_downloader/web/main.py +66 -0
- novel_downloader/web/pages/__init__.py +17 -0
- novel_downloader/web/pages/download.py +78 -0
- novel_downloader/web/pages/progress.py +147 -0
- novel_downloader/web/pages/search.py +329 -0
- novel_downloader/web/services/__init__.py +17 -0
- novel_downloader/web/services/client_dialog.py +164 -0
- novel_downloader/web/services/cred_broker.py +113 -0
- novel_downloader/web/services/cred_models.py +35 -0
- novel_downloader/web/services/task_manager.py +264 -0
- novel_downloader-2.0.0.dist-info/METADATA +171 -0
- novel_downloader-2.0.0.dist-info/RECORD +210 -0
- {novel_downloader-1.4.5.dist-info → novel_downloader-2.0.0.dist-info}/entry_points.txt +1 -1
- novel_downloader/config/site_rules.py +0 -94
- novel_downloader/core/downloaders/biquge.py +0 -25
- novel_downloader/core/downloaders/esjzone.py +0 -25
- novel_downloader/core/downloaders/linovelib.py +0 -25
- novel_downloader/core/downloaders/sfacg.py +0 -25
- novel_downloader/core/downloaders/yamibo.py +0 -25
- novel_downloader/core/exporters/biquge.py +0 -25
- novel_downloader/core/exporters/esjzone.py +0 -25
- novel_downloader/core/exporters/qianbi.py +0 -25
- novel_downloader/core/exporters/sfacg.py +0 -25
- novel_downloader/core/exporters/yamibo.py +0 -25
- novel_downloader/core/factory/__init__.py +0 -20
- novel_downloader/core/factory/downloader.py +0 -73
- novel_downloader/core/factory/exporter.py +0 -58
- novel_downloader/core/factory/fetcher.py +0 -96
- novel_downloader/core/factory/parser.py +0 -86
- novel_downloader/core/fetchers/base/__init__.py +0 -14
- novel_downloader/core/fetchers/base/browser.py +0 -403
- novel_downloader/core/fetchers/biquge/__init__.py +0 -14
- novel_downloader/core/fetchers/common/__init__.py +0 -14
- novel_downloader/core/fetchers/esjzone/__init__.py +0 -14
- novel_downloader/core/fetchers/esjzone/browser.py +0 -204
- novel_downloader/core/fetchers/linovelib/__init__.py +0 -14
- novel_downloader/core/fetchers/linovelib/browser.py +0 -193
- novel_downloader/core/fetchers/qianbi/__init__.py +0 -14
- novel_downloader/core/fetchers/qidian/__init__.py +0 -14
- novel_downloader/core/fetchers/qidian/browser.py +0 -318
- novel_downloader/core/fetchers/sfacg/__init__.py +0 -14
- novel_downloader/core/fetchers/sfacg/browser.py +0 -189
- novel_downloader/core/fetchers/yamibo/__init__.py +0 -14
- novel_downloader/core/fetchers/yamibo/browser.py +0 -229
- novel_downloader/core/parsers/biquge/__init__.py +0 -10
- novel_downloader/core/parsers/biquge/main_parser.py +0 -134
- novel_downloader/core/parsers/common/__init__.py +0 -13
- novel_downloader/core/parsers/common/helper.py +0 -323
- novel_downloader/core/parsers/common/main_parser.py +0 -106
- novel_downloader/core/parsers/esjzone/__init__.py +0 -10
- novel_downloader/core/parsers/linovelib/__init__.py +0 -10
- novel_downloader/core/parsers/qianbi/__init__.py +0 -10
- novel_downloader/core/parsers/sfacg/__init__.py +0 -10
- novel_downloader/core/parsers/yamibo/__init__.py +0 -10
- novel_downloader/core/parsers/yamibo/main_parser.py +0 -194
- novel_downloader/models/browser.py +0 -21
- novel_downloader/models/chapter.py +0 -25
- novel_downloader/models/site_rules.py +0 -99
- novel_downloader/models/tasks.py +0 -33
- novel_downloader/models/types.py +0 -15
- novel_downloader/resources/css_styles/volume-intro.css +0 -56
- novel_downloader/resources/json/replace_word_map.json +0 -4
- novel_downloader/resources/text/blacklist.txt +0 -22
- novel_downloader/tui/__init__.py +0 -7
- novel_downloader/tui/app.py +0 -32
- novel_downloader/tui/main.py +0 -17
- novel_downloader/tui/screens/__init__.py +0 -14
- novel_downloader/tui/screens/home.py +0 -198
- novel_downloader/tui/screens/login.py +0 -74
- novel_downloader/tui/styles/home_layout.tcss +0 -79
- novel_downloader/tui/widgets/richlog_handler.py +0 -24
- novel_downloader/utils/cache.py +0 -24
- novel_downloader/utils/fontocr/__init__.py +0 -22
- novel_downloader/utils/fontocr/model_loader.py +0 -69
- novel_downloader/utils/fontocr/ocr_v1.py +0 -303
- novel_downloader/utils/fontocr/ocr_v2.py +0 -752
- novel_downloader/utils/hash_store.py +0 -279
- novel_downloader/utils/hash_utils.py +0 -103
- novel_downloader/utils/text_utils/chapter_formatting.py +0 -46
- novel_downloader/utils/text_utils/font_mapping.py +0 -28
- novel_downloader/utils/text_utils/text_cleaning.py +0 -107
- novel_downloader-1.4.5.dist-info/METADATA +0 -196
- novel_downloader-1.4.5.dist-info/RECORD +0 -165
- {novel_downloader-1.4.5.dist-info → novel_downloader-2.0.0.dist-info}/WHEEL +0 -0
- {novel_downloader-1.4.5.dist-info → novel_downloader-2.0.0.dist-info}/licenses/LICENSE +0 -0
- {novel_downloader-1.4.5.dist-info → novel_downloader-2.0.0.dist-info}/top_level.txt +0 -0
@@ -15,7 +15,7 @@ from typing import TYPE_CHECKING
|
|
15
15
|
from lxml import html
|
16
16
|
|
17
17
|
from novel_downloader.models import ChapterDict
|
18
|
-
from novel_downloader.utils
|
18
|
+
from novel_downloader.utils import truncate_half_lines
|
19
19
|
|
20
20
|
from .utils import (
|
21
21
|
extract_chapter_info,
|
@@ -65,17 +65,15 @@ def parse_normal_chapter(
|
|
65
65
|
seq = chapter_info.get("seq", None)
|
66
66
|
volume = chapter_info.get("extra", {}).get("volumeName", "")
|
67
67
|
|
68
|
-
chapter_text =
|
68
|
+
chapter_text = _parse_paragraph(
|
69
|
+
html_str=raw_html,
|
70
|
+
is_vip=vip_status(ssr_data),
|
71
|
+
chapter_id=chapter_id,
|
72
|
+
fkp=fkp,
|
73
|
+
fuid=parser._fuid,
|
74
|
+
)
|
69
75
|
if not chapter_text:
|
70
|
-
|
71
|
-
html_str=raw_html,
|
72
|
-
is_vip=vip_status(ssr_data),
|
73
|
-
chapter_id=chapter_id,
|
74
|
-
fkp=fkp,
|
75
|
-
fuid=parser._fuid,
|
76
|
-
)
|
77
|
-
if not chapter_text:
|
78
|
-
return None
|
76
|
+
return None
|
79
77
|
|
80
78
|
if parser._use_truncation and duplicated:
|
81
79
|
chapter_text = truncate_half_lines(chapter_text)
|
@@ -103,55 +101,26 @@ def parse_normal_chapter(
|
|
103
101
|
return None
|
104
102
|
|
105
103
|
|
106
|
-
def
|
107
|
-
try:
|
108
|
-
tree = html.fromstring(html_str)
|
109
|
-
main = tree.xpath('//div[@id="app"]//div[@id="reader-content"]//main')
|
110
|
-
if not main:
|
111
|
-
return ""
|
112
|
-
main = main[0]
|
113
|
-
|
114
|
-
content_spans = main.xpath('.//span[contains(@class, "content-text")]')
|
115
|
-
|
116
|
-
paragraph_texts = [
|
117
|
-
span.text_content().strip()
|
118
|
-
for span in content_spans
|
119
|
-
if span.text_content().strip()
|
120
|
-
]
|
121
|
-
|
122
|
-
chapter_text = "\n\n".join(paragraph_texts)
|
123
|
-
return chapter_text
|
124
|
-
|
125
|
-
except Exception as e:
|
126
|
-
logger.error("[Parser] _parse_paragraph failed: %s", e)
|
127
|
-
return ""
|
128
|
-
|
129
|
-
|
130
|
-
def _parse_session_paragraph(
|
104
|
+
def _parse_paragraph(
|
131
105
|
html_str: str,
|
132
106
|
is_vip: bool,
|
133
107
|
chapter_id: str,
|
134
108
|
fkp: str,
|
135
109
|
fuid: str,
|
136
110
|
) -> str:
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
return ""
|
147
|
-
|
148
|
-
tree = html.fromstring(raw_html)
|
149
|
-
paras = tree.xpath(".//p")
|
150
|
-
paragraph_texts = [
|
151
|
-
p.text_content().strip() for p in paras if p.text_content().strip()
|
152
|
-
]
|
153
|
-
return "\n\n".join(paragraph_texts)
|
111
|
+
raw_html = html_str
|
112
|
+
|
113
|
+
if is_vip:
|
114
|
+
try:
|
115
|
+
decryptor = get_decryptor()
|
116
|
+
raw_html = decryptor.decrypt(raw_html, chapter_id, fkp, fuid)
|
117
|
+
except Exception as e:
|
118
|
+
logger.error("[Parser] decryption failed for '%s': %s", chapter_id, e)
|
119
|
+
return ""
|
154
120
|
|
155
|
-
|
156
|
-
|
157
|
-
|
121
|
+
tree = html.fromstring(raw_html)
|
122
|
+
paras = tree.xpath(".//p")
|
123
|
+
paragraph_texts = [
|
124
|
+
p.text_content().strip() for p in paras if p.text_content().strip()
|
125
|
+
]
|
126
|
+
return "\n".join(paragraph_texts)
|
@@ -10,12 +10,17 @@ from __future__ import annotations
|
|
10
10
|
|
11
11
|
import logging
|
12
12
|
from pathlib import Path
|
13
|
-
from typing import
|
13
|
+
from typing import Any
|
14
14
|
|
15
15
|
from novel_downloader.core.parsers.base import BaseParser
|
16
|
-
from novel_downloader.
|
16
|
+
from novel_downloader.core.parsers.registry import register_parser
|
17
|
+
from novel_downloader.models import (
|
18
|
+
BookInfoDict,
|
19
|
+
ChapterDict,
|
20
|
+
ParserConfig,
|
21
|
+
)
|
17
22
|
from novel_downloader.utils.constants import DATA_DIR
|
18
|
-
from novel_downloader.utils.cookies import
|
23
|
+
from novel_downloader.utils.cookies import get_cookie_value
|
19
24
|
|
20
25
|
from .book_info_parser import parse_book_info
|
21
26
|
from .chapter_router import parse_chapter
|
@@ -23,13 +28,13 @@ from .utils import is_encrypted
|
|
23
28
|
|
24
29
|
logger = logging.getLogger(__name__)
|
25
30
|
|
26
|
-
if TYPE_CHECKING:
|
27
|
-
from novel_downloader.utils.fontocr import FontOCR
|
28
|
-
|
29
31
|
|
32
|
+
@register_parser(
|
33
|
+
site_keys=["qidian", "qd"],
|
34
|
+
)
|
30
35
|
class QidianParser(BaseParser):
|
31
36
|
"""
|
32
|
-
Parser for
|
37
|
+
Parser for 起点中文网 site.
|
33
38
|
"""
|
34
39
|
|
35
40
|
def __init__(
|
@@ -44,50 +49,20 @@ class QidianParser(BaseParser):
|
|
44
49
|
"""
|
45
50
|
super().__init__(config)
|
46
51
|
|
47
|
-
# Extract and store parser flags from config
|
48
|
-
self._use_truncation = config.use_truncation
|
49
|
-
self._decode_font: bool = config.decode_font
|
50
|
-
self._save_font_debug: bool = config.save_font_debug
|
51
|
-
|
52
52
|
self._fixed_font_dir: Path = self._base_cache_dir / "fixed_fonts"
|
53
53
|
self._fixed_font_dir.mkdir(parents=True, exist_ok=True)
|
54
|
-
self.
|
54
|
+
self._debug_dir: Path = Path.cwd() / "debug"
|
55
55
|
|
56
56
|
state_files = [
|
57
|
-
DATA_DIR / "qidian" / "browser_state.cookies",
|
58
57
|
DATA_DIR / "qidian" / "session_state.cookies",
|
59
58
|
]
|
60
|
-
self._fuid: str = fuid or
|
61
|
-
|
62
|
-
self._font_ocr: FontOCR | None = None
|
63
|
-
if self._decode_font:
|
64
|
-
try:
|
65
|
-
from novel_downloader.utils.fontocr import FontOCR
|
66
|
-
except ImportError:
|
67
|
-
logger.warning(
|
68
|
-
"[QidianParser] FontOCR not available, font decoding will skip"
|
69
|
-
)
|
70
|
-
else:
|
71
|
-
self._font_ocr = FontOCR(
|
72
|
-
cache_dir=self._base_cache_dir,
|
73
|
-
use_freq=config.use_freq,
|
74
|
-
use_ocr=config.use_ocr,
|
75
|
-
use_vec=config.use_vec,
|
76
|
-
batch_size=config.batch_size,
|
77
|
-
gpu_mem=config.gpu_mem,
|
78
|
-
gpu_id=config.gpu_id,
|
79
|
-
ocr_weight=config.ocr_weight,
|
80
|
-
vec_weight=config.vec_weight,
|
81
|
-
font_debug=config.save_font_debug,
|
82
|
-
)
|
83
|
-
self._font_debug_dir = self._base_cache_dir / "qidian" / "font_debug"
|
84
|
-
self._font_debug_dir.mkdir(parents=True, exist_ok=True)
|
59
|
+
self._fuid: str = fuid or get_cookie_value(state_files, "ywguid")
|
85
60
|
|
86
61
|
def parse_book_info(
|
87
62
|
self,
|
88
63
|
html_list: list[str],
|
89
64
|
**kwargs: Any,
|
90
|
-
) ->
|
65
|
+
) -> BookInfoDict | None:
|
91
66
|
"""
|
92
67
|
Parse a book info page and extract metadata and chapter structure.
|
93
68
|
|
@@ -95,7 +70,7 @@ class QidianParser(BaseParser):
|
|
95
70
|
:return: Parsed metadata and chapter structure as a dictionary.
|
96
71
|
"""
|
97
72
|
if not html_list:
|
98
|
-
return
|
73
|
+
return None
|
99
74
|
return parse_book_info(html_list[0])
|
100
75
|
|
101
76
|
def parse_chapter(
|
@@ -121,19 +96,6 @@ class QidianParser(BaseParser):
|
|
121
96
|
"""
|
122
97
|
return is_encrypted(html_str)
|
123
98
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
Folders are only created if corresponding debug/save flags are enabled.
|
128
|
-
"""
|
129
|
-
base = self._base_cache_dir
|
130
|
-
|
131
|
-
# Font debug folder
|
132
|
-
if self._save_font_debug and self.book_id:
|
133
|
-
self._font_debug_dir = base / self.book_id / "font_debug"
|
134
|
-
self._font_debug_dir.mkdir(parents=True, exist_ok=True)
|
135
|
-
else:
|
136
|
-
self._font_debug_dir = None
|
137
|
-
|
138
|
-
def _on_book_id_set(self) -> None:
|
139
|
-
self._init_cache_folders()
|
99
|
+
@property
|
100
|
+
def save_font_debug(self) -> bool:
|
101
|
+
return self._config.save_font_debug
|
@@ -3,19 +3,9 @@
|
|
3
3
|
novel_downloader.core.parsers.qidian.utils
|
4
4
|
------------------------------------------
|
5
5
|
|
6
|
+
Utility functions and helpers for parsing and decrypting Qidian novel pages
|
6
7
|
"""
|
7
8
|
|
8
|
-
from .helpers import (
|
9
|
-
can_view_chapter,
|
10
|
-
extract_chapter_info,
|
11
|
-
find_ssr_page_context,
|
12
|
-
is_duplicated,
|
13
|
-
is_encrypted,
|
14
|
-
is_restricted_page,
|
15
|
-
vip_status,
|
16
|
-
)
|
17
|
-
from .node_decryptor import QidianNodeDecryptor, get_decryptor
|
18
|
-
|
19
9
|
__all__ = [
|
20
10
|
"find_ssr_page_context",
|
21
11
|
"extract_chapter_info",
|
@@ -27,3 +17,14 @@ __all__ = [
|
|
27
17
|
"QidianNodeDecryptor",
|
28
18
|
"get_decryptor",
|
29
19
|
]
|
20
|
+
|
21
|
+
from .helpers import (
|
22
|
+
can_view_chapter,
|
23
|
+
extract_chapter_info,
|
24
|
+
find_ssr_page_context,
|
25
|
+
is_duplicated,
|
26
|
+
is_encrypted,
|
27
|
+
is_restricted_page,
|
28
|
+
vip_status,
|
29
|
+
)
|
30
|
+
from .node_decryptor import QidianNodeDecryptor, get_decryptor
|
@@ -9,6 +9,11 @@ GitHub releases.
|
|
9
9
|
|
10
10
|
from __future__ import annotations
|
11
11
|
|
12
|
+
__all__ = [
|
13
|
+
"ensure_decryptor",
|
14
|
+
"RELEASE_VERSION",
|
15
|
+
]
|
16
|
+
|
12
17
|
import hashlib
|
13
18
|
import platform
|
14
19
|
import stat
|
@@ -20,7 +25,7 @@ import requests
|
|
20
25
|
from novel_downloader.utils.constants import JS_SCRIPT_DIR
|
21
26
|
|
22
27
|
DEST_ROOT: Final[Path] = JS_SCRIPT_DIR
|
23
|
-
GITHUB_OWNER: Final = "
|
28
|
+
GITHUB_OWNER: Final = "saudadez21"
|
24
29
|
GITHUB_REPO: Final = "qidian-decryptor"
|
25
30
|
RELEASE_VERSION: Final = "v1.0.1"
|
26
31
|
BASE_URL: Final = f"https://github.com/{GITHUB_OWNER}/{GITHUB_REPO}/releases/download/{RELEASE_VERSION}"
|
@@ -137,9 +142,3 @@ def _make_executable(p: Path) -> None:
|
|
137
142
|
p.chmod(mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
138
143
|
except PermissionError:
|
139
144
|
pass
|
140
|
-
|
141
|
-
|
142
|
-
__all__ = [
|
143
|
-
"ensure_decryptor",
|
144
|
-
"RELEASE_VERSION",
|
145
|
-
]
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
novel_downloader.core.parsers.qidian.utils.fontmap_recover
|
4
|
+
----------------------------------------------------------
|
5
|
+
|
6
|
+
Tools for generating and applying font character mappings
|
7
|
+
to recover obfuscated Qidian text.
|
8
|
+
"""
|
9
|
+
|
10
|
+
__all__ = [
|
11
|
+
"generate_font_map",
|
12
|
+
"apply_font_mapping",
|
13
|
+
]
|
14
|
+
|
15
|
+
import json
|
16
|
+
import logging
|
17
|
+
from pathlib import Path
|
18
|
+
|
19
|
+
import numpy as np
|
20
|
+
from fontTools.ttLib import TTFont
|
21
|
+
from PIL import ImageFont
|
22
|
+
|
23
|
+
logger = logging.getLogger(__name__)
|
24
|
+
CHAR_FONT_SIZE = 52
|
25
|
+
|
26
|
+
|
27
|
+
def generate_font_map(
|
28
|
+
fixed_font_path: Path,
|
29
|
+
random_font_path: Path,
|
30
|
+
char_set: set[str],
|
31
|
+
refl_set: set[str],
|
32
|
+
cache_dir: Path,
|
33
|
+
batch_size: int = 32,
|
34
|
+
) -> dict[str, str]:
|
35
|
+
"""
|
36
|
+
Build a mapping from scrambled font chars to real chars.
|
37
|
+
|
38
|
+
Uses OCR to compare rendered glyphs from a known (fixed) font and an
|
39
|
+
obfuscated (random) font. Results are cached in JSON so repeated runs
|
40
|
+
are faster.
|
41
|
+
|
42
|
+
:param fixed_font_path: fixed font file.
|
43
|
+
:param random_font_path: random font file.
|
44
|
+
:param char_set: Characters to match directly.
|
45
|
+
:param refl_set: Characters to match in flipped form.
|
46
|
+
:param cache_dir: Directory to save/load cached results.
|
47
|
+
:param batch_size: How many chars to OCR per batch.
|
48
|
+
|
49
|
+
:return: { obf_char: real_char, ... }
|
50
|
+
"""
|
51
|
+
try:
|
52
|
+
from novel_downloader.utils.fontocr import get_font_ocr
|
53
|
+
|
54
|
+
font_ocr = get_font_ocr(batch_size=batch_size)
|
55
|
+
except ImportError:
|
56
|
+
logger.warning("[QidianParser] FontOCR not available, font decoding will skip")
|
57
|
+
return {}
|
58
|
+
|
59
|
+
mapping_result: dict[str, str] = {}
|
60
|
+
fixed_map_file = cache_dir / "fixed_font_map" / f"{Path(fixed_font_path).stem}.json"
|
61
|
+
fixed_map_file.parent.mkdir(parents=True, exist_ok=True)
|
62
|
+
|
63
|
+
# load existing cache
|
64
|
+
try:
|
65
|
+
with open(fixed_map_file, encoding="utf-8") as f:
|
66
|
+
fixed_map = json.load(f)
|
67
|
+
cached_chars = set(fixed_map.keys())
|
68
|
+
mapping_result.update({ch: fixed_map[ch] for ch in char_set if ch in fixed_map})
|
69
|
+
mapping_result.update({ch: fixed_map[ch] for ch in refl_set if ch in fixed_map})
|
70
|
+
char_set = set(char_set) - cached_chars
|
71
|
+
refl_set = set(refl_set) - cached_chars
|
72
|
+
except Exception:
|
73
|
+
fixed_map = {}
|
74
|
+
cached_chars = set()
|
75
|
+
|
76
|
+
# prepare font renderers and cmap sets
|
77
|
+
try:
|
78
|
+
fixed_ttf = TTFont(fixed_font_path)
|
79
|
+
fixed_chars = {chr(c) for c in fixed_ttf.getBestCmap()}
|
80
|
+
fixed_font = ImageFont.truetype(str(fixed_font_path), CHAR_FONT_SIZE)
|
81
|
+
|
82
|
+
random_ttf = TTFont(random_font_path)
|
83
|
+
random_chars = {chr(c) for c in random_ttf.getBestCmap()}
|
84
|
+
random_font = ImageFont.truetype(str(random_font_path), CHAR_FONT_SIZE)
|
85
|
+
except Exception as e:
|
86
|
+
logger.error("[FontOCR] Failed to load TTF fonts: %s", e)
|
87
|
+
return mapping_result
|
88
|
+
|
89
|
+
def _render_batch(chars: list[tuple[str, bool]]) -> list[tuple[str, np.ndarray]]:
|
90
|
+
out = []
|
91
|
+
for ch, reflect in chars:
|
92
|
+
if ch in fixed_chars:
|
93
|
+
font = fixed_font
|
94
|
+
elif ch in random_chars:
|
95
|
+
font = random_font
|
96
|
+
else:
|
97
|
+
continue
|
98
|
+
img = font_ocr.render_char_image_array(ch, font, reflect)
|
99
|
+
if img is not None:
|
100
|
+
out.append((ch, img))
|
101
|
+
return out
|
102
|
+
|
103
|
+
# process normal and reflected sets together
|
104
|
+
for chars, reflect in [(list(char_set), False), (list(refl_set), True)]:
|
105
|
+
for batch_chars in font_ocr._chunked(chars, font_ocr._batch_size):
|
106
|
+
# render all images in this batch
|
107
|
+
to_render = [(ch, reflect) for ch in batch_chars]
|
108
|
+
rendered = _render_batch(to_render)
|
109
|
+
if not rendered:
|
110
|
+
continue
|
111
|
+
|
112
|
+
# query OCR+vec simultaneously
|
113
|
+
imgs_to_query = [img for (ch, img) in rendered]
|
114
|
+
fused = font_ocr.predict(imgs_to_query, top_k=1)
|
115
|
+
|
116
|
+
# pick best per char, apply threshold + cache
|
117
|
+
for (ch, _), preds in zip(rendered, fused, strict=False):
|
118
|
+
if not preds:
|
119
|
+
continue
|
120
|
+
real_char, _ = preds[0]
|
121
|
+
mapping_result[ch] = real_char
|
122
|
+
fixed_map[ch] = real_char
|
123
|
+
|
124
|
+
# persist updated fixed_map
|
125
|
+
try:
|
126
|
+
with open(fixed_map_file, "w", encoding="utf-8") as f:
|
127
|
+
json.dump(fixed_map, f, ensure_ascii=False, indent=2)
|
128
|
+
except Exception as e:
|
129
|
+
logger.error("[FontOCR] Failed to save fixed map: %s", e)
|
130
|
+
|
131
|
+
return mapping_result
|
132
|
+
|
133
|
+
|
134
|
+
def apply_font_mapping(text: str, font_map: dict[str, str]) -> str:
|
135
|
+
"""
|
136
|
+
Replace each character in `text` using `font_map`,
|
137
|
+
leaving unmapped characters unchanged.
|
138
|
+
|
139
|
+
:param text: The input string, possibly containing obfuscated font chars.
|
140
|
+
:param font_map: A dict mapping obfuscated chars to real chars.
|
141
|
+
:return: The de-obfuscated text.
|
142
|
+
"""
|
143
|
+
return "".join(font_map.get(ch, ch) for ch in text)
|
@@ -4,10 +4,6 @@ novel_downloader.core.parsers.qidian.utils.helpers
|
|
4
4
|
--------------------------------------------------
|
5
5
|
|
6
6
|
Shared utility functions for parsing Qidian pages.
|
7
|
-
|
8
|
-
This module provides reusable helpers to:
|
9
|
-
- Extract SSR-rendered JSON page context and structured chapter metadata.
|
10
|
-
- Identify VIP chapters, encrypted content, and viewability conditions.
|
11
7
|
"""
|
12
8
|
|
13
9
|
import json
|
@@ -80,10 +80,10 @@ class QidianNodeDecryptor:
|
|
80
80
|
|
81
81
|
# 3) Download the Fock JS module from Qidian CDN if missing
|
82
82
|
if not self.QIDIAN_FOCK_JS_PATH.exists():
|
83
|
-
from novel_downloader.utils.network import
|
83
|
+
from novel_downloader.utils.network import download
|
84
84
|
|
85
85
|
try:
|
86
|
-
|
86
|
+
download(
|
87
87
|
self.QIDIAN_FOCK_JS_URL,
|
88
88
|
self.script_dir,
|
89
89
|
on_exist="overwrite",
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
novel_downloader.core.parsers.quanben5
|
4
|
+
--------------------------------------
|
5
|
+
|
6
|
+
"""
|
7
|
+
|
8
|
+
from datetime import datetime
|
9
|
+
from typing import Any
|
10
|
+
|
11
|
+
from lxml import html
|
12
|
+
|
13
|
+
from novel_downloader.core.parsers.base import BaseParser
|
14
|
+
from novel_downloader.core.parsers.registry import register_parser
|
15
|
+
from novel_downloader.models import (
|
16
|
+
BookInfoDict,
|
17
|
+
ChapterDict,
|
18
|
+
ChapterInfoDict,
|
19
|
+
VolumeInfoDict,
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
@register_parser(
|
24
|
+
site_keys=["quanben5"],
|
25
|
+
)
|
26
|
+
class Quanben5Parser(BaseParser):
|
27
|
+
"""
|
28
|
+
Parser for 全本小说网 book pages.
|
29
|
+
"""
|
30
|
+
|
31
|
+
def parse_book_info(
|
32
|
+
self,
|
33
|
+
html_list: list[str],
|
34
|
+
**kwargs: Any,
|
35
|
+
) -> BookInfoDict | None:
|
36
|
+
if not html_list:
|
37
|
+
return None
|
38
|
+
|
39
|
+
tree = html.fromstring(html_list[0])
|
40
|
+
book_name = self._first_str(tree.xpath("//h3/span/text()"))
|
41
|
+
author = self._first_str(
|
42
|
+
tree.xpath(
|
43
|
+
'//p[@class="info"][contains(., "作者")]/span[@class="author"]/text()'
|
44
|
+
)
|
45
|
+
)
|
46
|
+
cover_url = self._first_str(tree.xpath('//div[@class="pic"]/img/@src'))
|
47
|
+
category = self._first_str(
|
48
|
+
tree.xpath('//p[@class="info"][contains(., "类别")]/span/text()')
|
49
|
+
)
|
50
|
+
tags = [category] if category else []
|
51
|
+
update_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
52
|
+
summary = self._first_str(tree.xpath('//p[@class="description"]/text()'))
|
53
|
+
|
54
|
+
chapters: list[ChapterInfoDict] = []
|
55
|
+
for li in tree.xpath('//ul[@class="list"]/li'):
|
56
|
+
link = li.xpath(".//a")[0]
|
57
|
+
href = link.get("href", "").strip()
|
58
|
+
title = self._first_str(link.xpath(".//span/text()"))
|
59
|
+
# '/n/toutian/83840.html' -> '83840'
|
60
|
+
chapter_id = href.rstrip(".html").split("/")[-1]
|
61
|
+
chapters.append({"title": title, "url": href, "chapterId": chapter_id})
|
62
|
+
|
63
|
+
volumes: list[VolumeInfoDict] = [{"volume_name": "正文", "chapters": chapters}]
|
64
|
+
|
65
|
+
return {
|
66
|
+
"book_name": book_name,
|
67
|
+
"author": author,
|
68
|
+
"cover_url": cover_url,
|
69
|
+
"update_time": update_time,
|
70
|
+
"tags": tags,
|
71
|
+
"summary": summary,
|
72
|
+
"volumes": volumes,
|
73
|
+
"extra": {},
|
74
|
+
}
|
75
|
+
|
76
|
+
def parse_chapter(
|
77
|
+
self,
|
78
|
+
html_list: list[str],
|
79
|
+
chapter_id: str,
|
80
|
+
**kwargs: Any,
|
81
|
+
) -> ChapterDict | None:
|
82
|
+
if not html_list:
|
83
|
+
return None
|
84
|
+
|
85
|
+
tree = html.fromstring(html_list[0])
|
86
|
+
|
87
|
+
# Extract the chapter title
|
88
|
+
title = self._first_str(tree.xpath('//h1[@class="title1"]/text()'))
|
89
|
+
|
90
|
+
# Extract all <p> text within the content container
|
91
|
+
paragraphs = tree.xpath('//div[@id="content"]/p/text()')
|
92
|
+
# Clean whitespace and join with double newlines
|
93
|
+
content = "\n".join(p.strip() for p in paragraphs if p.strip())
|
94
|
+
|
95
|
+
if not content:
|
96
|
+
return None
|
97
|
+
|
98
|
+
return {
|
99
|
+
"id": chapter_id,
|
100
|
+
"title": title,
|
101
|
+
"content": content,
|
102
|
+
"extra": {"site": "quanben5"},
|
103
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
novel_downloader.core.parsers.registry
|
4
|
+
--------------------------------------
|
5
|
+
|
6
|
+
Registry and factory helpers for creating site-specific parsers.
|
7
|
+
"""
|
8
|
+
|
9
|
+
__all__ = ["register_parser", "get_parser"]
|
10
|
+
|
11
|
+
from collections.abc import Callable, Sequence
|
12
|
+
from typing import TypeVar
|
13
|
+
|
14
|
+
from novel_downloader.core.interfaces import ParserProtocol
|
15
|
+
from novel_downloader.models import ParserConfig
|
16
|
+
|
17
|
+
ParserBuilder = Callable[[ParserConfig], ParserProtocol]
|
18
|
+
|
19
|
+
P = TypeVar("P", bound=ParserProtocol)
|
20
|
+
_PARSER_MAP: dict[str, ParserBuilder] = {}
|
21
|
+
|
22
|
+
|
23
|
+
def register_parser(
|
24
|
+
site_keys: Sequence[str],
|
25
|
+
) -> Callable[[type[P]], type[P]]:
|
26
|
+
"""
|
27
|
+
Decorator to register a parser class under given keys.
|
28
|
+
|
29
|
+
:param site_keys: Sequence of site identifiers
|
30
|
+
:param backends: Sequence of backend types
|
31
|
+
:return: A class decorator that populates _PARSER_MAP.
|
32
|
+
"""
|
33
|
+
|
34
|
+
def decorator(cls: type[P]) -> type[P]:
|
35
|
+
for site in site_keys:
|
36
|
+
site_lower = site.lower()
|
37
|
+
_PARSER_MAP[site_lower] = cls
|
38
|
+
return cls
|
39
|
+
|
40
|
+
return decorator
|
41
|
+
|
42
|
+
|
43
|
+
def get_parser(site: str, config: ParserConfig) -> ParserProtocol:
|
44
|
+
"""
|
45
|
+
Returns a site-specific parser instance.
|
46
|
+
|
47
|
+
:param site: Site name (e.g., 'qidian')
|
48
|
+
:param config: Configuration for the parser
|
49
|
+
:return: An instance of a parser class
|
50
|
+
"""
|
51
|
+
site_key = site.lower()
|
52
|
+
try:
|
53
|
+
parser_cls = _PARSER_MAP[site_key]
|
54
|
+
except KeyError as err:
|
55
|
+
raise ValueError(f"Unsupported site: {site!r}") from err
|
56
|
+
|
57
|
+
return parser_cls(config)
|