Skip to content

Commit 52298d0

Browse files
authored
v2.4.2: 实现网页端正则匹配收藏夹列表,补充安装依赖项install_requires (#163) (#165)
1 parent c34301d commit 52298d0

File tree

9 files changed

+41
-25
lines changed

9 files changed

+41
-25
lines changed

assets/docs/mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ theme:
55
plugins:
66
- search
77
- mkdocstrings:
8-
custom_templates: templates
98
handlers:
109
# See: https://mkdocstrings.github.io/python/usage/
1110
python:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
package_dir={"": "src"},
2828
python_requires=">=3.7",
2929
install_requires=[
30-
'commonX>=0.6.2',
30+
'commonX>=0.6.3',
3131
'curl_cffi',
3232
'PyYAML',
3333
'Pillow',
34+
'pycryptodome',
3435
],
3536
keywords=['python', 'jmcomic', '18comic', '禁漫天堂', 'NSFW'],
3637
classifiers=[

src/jmcomic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# 被依赖方 <--- 使用方
33
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
44

5-
__version__ = '2.4.1'
5+
__version__ = '2.4.2'
66

77
from .api import *
88
from .jm_plugin import *

src/jmcomic/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def download_batch(download_api,
1919
from common import multi_thread_launcher
2020

2121
if option is None:
22-
option = JmOption.default()
22+
option = JmModuleConfig.option_class().default()
2323

2424
return multi_thread_launcher(
2525
iter_objs=set(

src/jmcomic/jm_client_impl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def get_photo_detail(self,
216216
# 一并获取该章节的所处本子
217217
# todo: 可优化,获取章节所在本子,其实不需要等待章节获取完毕后。
218218
# 可以直接调用 self.get_album_detail(photo_id),会重定向返回本子的HTML
219+
# (had polished by FutureClientProxy)
219220
if fetch_album is True:
220221
photo.from_album = self.get_album_detail(photo.album_id)
221222

@@ -594,7 +595,7 @@ def fetch_photo_additional_field(self, photo: JmPhotoDetail, fetch_album: bool,
594595
2. album
595596
如果都需要获取,会排队,效率低
596597
597-
todo: 改进实现
598+
todo: 改进实现 (had polished by FutureClientProxy)
598599
1. 直接开两个线程跑
599600
2. 开两个线程,但是开之前检查重复性
600601
3. 线程池,也要检查重复性
@@ -658,9 +659,6 @@ def setting(self) -> JmApiResp:
658659
def login(self,
659660
username,
660661
password,
661-
refresh_client_cookies=True,
662-
id_remember='on',
663-
login_remember='on',
664662
) -> JmApiResp:
665663
"""
666664
{

src/jmcomic/jm_client_interface.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@ def check_photo(self, photo: JmPhotoDetail):
192192
class JmUserClient:
193193

194194
def login(self,
195-
username,
196-
password,
195+
username: str,
196+
password: str,
197197
):
198+
"""
199+
1. 返回response响应对象
200+
2. 保证当前client拥有登录cookies
201+
"""
198202
raise NotImplementedError
199203

200204
def album_comment(self,

src/jmcomic/jm_entity.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def __init__(self, content: List[ContentItem], total: int):
457457
album_id, {title, tag_list, ...}
458458
]
459459
:param content: 分页数据
460-
:param total: 一共多少页
460+
:param total: 总结果数
461461
"""
462462
self.content = content
463463
self.total = total
@@ -513,7 +513,6 @@ class JmSearchPage(JmPageContent):
513513

514514
@property
515515
def page_size(self) -> int:
516-
from .jm_client_interface import JmMagicConstants
517516
return JmMagicConstants.PAGE_SIZE_SEARCH
518517

519518
# 下面的方法是对单个album的包装
@@ -533,7 +532,7 @@ def wrap_single_album(cls, album: JmAlbumDetail) -> 'JmSearchPage':
533532
'name': album.name,
534533
'tag_list': album.tags,
535534
}
536-
)], -1)
535+
)], 1)
537536
setattr(page, 'album', album)
538537
return page
539538

@@ -553,3 +552,11 @@ def __init__(self, content, folder_list, total):
553552
@property
554553
def page_size(self) -> int:
555554
return JmMagicConstants.PAGE_SIZE_FAVORITE
555+
556+
def folder_id_name_iter(self) -> Generator[Tuple[str, str], None, None]:
557+
"""
558+
用户文件夹的迭代器
559+
"""
560+
for folder_info in self.folder_list:
561+
fid, fname = folder_info['FID'], folder_info['name']
562+
yield fid, fname

src/jmcomic/jm_plugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,10 @@ class FindUpdatePlugin(JmOptionPlugin):
185185
def invoke(self, **kwargs) -> None:
186186
self.download_album_with_find_update(kwargs or {})
187187

188-
def download_album_with_find_update(self, dic):
188+
def download_album_with_find_update(self, dic: Dict[str, int]):
189189
from .api import download_album
190190
from .jm_downloader import JmDownloader
191191

192-
dic: Dict[str, int]
193-
194192
# 带入漫画id, 章节id(第x章),寻找该漫画下第x章节後的所有章节Id
195193
def find_update(album: JmAlbumDetail):
196194
if album.album_id not in dic:

src/jmcomic/jm_toolkit.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def analyse_jm_search_html(cls, html: str) -> JmSearchPage:
120120
@classmethod
121121
def reflect_new_instance(cls, html: str, cls_field_prefix: str, clazz: type):
122122

123-
def match_field(field_key: str, pattern: Union[Pattern, List[Pattern]], text):
123+
def match_field(field_name: str, pattern: Union[Pattern, List[Pattern]], text):
124124

125125
if isinstance(pattern, list):
126126
# 如果是 pattern 是 List[re.Pattern],
@@ -136,7 +136,7 @@ def match_field(field_key: str, pattern: Union[Pattern, List[Pattern]], text):
136136

137137
return last_pattern.findall(text)
138138

139-
if field_key.endswith("_list"):
139+
if field_name.endswith("_list"):
140140
return pattern.findall(text)
141141
else:
142142
match = pattern.search(text)
@@ -283,9 +283,15 @@ class JmPageTool:
283283
r'</div>'
284284
)
285285

286-
# 收藏页面的文件夹收藏总数
286+
# 收藏夹的收藏总数
287287
pattern_html_favorite_total = compile(r' : (\d+)[^/]*/\D*(\d+)')
288288

289+
# 所有的收藏夹
290+
pattern_html_favorite_folder_list = [
291+
compile(r'<select class="user-select" name="movefolder-fid">([\s\S]*)</select>'),
292+
compile(r'<option value="(\d+)">([^<]*?)</option>')
293+
]
294+
289295
@classmethod
290296
def parse_html_to_search_page(cls, html: str) -> JmSearchPage:
291297
# 1. 检查是否失败
@@ -327,15 +333,18 @@ def parse_html_to_favorite_page(cls, html: str) -> JmFavoritePage:
327333
'未匹配到收藏夹的本子总数',
328334
))
329335

330-
# 收藏页面的本子结果
336+
# 收藏夹的本子结果
331337
content = cls.pattern_html_favorite_content.findall(html)
332338
content = [
333339
(aid, {'name': atitle})
334340
for aid, atitle in content
335341
]
336342

337-
# 暂不实现匹配文件夹列表,感觉没什么意义..
338-
folder_list = []
343+
# 匹配收藏夹列表
344+
p1, p2 = cls.pattern_html_favorite_folder_list
345+
folder_list_text = PatternTool.require_match(html, p1, '未匹配到收藏夹列表')
346+
folder_list_raw = p2.findall(folder_list_text)
347+
folder_list = [{'name': fname, 'FID': fid} for fid, fname in folder_list_raw]
339348

340349
return JmFavoritePage(content, folder_list, total)
341350

@@ -397,8 +406,8 @@ def parse_api_to_favorite_page(cls, data: DictModel) -> JmFavoritePage:
397406
"FID": "123",
398407
"1": "456",
399408
"UID": "456",
400-
"2": "文件夹名",
401-
"name": "文件夹名"
409+
"2": "收藏夹名",
410+
"name": "收藏夹名"
402411
}
403412
],
404413
"total": "87",
@@ -408,7 +417,7 @@ def parse_api_to_favorite_page(cls, data: DictModel) -> JmFavoritePage:
408417
total: int = int(data.total)
409418
# count: int = int(data.count)
410419
content = cls.adapt_content(data.list)
411-
folder_list = data.folder_list
420+
folder_list = data.get('folder_list', [])
412421

413422
return JmFavoritePage(content, folder_list, total)
414423

0 commit comments

Comments
 (0)