novel-downloader 1.5.0__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 +1 -3
- novel_downloader/cli/clean.py +21 -88
- novel_downloader/cli/config.py +26 -21
- novel_downloader/cli/download.py +77 -64
- novel_downloader/cli/export.py +16 -20
- novel_downloader/cli/main.py +1 -1
- novel_downloader/cli/search.py +62 -65
- novel_downloader/cli/ui.py +156 -0
- novel_downloader/config/__init__.py +8 -5
- novel_downloader/config/adapter.py +65 -105
- novel_downloader/config/{loader.py → file_io.py} +53 -26
- novel_downloader/core/__init__.py +1 -0
- 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/{searchers/qidian.py → archived/qidian/searcher.py} +12 -20
- novel_downloader/core/archived/wanbengo/searcher.py +98 -0
- novel_downloader/core/archived/xshbook/searcher.py +93 -0
- novel_downloader/core/downloaders/__init__.py +3 -24
- novel_downloader/core/downloaders/base.py +49 -23
- novel_downloader/core/downloaders/common.py +191 -137
- novel_downloader/core/downloaders/qianbi.py +187 -146
- novel_downloader/core/downloaders/qidian.py +187 -141
- novel_downloader/core/downloaders/registry.py +4 -2
- novel_downloader/core/downloaders/signals.py +46 -0
- novel_downloader/core/exporters/__init__.py +3 -20
- novel_downloader/core/exporters/base.py +33 -37
- novel_downloader/core/exporters/common/__init__.py +1 -2
- novel_downloader/core/exporters/common/epub.py +15 -10
- novel_downloader/core/exporters/common/main_exporter.py +19 -12
- novel_downloader/core/exporters/common/txt.py +14 -9
- novel_downloader/core/exporters/epub_util.py +59 -29
- novel_downloader/core/exporters/linovelib/__init__.py +1 -0
- novel_downloader/core/exporters/linovelib/epub.py +23 -25
- novel_downloader/core/exporters/linovelib/main_exporter.py +8 -12
- novel_downloader/core/exporters/linovelib/txt.py +17 -11
- novel_downloader/core/exporters/qidian.py +2 -8
- novel_downloader/core/exporters/registry.py +4 -2
- novel_downloader/core/exporters/txt_util.py +7 -7
- novel_downloader/core/fetchers/__init__.py +54 -48
- novel_downloader/core/fetchers/aaatxt.py +83 -0
- novel_downloader/core/fetchers/{biquge/session.py → b520.py} +6 -11
- novel_downloader/core/fetchers/{base/session.py → base.py} +37 -46
- novel_downloader/core/fetchers/{biquge/browser.py → biquyuedu.py} +12 -17
- 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} +19 -12
- 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} +19 -28
- novel_downloader/core/fetchers/ixdzs8.py +113 -0
- novel_downloader/core/fetchers/jpxs123.py +101 -0
- novel_downloader/core/fetchers/lewenn.py +83 -0
- novel_downloader/core/fetchers/{linovelib/session.py → linovelib.py} +12 -13
- 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} +5 -10
- novel_downloader/core/fetchers/{qidian/session.py → qidian.py} +46 -39
- 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 +5 -16
- novel_downloader/core/fetchers/{sfacg/session.py → sfacg.py} +7 -10
- novel_downloader/core/fetchers/shencou.py +106 -0
- novel_downloader/core/fetchers/shuhaige.py +84 -0
- novel_downloader/core/fetchers/tongrenquan.py +84 -0
- novel_downloader/core/fetchers/ttkan.py +95 -0
- novel_downloader/core/fetchers/wanbengo.py +83 -0
- 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} +19 -12
- novel_downloader/core/fetchers/yibige.py +114 -0
- novel_downloader/core/interfaces/__init__.py +1 -9
- 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 +9 -1
- novel_downloader/core/parsers/__init__.py +49 -12
- 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.py +61 -66
- 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.py +48 -64
- novel_downloader/core/parsers/piaotia.py +189 -0
- novel_downloader/core/parsers/qbtr.py +136 -0
- novel_downloader/core/parsers/qianbi.py +48 -50
- novel_downloader/core/parsers/qidian/book_info_parser.py +58 -59
- novel_downloader/core/parsers/qidian/chapter_encrypted.py +272 -330
- novel_downloader/core/parsers/qidian/chapter_normal.py +24 -55
- novel_downloader/core/parsers/qidian/main_parser.py +11 -38
- novel_downloader/core/parsers/qidian/utils/__init__.py +1 -0
- novel_downloader/core/parsers/qidian/utils/decryptor_fetcher.py +1 -1
- 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/quanben5.py +103 -0
- novel_downloader/core/parsers/registry.py +5 -16
- novel_downloader/core/parsers/sfacg.py +38 -45
- 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 +87 -131
- novel_downloader/core/parsers/yibige.py +166 -0
- novel_downloader/core/searchers/__init__.py +34 -3
- novel_downloader/core/searchers/aaatxt.py +107 -0
- novel_downloader/core/searchers/{biquge.py → b520.py} +29 -28
- novel_downloader/core/searchers/base.py +112 -36
- novel_downloader/core/searchers/dxmwx.py +105 -0
- novel_downloader/core/searchers/eightnovel.py +84 -0
- novel_downloader/core/searchers/esjzone.py +43 -25
- 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 +74 -40
- novel_downloader/core/searchers/quanben5.py +144 -0
- novel_downloader/core/searchers/registry.py +24 -8
- 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 +31 -82
- novel_downloader/locales/zh.json +32 -83
- novel_downloader/models/__init__.py +21 -22
- novel_downloader/models/book.py +44 -0
- novel_downloader/models/config.py +4 -37
- novel_downloader/models/login.py +1 -1
- novel_downloader/models/search.py +5 -0
- novel_downloader/resources/config/settings.toml +8 -70
- novel_downloader/resources/json/xiguashuwu.json +718 -0
- novel_downloader/utils/__init__.py +13 -22
- novel_downloader/utils/chapter_storage.py +3 -2
- novel_downloader/utils/constants.py +4 -29
- 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 +1 -1
- novel_downloader/utils/epub/constants.py +57 -16
- novel_downloader/utils/epub/documents.py +88 -194
- novel_downloader/utils/epub/models.py +0 -14
- novel_downloader/utils/epub/utils.py +63 -96
- novel_downloader/utils/file_utils/__init__.py +2 -23
- novel_downloader/utils/file_utils/io.py +3 -113
- novel_downloader/utils/file_utils/sanitize.py +0 -4
- novel_downloader/utils/fontocr.py +207 -0
- novel_downloader/utils/logger.py +8 -16
- novel_downloader/utils/network.py +2 -2
- novel_downloader/utils/state.py +4 -90
- novel_downloader/utils/text_utils/__init__.py +1 -7
- novel_downloader/utils/text_utils/diff_display.py +5 -7
- novel_downloader/utils/time_utils/__init__.py +5 -11
- novel_downloader/utils/time_utils/datetime_utils.py +20 -29
- novel_downloader/utils/time_utils/sleep_utils.py +4 -8
- 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.5.0.dist-info → novel_downloader-2.0.0.dist-info}/entry_points.txt +1 -1
- novel_downloader/core/downloaders/biquge.py +0 -29
- novel_downloader/core/downloaders/esjzone.py +0 -29
- novel_downloader/core/downloaders/linovelib.py +0 -29
- novel_downloader/core/downloaders/sfacg.py +0 -29
- novel_downloader/core/downloaders/yamibo.py +0 -29
- novel_downloader/core/exporters/biquge.py +0 -22
- novel_downloader/core/exporters/esjzone.py +0 -22
- novel_downloader/core/exporters/qianbi.py +0 -22
- novel_downloader/core/exporters/sfacg.py +0 -22
- novel_downloader/core/exporters/yamibo.py +0 -22
- novel_downloader/core/fetchers/base/__init__.py +0 -14
- novel_downloader/core/fetchers/base/browser.py +0 -422
- novel_downloader/core/fetchers/biquge/__init__.py +0 -14
- novel_downloader/core/fetchers/esjzone/__init__.py +0 -14
- novel_downloader/core/fetchers/esjzone/browser.py +0 -209
- novel_downloader/core/fetchers/linovelib/__init__.py +0 -14
- novel_downloader/core/fetchers/linovelib/browser.py +0 -198
- 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 -326
- novel_downloader/core/fetchers/sfacg/__init__.py +0 -14
- novel_downloader/core/fetchers/sfacg/browser.py +0 -194
- novel_downloader/core/fetchers/yamibo/__init__.py +0 -14
- novel_downloader/core/fetchers/yamibo/browser.py +0 -234
- novel_downloader/core/parsers/biquge.py +0 -139
- novel_downloader/models/chapter.py +0 -25
- novel_downloader/models/types.py +0 -13
- 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/hash_store.py +0 -280
- novel_downloader/utils/fontocr/hash_utils.py +0 -103
- novel_downloader/utils/fontocr/model_loader.py +0 -69
- novel_downloader/utils/fontocr/ocr_v1.py +0 -315
- novel_downloader/utils/fontocr/ocr_v2.py +0 -764
- novel_downloader/utils/fontocr/ocr_v3.py +0 -744
- novel_downloader-1.5.0.dist-info/METADATA +0 -196
- novel_downloader-1.5.0.dist-info/RECORD +0 -164
- {novel_downloader-1.5.0.dist-info → novel_downloader-2.0.0.dist-info}/WHEEL +0 -0
- {novel_downloader-1.5.0.dist-info → novel_downloader-2.0.0.dist-info}/licenses/LICENSE +0 -0
- {novel_downloader-1.5.0.dist-info → novel_downloader-2.0.0.dist-info}/top_level.txt +0 -0
@@ -1,198 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
"""
|
3
|
-
novel_downloader.core.fetchers.linovelib.browser
|
4
|
-
------------------------------------------------
|
5
|
-
|
6
|
-
"""
|
7
|
-
|
8
|
-
import re
|
9
|
-
from typing import Any
|
10
|
-
|
11
|
-
from novel_downloader.core.fetchers.base import BaseBrowser
|
12
|
-
from novel_downloader.core.fetchers.registry import register_fetcher
|
13
|
-
from novel_downloader.models import FetcherConfig
|
14
|
-
from novel_downloader.utils import async_sleep_with_random_delay
|
15
|
-
|
16
|
-
|
17
|
-
@register_fetcher(
|
18
|
-
site_keys=["linovelib"],
|
19
|
-
backends=["browser"],
|
20
|
-
)
|
21
|
-
class LinovelibBrowser(BaseBrowser):
|
22
|
-
"""
|
23
|
-
A browser class for interacting with Linovelib (www.linovelib.com) novel website.
|
24
|
-
"""
|
25
|
-
|
26
|
-
BASE_URL = "https://www.linovelib.com"
|
27
|
-
BOOK_INFO_URL = "https://www.linovelib.com/novel/{book_id}.html"
|
28
|
-
BOOK_CATALOG_UTL = "https://www.linovelib.com/novel/{book_id}/catalog"
|
29
|
-
BOOK_VOL_URL = "https://www.linovelib.com/novel/{book_id}/{vol_id}.html"
|
30
|
-
CHAPTER_URL = "https://www.linovelib.com/novel/{book_id}/{chapter_id}.html"
|
31
|
-
|
32
|
-
_VOL_ID_PATTERN: re.Pattern[str] = re.compile(r"/novel/\d+/(vol_\d+)\.html")
|
33
|
-
|
34
|
-
def __init__(
|
35
|
-
self,
|
36
|
-
config: FetcherConfig,
|
37
|
-
reuse_page: bool = False,
|
38
|
-
**kwargs: Any,
|
39
|
-
) -> None:
|
40
|
-
super().__init__("linovelib", config, reuse_page, **kwargs)
|
41
|
-
|
42
|
-
async def get_book_info(
|
43
|
-
self,
|
44
|
-
book_id: str,
|
45
|
-
**kwargs: Any,
|
46
|
-
) -> list[str]:
|
47
|
-
"""
|
48
|
-
Fetch the raw HTML of the book info page.
|
49
|
-
|
50
|
-
:param book_id: The book identifier.
|
51
|
-
:return: A list of HTML strings: [info_html, vol1_html, ..., volN_html]
|
52
|
-
"""
|
53
|
-
url = self.book_info_url(book_id=book_id)
|
54
|
-
info_html = await self.fetch(url, **kwargs)
|
55
|
-
|
56
|
-
vol_ids = self._extract_vol_ids(info_html)
|
57
|
-
vol_ids.reverse()
|
58
|
-
if not vol_ids:
|
59
|
-
url = self.catalog_url(book_id=book_id)
|
60
|
-
catalog_html = await self.fetch(url, **kwargs)
|
61
|
-
vol_ids = self._extract_vol_ids(catalog_html)
|
62
|
-
|
63
|
-
vol_htmls = []
|
64
|
-
for vol_id in vol_ids:
|
65
|
-
await async_sleep_with_random_delay(
|
66
|
-
self.request_interval,
|
67
|
-
mul_spread=1.1,
|
68
|
-
max_sleep=self.request_interval + 2,
|
69
|
-
)
|
70
|
-
html = await self.get_book_volume(book_id, vol_id, **kwargs)
|
71
|
-
if html:
|
72
|
-
vol_htmls.append(html)
|
73
|
-
|
74
|
-
return [info_html] + vol_htmls
|
75
|
-
|
76
|
-
async def get_book_volume(
|
77
|
-
self,
|
78
|
-
book_id: str,
|
79
|
-
vol_id: str,
|
80
|
-
**kwargs: Any,
|
81
|
-
) -> str:
|
82
|
-
"""
|
83
|
-
Fetch the HTML content of a specific volume.
|
84
|
-
|
85
|
-
:param book_id: The book identifier.
|
86
|
-
:param vol_id: The volume identifier.
|
87
|
-
:return: The volume content as a string.
|
88
|
-
"""
|
89
|
-
url = self.volume_url(book_id=book_id, vol_id=vol_id)
|
90
|
-
return await self.fetch(url, **kwargs)
|
91
|
-
|
92
|
-
async def get_book_chapter(
|
93
|
-
self,
|
94
|
-
book_id: str,
|
95
|
-
chapter_id: str,
|
96
|
-
**kwargs: Any,
|
97
|
-
) -> list[str]:
|
98
|
-
"""
|
99
|
-
Fetch the raw HTML of a single chapter asynchronously.
|
100
|
-
|
101
|
-
:param book_id: The book identifier.
|
102
|
-
:param chapter_id: The chapter identifier.
|
103
|
-
:return: The chapter content as a string.
|
104
|
-
"""
|
105
|
-
html_pages: list[str] = []
|
106
|
-
idx = 1
|
107
|
-
|
108
|
-
while True:
|
109
|
-
chapter_suffix = chapter_id if idx == 1 else f"{chapter_id}_{idx}"
|
110
|
-
relative_path = self.relative_chapter_url(book_id, chapter_suffix)
|
111
|
-
full_url = self.BASE_URL + relative_path
|
112
|
-
|
113
|
-
if idx > 1 and relative_path not in html_pages[-1]:
|
114
|
-
break
|
115
|
-
|
116
|
-
try:
|
117
|
-
html = await self.fetch(full_url, **kwargs)
|
118
|
-
except Exception as exc:
|
119
|
-
self.logger.warning(
|
120
|
-
"[async] get_book_chapter(%s page %d) failed: %s",
|
121
|
-
chapter_id,
|
122
|
-
idx,
|
123
|
-
exc,
|
124
|
-
)
|
125
|
-
break
|
126
|
-
|
127
|
-
html_pages.append(html)
|
128
|
-
idx += 1
|
129
|
-
await async_sleep_with_random_delay(
|
130
|
-
self.request_interval,
|
131
|
-
mul_spread=1.1,
|
132
|
-
max_sleep=self.request_interval + 2,
|
133
|
-
)
|
134
|
-
|
135
|
-
return html_pages
|
136
|
-
|
137
|
-
@classmethod
|
138
|
-
def book_info_url(cls, book_id: str) -> str:
|
139
|
-
"""
|
140
|
-
Construct the URL for fetching a book's info page.
|
141
|
-
|
142
|
-
:param book_id: The identifier of the book.
|
143
|
-
:return: Fully qualified URL for the book info page.
|
144
|
-
"""
|
145
|
-
return cls.BOOK_INFO_URL.format(book_id=book_id)
|
146
|
-
|
147
|
-
@classmethod
|
148
|
-
def catalog_url(cls, book_id: str) -> str:
|
149
|
-
"""
|
150
|
-
Construct the URL for fetching a catalog page.
|
151
|
-
|
152
|
-
:param book_id: The identifier of the book.
|
153
|
-
:return: Fully qualified catalog URL.
|
154
|
-
"""
|
155
|
-
return cls.BOOK_CATALOG_UTL.format(book_id=book_id)
|
156
|
-
|
157
|
-
@classmethod
|
158
|
-
def volume_url(cls, book_id: str, vol_id: str) -> str:
|
159
|
-
"""
|
160
|
-
Construct the URL for fetching a specific volume.
|
161
|
-
|
162
|
-
:param book_id: The identifier of the book.
|
163
|
-
:param vol_id: The identifier of the volume.
|
164
|
-
:return: Fully qualified volume URL.
|
165
|
-
"""
|
166
|
-
return cls.BOOK_VOL_URL.format(book_id=book_id, vol_id=vol_id)
|
167
|
-
|
168
|
-
@classmethod
|
169
|
-
def chapter_url(cls, book_id: str, chapter_id: str) -> str:
|
170
|
-
"""
|
171
|
-
Construct the URL for fetching a specific chapter.
|
172
|
-
|
173
|
-
:param book_id: The identifier of the book.
|
174
|
-
:param chapter_id: The identifier of the chapter.
|
175
|
-
:return: Fully qualified chapter URL.
|
176
|
-
"""
|
177
|
-
return cls.CHAPTER_URL.format(book_id=book_id, chapter_id=chapter_id)
|
178
|
-
|
179
|
-
@property
|
180
|
-
def hostname(self) -> str:
|
181
|
-
return "www.linovelib.com"
|
182
|
-
|
183
|
-
@classmethod
|
184
|
-
def relative_chapter_url(cls, book_id: str, chapter_id: str) -> str:
|
185
|
-
"""
|
186
|
-
Return the relative URL path for a given chapter.
|
187
|
-
"""
|
188
|
-
return f"/novel/{book_id}/{chapter_id}.html"
|
189
|
-
|
190
|
-
def _extract_vol_ids(self, html_str: str) -> list[str]:
|
191
|
-
"""
|
192
|
-
Extract volume IDs (like 'vol_12345') from the info HTML.
|
193
|
-
|
194
|
-
:param html_str: Raw HTML of the info page.
|
195
|
-
:return: List of volume ID strings.
|
196
|
-
"""
|
197
|
-
# /novel/{book_id}/{vol_id}.html
|
198
|
-
return self._VOL_ID_PATTERN.findall(html_str)
|
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
"""
|
3
|
-
novel_downloader.core.fetchers.qianbi
|
4
|
-
-------------------------------------
|
5
|
-
|
6
|
-
"""
|
7
|
-
|
8
|
-
__all__ = [
|
9
|
-
"QianbiBrowser",
|
10
|
-
"QianbiSession",
|
11
|
-
]
|
12
|
-
|
13
|
-
from .browser import QianbiBrowser
|
14
|
-
from .session import QianbiSession
|
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
"""
|
3
|
-
novel_downloader.core.fetchers.qidian
|
4
|
-
-------------------------------------
|
5
|
-
|
6
|
-
"""
|
7
|
-
|
8
|
-
__all__ = [
|
9
|
-
"QidianBrowser",
|
10
|
-
"QidianSession",
|
11
|
-
]
|
12
|
-
|
13
|
-
from .browser import QidianBrowser
|
14
|
-
from .session import QidianSession
|
@@ -1,326 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
"""
|
3
|
-
novel_downloader.core.fetchers.qidian.browser
|
4
|
-
---------------------------------------------
|
5
|
-
|
6
|
-
"""
|
7
|
-
|
8
|
-
import asyncio
|
9
|
-
from typing import Any
|
10
|
-
|
11
|
-
from playwright.async_api import Page
|
12
|
-
|
13
|
-
from novel_downloader.core.fetchers.base import BaseBrowser
|
14
|
-
from novel_downloader.core.fetchers.registry import register_fetcher
|
15
|
-
from novel_downloader.models import FetcherConfig, LoginField
|
16
|
-
from novel_downloader.utils.i18n import t
|
17
|
-
|
18
|
-
|
19
|
-
@register_fetcher(
|
20
|
-
site_keys=["qidian", "qd"],
|
21
|
-
backends=["browser"],
|
22
|
-
)
|
23
|
-
class QidianBrowser(BaseBrowser):
|
24
|
-
"""
|
25
|
-
A browser class for interacting with the Qidian (www.qidian.com) novel website.
|
26
|
-
"""
|
27
|
-
|
28
|
-
WAIT_TIME = 2.0
|
29
|
-
HOMEPAGE_URL = "https://www.qidian.com/"
|
30
|
-
BOOKCASE_URL = "https://my.qidian.com/bookcase/"
|
31
|
-
# BOOK_INFO_URL = "https://book.qidian.com/info/{book_id}/"
|
32
|
-
BOOK_INFO_URL = "https://www.qidian.com/book/{book_id}/"
|
33
|
-
CHAPTER_URL = "https://www.qidian.com/chapter/{book_id}/{chapter_id}/"
|
34
|
-
|
35
|
-
LOGIN_URL = "https://passport.qidian.com/"
|
36
|
-
|
37
|
-
def __init__(
|
38
|
-
self,
|
39
|
-
config: FetcherConfig,
|
40
|
-
reuse_page: bool = False,
|
41
|
-
**kwargs: Any,
|
42
|
-
) -> None:
|
43
|
-
super().__init__("qidian", config, reuse_page, **kwargs)
|
44
|
-
|
45
|
-
async def login(
|
46
|
-
self,
|
47
|
-
username: str = "",
|
48
|
-
password: str = "",
|
49
|
-
cookies: dict[str, str] | None = None,
|
50
|
-
attempt: int = 1,
|
51
|
-
**kwargs: Any,
|
52
|
-
) -> bool:
|
53
|
-
self._is_logged_in = await self._check_login_status()
|
54
|
-
return self._is_logged_in
|
55
|
-
|
56
|
-
async def get_book_info(
|
57
|
-
self,
|
58
|
-
book_id: str,
|
59
|
-
**kwargs: Any,
|
60
|
-
) -> list[str]:
|
61
|
-
"""
|
62
|
-
Fetch the raw HTML of the book info page asynchronously.
|
63
|
-
|
64
|
-
:param book_id: The book identifier.
|
65
|
-
:return: The page content as a string.
|
66
|
-
"""
|
67
|
-
url = self.book_info_url(book_id=book_id)
|
68
|
-
return [await self.fetch(url, delay=self.WAIT_TIME, **kwargs)]
|
69
|
-
|
70
|
-
async def get_book_chapter(
|
71
|
-
self,
|
72
|
-
book_id: str,
|
73
|
-
chapter_id: str,
|
74
|
-
**kwargs: Any,
|
75
|
-
) -> list[str]:
|
76
|
-
"""
|
77
|
-
Fetch the raw HTML of a single chapter asynchronously.
|
78
|
-
|
79
|
-
:param book_id: The book identifier.
|
80
|
-
:param chapter_id: The chapter identifier.
|
81
|
-
:return: The chapter content as a string.
|
82
|
-
"""
|
83
|
-
catalog_url = self.book_info_url(book_id=book_id)
|
84
|
-
url = self.chapter_url(book_id=book_id, chapter_id=chapter_id)
|
85
|
-
return [
|
86
|
-
await self.fetch(url, referer=catalog_url, delay=self.WAIT_TIME, **kwargs)
|
87
|
-
]
|
88
|
-
|
89
|
-
async def get_bookcase(
|
90
|
-
self,
|
91
|
-
**kwargs: Any,
|
92
|
-
) -> list[str]:
|
93
|
-
"""
|
94
|
-
Retrieve the user's *bookcase* page.
|
95
|
-
|
96
|
-
:return: The HTML markup of the bookcase page.
|
97
|
-
"""
|
98
|
-
url = self.bookcase_url()
|
99
|
-
return [await self.fetch(url, delay=self.WAIT_TIME, **kwargs)]
|
100
|
-
|
101
|
-
async def get_homepage(
|
102
|
-
self,
|
103
|
-
**kwargs: Any,
|
104
|
-
) -> list[str]:
|
105
|
-
"""
|
106
|
-
Retrieve the site home page.
|
107
|
-
|
108
|
-
:return: The HTML markup of the home page.
|
109
|
-
"""
|
110
|
-
url = self.homepage_url()
|
111
|
-
return [await self.fetch(url, delay=self.WAIT_TIME, **kwargs)]
|
112
|
-
|
113
|
-
async def set_interactive_mode(self, enable: bool) -> bool:
|
114
|
-
"""
|
115
|
-
Enable or disable interactive mode for manual login.
|
116
|
-
|
117
|
-
:param enable: True to enable, False to disable interactive mode.
|
118
|
-
:return: True if operation or login check succeeded, False otherwise.
|
119
|
-
"""
|
120
|
-
if enable:
|
121
|
-
if self.headless:
|
122
|
-
await self._restart_browser(headless=False)
|
123
|
-
if self._manual_page is None:
|
124
|
-
self._manual_page = await self.context.new_page()
|
125
|
-
await self._manual_page.goto(self.LOGIN_URL)
|
126
|
-
return True
|
127
|
-
|
128
|
-
# restore
|
129
|
-
if self._manual_page:
|
130
|
-
await self._manual_page.close()
|
131
|
-
self._manual_page = None
|
132
|
-
if self.headless:
|
133
|
-
await self._restart_browser(headless=True)
|
134
|
-
self._is_logged_in = await self._check_login_status()
|
135
|
-
return self.is_logged_in
|
136
|
-
|
137
|
-
@property
|
138
|
-
def login_fields(self) -> list[LoginField]:
|
139
|
-
return [
|
140
|
-
LoginField(
|
141
|
-
name="manual_login",
|
142
|
-
label="手动登录",
|
143
|
-
type="manual_login",
|
144
|
-
required=True,
|
145
|
-
description=t("login_prompt_intro"),
|
146
|
-
)
|
147
|
-
]
|
148
|
-
|
149
|
-
@classmethod
|
150
|
-
def homepage_url(cls) -> str:
|
151
|
-
"""
|
152
|
-
Construct the URL for the site home page.
|
153
|
-
|
154
|
-
:return: Fully qualified URL of the home page.
|
155
|
-
"""
|
156
|
-
return cls.HOMEPAGE_URL
|
157
|
-
|
158
|
-
@classmethod
|
159
|
-
def bookcase_url(cls) -> str:
|
160
|
-
"""
|
161
|
-
Construct the URL for the user's bookcase page.
|
162
|
-
|
163
|
-
:return: Fully qualified URL of the bookcase.
|
164
|
-
"""
|
165
|
-
return cls.BOOKCASE_URL
|
166
|
-
|
167
|
-
@classmethod
|
168
|
-
def book_info_url(cls, book_id: str) -> str:
|
169
|
-
"""
|
170
|
-
Construct the URL for fetching a book's info page.
|
171
|
-
|
172
|
-
:param book_id: The identifier of the book.
|
173
|
-
:return: Fully qualified URL for the book info page.
|
174
|
-
"""
|
175
|
-
return cls.BOOK_INFO_URL.format(book_id=book_id)
|
176
|
-
|
177
|
-
@classmethod
|
178
|
-
def chapter_url(cls, book_id: str, chapter_id: str) -> str:
|
179
|
-
"""
|
180
|
-
Construct the URL for fetching a specific chapter.
|
181
|
-
|
182
|
-
:param book_id: The identifier of the book.
|
183
|
-
:param chapter_id: The identifier of the chapter.
|
184
|
-
:return: Fully qualified chapter URL.
|
185
|
-
"""
|
186
|
-
return cls.CHAPTER_URL.format(book_id=book_id, chapter_id=chapter_id)
|
187
|
-
|
188
|
-
@property
|
189
|
-
def hostname(self) -> str:
|
190
|
-
return "www.qidian.com"
|
191
|
-
|
192
|
-
async def _check_login_status(self) -> bool:
|
193
|
-
"""
|
194
|
-
Check whether the user is currently logged in by inspecting
|
195
|
-
the visibility of the 'sign-in' element on the homepage.
|
196
|
-
|
197
|
-
:return: True if the user appears to be logged in, False otherwise.
|
198
|
-
"""
|
199
|
-
try:
|
200
|
-
page = await self.context.new_page()
|
201
|
-
await self._login_auto(page)
|
202
|
-
await self._dismiss_overlay(page)
|
203
|
-
await page.goto(self.HOMEPAGE_URL, wait_until="networkidle")
|
204
|
-
sign_in_elem = await page.query_selector("#login-box .sign-in")
|
205
|
-
sign_out_elem = await page.query_selector("#login-box .sign-out")
|
206
|
-
|
207
|
-
sign_in_class = (
|
208
|
-
(await sign_in_elem.get_attribute("class") or "")
|
209
|
-
if sign_in_elem
|
210
|
-
else ""
|
211
|
-
)
|
212
|
-
sign_out_class = (
|
213
|
-
(await sign_out_elem.get_attribute("class") or "")
|
214
|
-
if sign_out_elem
|
215
|
-
else ""
|
216
|
-
)
|
217
|
-
|
218
|
-
sign_in_hidden = "hidden" in sign_in_class
|
219
|
-
sign_out_hidden = "hidden" in sign_out_class
|
220
|
-
|
221
|
-
await page.close()
|
222
|
-
|
223
|
-
# if sign_in_visible and not sign_out_visible:
|
224
|
-
if not sign_in_hidden and sign_out_hidden:
|
225
|
-
self.logger.debug("[auth] Detected as logged in.")
|
226
|
-
return True
|
227
|
-
else:
|
228
|
-
self.logger.debug("[auth] Detected as not logged in.")
|
229
|
-
return False
|
230
|
-
except Exception as e:
|
231
|
-
self.logger.warning("[auth] Error while checking login status: %s", e)
|
232
|
-
return False
|
233
|
-
|
234
|
-
async def _dismiss_overlay(
|
235
|
-
self,
|
236
|
-
page: Page,
|
237
|
-
timeout: float = 2.0,
|
238
|
-
) -> None:
|
239
|
-
"""
|
240
|
-
Detect and close any full-page overlay mask that might block the login UI.
|
241
|
-
"""
|
242
|
-
try:
|
243
|
-
mask = await page.wait_for_selector("div.mask", timeout=timeout * 1000)
|
244
|
-
if not mask or not await mask.is_visible():
|
245
|
-
return
|
246
|
-
|
247
|
-
self.logger.debug("[auth] Overlay mask detected; attempting to close.")
|
248
|
-
|
249
|
-
iframe_element = await page.wait_for_selector(
|
250
|
-
"#loginIfr",
|
251
|
-
timeout=timeout * 1000,
|
252
|
-
)
|
253
|
-
if iframe_element is None:
|
254
|
-
self.logger.debug("[auth] Login iframe not found.")
|
255
|
-
return
|
256
|
-
|
257
|
-
iframe = await iframe_element.content_frame()
|
258
|
-
if iframe is None:
|
259
|
-
self.logger.debug("[auth] Unable to access iframe content.")
|
260
|
-
return
|
261
|
-
|
262
|
-
# 点击关闭按钮
|
263
|
-
await iframe.click("#close", timeout=2000)
|
264
|
-
self.logger.debug("[auth] Overlay mask closed.")
|
265
|
-
|
266
|
-
except Exception as e:
|
267
|
-
self.logger.debug("[auth] Error handling overlay mask: %s", e)
|
268
|
-
|
269
|
-
async def _login_auto(
|
270
|
-
self,
|
271
|
-
page: Page,
|
272
|
-
timeout: float = 5.0,
|
273
|
-
) -> None:
|
274
|
-
"""
|
275
|
-
Attempt one automatic login interaction (click once and check).
|
276
|
-
|
277
|
-
:param page: Playwright Page object to interact with.
|
278
|
-
:param timeout: Seconds to wait for login box to appear.
|
279
|
-
:return: True if login successful or already logged in; False otherwise.
|
280
|
-
"""
|
281
|
-
try:
|
282
|
-
await page.goto("https://www.qidian.com/", wait_until="networkidle")
|
283
|
-
await page.wait_for_selector("#login-box", timeout=timeout * 1000)
|
284
|
-
except Exception as e:
|
285
|
-
self.logger.warning("[auth] Failed to load login box: %s", e)
|
286
|
-
return
|
287
|
-
|
288
|
-
self.logger.debug("[auth] Clicking login button once.")
|
289
|
-
try:
|
290
|
-
btn = await page.query_selector("#login-btn")
|
291
|
-
if btn and await btn.is_visible():
|
292
|
-
await btn.click()
|
293
|
-
tasks = [
|
294
|
-
asyncio.create_task(
|
295
|
-
page.wait_for_selector(
|
296
|
-
"div.mask",
|
297
|
-
timeout=timeout * 1000,
|
298
|
-
)
|
299
|
-
),
|
300
|
-
asyncio.create_task(
|
301
|
-
page.wait_for_selector(
|
302
|
-
"div.qdlogin-wrap",
|
303
|
-
timeout=timeout * 1000,
|
304
|
-
)
|
305
|
-
),
|
306
|
-
asyncio.create_task(
|
307
|
-
page.wait_for_url(
|
308
|
-
lambda url: "login" not in url,
|
309
|
-
timeout=timeout * 1000,
|
310
|
-
)
|
311
|
-
),
|
312
|
-
]
|
313
|
-
done, pending = await asyncio.wait(
|
314
|
-
tasks,
|
315
|
-
timeout=timeout + 1,
|
316
|
-
return_when=asyncio.FIRST_COMPLETED,
|
317
|
-
)
|
318
|
-
for task in pending:
|
319
|
-
task.cancel()
|
320
|
-
if done:
|
321
|
-
self.logger.debug("[auth] Login flow proceeded after button click.")
|
322
|
-
else:
|
323
|
-
self.logger.warning("[auth] Timeout waiting for login to proceed.")
|
324
|
-
except Exception as e:
|
325
|
-
self.logger.debug("[auth] Failed to click login button: %s", e)
|
326
|
-
return
|