From 52298d0faf21222770c53467ccdefdf00ce5e147 Mon Sep 17 00:00:00 2001
From: hect0x7 <93357912+hect0x7@users.noreply.github.com>
Date: Mon, 20 Nov 2023 22:14:00 +0800
Subject: [PATCH] =?UTF-8?q?v2.4.2:=20=E5=AE=9E=E7=8E=B0=E7=BD=91=E9=A1=B5?=
=?UTF-8?q?=E7=AB=AF=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8D=E6=94=B6=E8=97=8F?=
=?UTF-8?q?=E5=A4=B9=E5=88=97=E8=A1=A8=EF=BC=8C=E8=A1=A5=E5=85=85=E5=AE=89?=
=?UTF-8?q?=E8=A3=85=E4=BE=9D=E8=B5=96=E9=A1=B9install=5Frequires=20(#163)?=
=?UTF-8?q?=20(#165)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
assets/docs/mkdocs.yml | 1 -
setup.py | 3 ++-
src/jmcomic/__init__.py | 2 +-
src/jmcomic/api.py | 2 +-
src/jmcomic/jm_client_impl.py | 6 ++----
src/jmcomic/jm_client_interface.py | 8 ++++++--
src/jmcomic/jm_entity.py | 13 ++++++++++---
src/jmcomic/jm_plugin.py | 4 +---
src/jmcomic/jm_toolkit.py | 27 ++++++++++++++++++---------
9 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/assets/docs/mkdocs.yml b/assets/docs/mkdocs.yml
index 0e34e5bb..ac9f8b82 100644
--- a/assets/docs/mkdocs.yml
+++ b/assets/docs/mkdocs.yml
@@ -5,7 +5,6 @@ theme:
plugins:
- search
- mkdocstrings:
- custom_templates: templates
handlers:
# See: https://mkdocstrings.github.io/python/usage/
python:
diff --git a/setup.py b/setup.py
index 50c61848..3ae87171 100644
--- a/setup.py
+++ b/setup.py
@@ -27,10 +27,11 @@
package_dir={"": "src"},
python_requires=">=3.7",
install_requires=[
- 'commonX>=0.6.2',
+ 'commonX>=0.6.3',
'curl_cffi',
'PyYAML',
'Pillow',
+ 'pycryptodome',
],
keywords=['python', 'jmcomic', '18comic', '禁漫天堂', 'NSFW'],
classifiers=[
diff --git a/src/jmcomic/__init__.py b/src/jmcomic/__init__.py
index 42a4708a..5963d62b 100644
--- a/src/jmcomic/__init__.py
+++ b/src/jmcomic/__init__.py
@@ -2,7 +2,7 @@
# 被依赖方 <--- 使用方
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
-__version__ = '2.4.1'
+__version__ = '2.4.2'
from .api import *
from .jm_plugin import *
diff --git a/src/jmcomic/api.py b/src/jmcomic/api.py
index fda60df4..275d777f 100644
--- a/src/jmcomic/api.py
+++ b/src/jmcomic/api.py
@@ -19,7 +19,7 @@ def download_batch(download_api,
from common import multi_thread_launcher
if option is None:
- option = JmOption.default()
+ option = JmModuleConfig.option_class().default()
return multi_thread_launcher(
iter_objs=set(
diff --git a/src/jmcomic/jm_client_impl.py b/src/jmcomic/jm_client_impl.py
index b90541b9..4abdb483 100644
--- a/src/jmcomic/jm_client_impl.py
+++ b/src/jmcomic/jm_client_impl.py
@@ -216,6 +216,7 @@ def get_photo_detail(self,
# 一并获取该章节的所处本子
# todo: 可优化,获取章节所在本子,其实不需要等待章节获取完毕后。
# 可以直接调用 self.get_album_detail(photo_id),会重定向返回本子的HTML
+ # (had polished by FutureClientProxy)
if fetch_album is True:
photo.from_album = self.get_album_detail(photo.album_id)
@@ -594,7 +595,7 @@ def fetch_photo_additional_field(self, photo: JmPhotoDetail, fetch_album: bool,
2. album
如果都需要获取,会排队,效率低
- todo: 改进实现
+ todo: 改进实现 (had polished by FutureClientProxy)
1. 直接开两个线程跑
2. 开两个线程,但是开之前检查重复性
3. 线程池,也要检查重复性
@@ -658,9 +659,6 @@ def setting(self) -> JmApiResp:
def login(self,
username,
password,
- refresh_client_cookies=True,
- id_remember='on',
- login_remember='on',
) -> JmApiResp:
"""
{
diff --git a/src/jmcomic/jm_client_interface.py b/src/jmcomic/jm_client_interface.py
index 9cbf05d0..92656f85 100644
--- a/src/jmcomic/jm_client_interface.py
+++ b/src/jmcomic/jm_client_interface.py
@@ -192,9 +192,13 @@ def check_photo(self, photo: JmPhotoDetail):
class JmUserClient:
def login(self,
- username,
- password,
+ username: str,
+ password: str,
):
+ """
+ 1. 返回response响应对象
+ 2. 保证当前client拥有登录cookies
+ """
raise NotImplementedError
def album_comment(self,
diff --git a/src/jmcomic/jm_entity.py b/src/jmcomic/jm_entity.py
index 9884d851..9d391ede 100644
--- a/src/jmcomic/jm_entity.py
+++ b/src/jmcomic/jm_entity.py
@@ -457,7 +457,7 @@ def __init__(self, content: List[ContentItem], total: int):
album_id, {title, tag_list, ...}
]
:param content: 分页数据
- :param total: 一共多少页
+ :param total: 总结果数
"""
self.content = content
self.total = total
@@ -513,7 +513,6 @@ class JmSearchPage(JmPageContent):
@property
def page_size(self) -> int:
- from .jm_client_interface import JmMagicConstants
return JmMagicConstants.PAGE_SIZE_SEARCH
# 下面的方法是对单个album的包装
@@ -533,7 +532,7 @@ def wrap_single_album(cls, album: JmAlbumDetail) -> 'JmSearchPage':
'name': album.name,
'tag_list': album.tags,
}
- )], -1)
+ )], 1)
setattr(page, 'album', album)
return page
@@ -553,3 +552,11 @@ def __init__(self, content, folder_list, total):
@property
def page_size(self) -> int:
return JmMagicConstants.PAGE_SIZE_FAVORITE
+
+ def folder_id_name_iter(self) -> Generator[Tuple[str, str], None, None]:
+ """
+ 用户文件夹的迭代器
+ """
+ for folder_info in self.folder_list:
+ fid, fname = folder_info['FID'], folder_info['name']
+ yield fid, fname
diff --git a/src/jmcomic/jm_plugin.py b/src/jmcomic/jm_plugin.py
index b57553a4..7d3fc611 100644
--- a/src/jmcomic/jm_plugin.py
+++ b/src/jmcomic/jm_plugin.py
@@ -185,12 +185,10 @@ class FindUpdatePlugin(JmOptionPlugin):
def invoke(self, **kwargs) -> None:
self.download_album_with_find_update(kwargs or {})
- def download_album_with_find_update(self, dic):
+ def download_album_with_find_update(self, dic: Dict[str, int]):
from .api import download_album
from .jm_downloader import JmDownloader
- dic: Dict[str, int]
-
# 带入漫画id, 章节id(第x章),寻找该漫画下第x章节後的所有章节Id
def find_update(album: JmAlbumDetail):
if album.album_id not in dic:
diff --git a/src/jmcomic/jm_toolkit.py b/src/jmcomic/jm_toolkit.py
index 90f41ed8..b8ae517b 100644
--- a/src/jmcomic/jm_toolkit.py
+++ b/src/jmcomic/jm_toolkit.py
@@ -120,7 +120,7 @@ def analyse_jm_search_html(cls, html: str) -> JmSearchPage:
@classmethod
def reflect_new_instance(cls, html: str, cls_field_prefix: str, clazz: type):
- def match_field(field_key: str, pattern: Union[Pattern, List[Pattern]], text):
+ def match_field(field_name: str, pattern: Union[Pattern, List[Pattern]], text):
if isinstance(pattern, list):
# 如果是 pattern 是 List[re.Pattern],
@@ -136,7 +136,7 @@ def match_field(field_key: str, pattern: Union[Pattern, List[Pattern]], text):
return last_pattern.findall(text)
- if field_key.endswith("_list"):
+ if field_name.endswith("_list"):
return pattern.findall(text)
else:
match = pattern.search(text)
@@ -283,9 +283,15 @@ class JmPageTool:
r''
)
- # 收藏页面的文件夹收藏总数
+ # 收藏夹的收藏总数
pattern_html_favorite_total = compile(r' : (\d+)[^/]*/\D*(\d+)')
+ # 所有的收藏夹
+ pattern_html_favorite_folder_list = [
+ compile(r''),
+ compile(r'')
+ ]
+
@classmethod
def parse_html_to_search_page(cls, html: str) -> JmSearchPage:
# 1. 检查是否失败
@@ -327,15 +333,18 @@ def parse_html_to_favorite_page(cls, html: str) -> JmFavoritePage:
'未匹配到收藏夹的本子总数',
))
- # 收藏页面的本子结果
+ # 收藏夹的本子结果
content = cls.pattern_html_favorite_content.findall(html)
content = [
(aid, {'name': atitle})
for aid, atitle in content
]
- # 暂不实现匹配文件夹列表,感觉没什么意义..
- folder_list = []
+ # 匹配收藏夹列表
+ p1, p2 = cls.pattern_html_favorite_folder_list
+ folder_list_text = PatternTool.require_match(html, p1, '未匹配到收藏夹列表')
+ folder_list_raw = p2.findall(folder_list_text)
+ folder_list = [{'name': fname, 'FID': fid} for fid, fname in folder_list_raw]
return JmFavoritePage(content, folder_list, total)
@@ -397,8 +406,8 @@ def parse_api_to_favorite_page(cls, data: DictModel) -> JmFavoritePage:
"FID": "123",
"1": "456",
"UID": "456",
- "2": "文件夹名",
- "name": "文件夹名"
+ "2": "收藏夹名",
+ "name": "收藏夹名"
}
],
"total": "87",
@@ -408,7 +417,7 @@ def parse_api_to_favorite_page(cls, data: DictModel) -> JmFavoritePage:
total: int = int(data.total)
# count: int = int(data.count)
content = cls.adapt_content(data.list)
- folder_list = data.folder_list
+ folder_list = data.get('folder_list', [])
return JmFavoritePage(content, folder_list, total)