From 2cb5455d3ba5a8868bb1c808ae042d1b9792f159 Mon Sep 17 00:00:00 2001 From: hect0x7 <93357912+hect0x7@users.noreply.github.com> Date: Fri, 18 Jul 2025 01:02:19 +0800 Subject: [PATCH] =?UTF-8?q?v2.6.4:=20=E6=9C=AC=E5=AD=90=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0description=E5=AD=97=E6=AE=B5=EF=BC=8Cimg2pdf?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AEpdf?= =?UTF-8?q?=E5=AF=86=E7=A0=81=20(#458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/docs/sources/option_file_syntax.md | 2 ++ src/jmcomic/__init__.py | 2 +- src/jmcomic/jm_entity.py | 2 ++ src/jmcomic/jm_plugin.py | 19 +++++++++++++++++-- src/jmcomic/jm_toolkit.py | 2 ++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/assets/docs/sources/option_file_syntax.md b/assets/docs/sources/option_file_syntax.md index 00c9890..f5e5434 100644 --- a/assets/docs/sources/option_file_syntax.md +++ b/assets/docs/sources/option_file_syntax.md @@ -279,6 +279,8 @@ plugins: kwargs: pdf_dir: D:/pdf/ # pdf存放文件夹 filename_rule: Pid # pdf命名规则,P代表photo, id代表使用photo.id也就是章节id + encrypt: # pdf密码,可选配置项 + password: 123 # 密码 # img2pdf也支持合并整个本子,把上方的after_photo改为after_album即可。 # https://github.com/hect0x7/JMComic-Crawler-Python/discussions/258 diff --git a/src/jmcomic/__init__.py b/src/jmcomic/__init__.py index ff52583..0dd7ba8 100644 --- a/src/jmcomic/__init__.py +++ b/src/jmcomic/__init__.py @@ -2,7 +2,7 @@ # 被依赖方 <--- 使用方 # config <--- entity <--- toolkit <--- client <--- option <--- downloader -__version__ = '2.6.3' +__version__ = '2.6.4' from .api import * from .jm_plugin import * diff --git a/src/jmcomic/jm_entity.py b/src/jmcomic/jm_entity.py index ed1d0fb..8742a65 100644 --- a/src/jmcomic/jm_entity.py +++ b/src/jmcomic/jm_entity.py @@ -469,11 +469,13 @@ class JmAlbumDetail(DetailEntity, Downloadable): authors, tags, related_list=None, + description='', ): super().__init__() self.album_id: str = str(album_id) self.scramble_id: str = str(scramble_id) self.name: str = str(name).strip() + self.description = str(description).strip() self.page_count: int = int(page_count) # 总页数 self.pub_date: str = pub_date # 发布日期 self.update_date: str = update_date # 更新日期 diff --git a/src/jmcomic/jm_plugin.py b/src/jmcomic/jm_plugin.py index 2f64dae..cbd17e1 100644 --- a/src/jmcomic/jm_plugin.py +++ b/src/jmcomic/jm_plugin.py @@ -749,6 +749,7 @@ class Img2pdfPlugin(JmOptionPlugin): filename_rule='Pid', dir_rule=None, delete_original_file=False, + encrypt=None, **kwargs, ): if photo is None and album is None: @@ -766,14 +767,14 @@ class Img2pdfPlugin(JmOptionPlugin): pdf_filepath = self.decide_filepath(album, photo, filename_rule, 'pdf', pdf_dir, dir_rule) # 调用 img2pdf 把 photo_dir 下的所有图片转为pdf - img_path_ls, img_dir_ls = self.write_img_2_pdf(pdf_filepath, album, photo) + img_path_ls, img_dir_ls = self.write_img_2_pdf(pdf_filepath, album, photo, encrypt) self.log(f'Convert Successfully: JM{album or photo} → {pdf_filepath}') # 执行删除 img_path_ls += img_dir_ls self.execute_deletion(img_path_ls) - def write_img_2_pdf(self, pdf_filepath, album: JmAlbumDetail, photo: JmPhotoDetail): + def write_img_2_pdf(self, pdf_filepath, album: JmAlbumDetail, photo: JmPhotoDetail, encrypt): import img2pdf if album is None: @@ -795,8 +796,22 @@ class Img2pdfPlugin(JmOptionPlugin): with open(pdf_filepath, 'wb') as f: f.write(img2pdf.convert(img_path_ls)) + if encrypt: + self.encrypt_pdf(pdf_filepath, encrypt) + return img_path_ls, img_dir_ls + def encrypt_pdf(self, pdf_filepath: str, encrypt: dict): + try: + import pikepdf + except ImportError: + self.warning_lib_not_install('pikepdf') + return + + password = str(encrypt.get('password', '')) + with pikepdf.open(pdf_filepath, allow_overwriting_input=True) as pdf: + pdf.save(pdf_filepath, encryption=pikepdf.Encryption(user=password, owner=password)) + class LongImgPlugin(JmOptionPlugin): plugin_key = 'long_img' diff --git a/src/jmcomic/jm_toolkit.py b/src/jmcomic/jm_toolkit.py index 3bb39b9..e5eada1 100644 --- a/src/jmcomic/jm_toolkit.py +++ b/src/jmcomic/jm_toolkit.py @@ -26,6 +26,7 @@ class JmcomicText: pattern_html_album_album_id = compile(r'.*?:JM(\d+)') pattern_html_album_scramble_id = compile(r'var scramble_id = (\d+);') pattern_html_album_name = compile(r'id="book-name"[^>]*?>([\s\S]*?)<') + pattern_html_album_description = compile(r'叙述:([\s\S]*?)') pattern_html_album_episode_list = compile(r'data-album="(\d+)"[^>]*>[\s\S]*?第(\d+)[话話]([\s\S]*?)<[\s\S]*?>') pattern_html_album_page_count = compile(r'.*?:(\d+)') pattern_html_album_pub_date = compile(r'>上架日期 : (.*?)') @@ -651,6 +652,7 @@ class JmApiAdaptTool: 'actors', 'related_list', 'name', + 'description', ('id', 'album_id'), ('author', 'authors'), ('total_views', 'views'),