Skip to content

Commit

Permalink
v2.4.2: 实现网页端正则匹配收藏夹列表,补充安装依赖项install_requires (#163) (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
hect0x7 authored Nov 20, 2023
1 parent c34301d commit 52298d0
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 25 deletions.
1 change: 0 additions & 1 deletion assets/docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ theme:
plugins:
- search
- mkdocstrings:
custom_templates: templates
handlers:
# See: https://mkdocstrings.github.io/python/usage/
python:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
2 changes: 1 addition & 1 deletion src/jmcomic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
2 changes: 1 addition & 1 deletion src/jmcomic/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions src/jmcomic/jm_client_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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. 线程池,也要检查重复性
Expand Down Expand Up @@ -658,9 +659,6 @@ def setting(self) -> JmApiResp:
def login(self,
username,
password,
refresh_client_cookies=True,
id_remember='on',
login_remember='on',
) -> JmApiResp:
"""
{
Expand Down
8 changes: 6 additions & 2 deletions src/jmcomic/jm_client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/jmcomic/jm_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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的包装
Expand All @@ -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

Expand All @@ -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
4 changes: 1 addition & 3 deletions src/jmcomic/jm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 18 additions & 9 deletions src/jmcomic/jm_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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)
Expand Down Expand Up @@ -283,9 +283,15 @@ class JmPageTool:
r'</div>'
)

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

# 所有的收藏夹
pattern_html_favorite_folder_list = [
compile(r'<select class="user-select" name="movefolder-fid">([\s\S]*)</select>'),
compile(r'<option value="(\d+)">([^<]*?)</option>')
]

@classmethod
def parse_html_to_search_page(cls, html: str) -> JmSearchPage:
# 1. 检查是否失败
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand All @@ -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)

Expand Down

0 comments on commit 52298d0

Please sign in to comment.