diff --git a/assets/docs/sources/option_file_syntax.md b/assets/docs/sources/option_file_syntax.md index 00c9890b..f5e54342 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 ff525832..0dd7ba83 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 ed1d0fb1..8742a65a 100644 --- a/src/jmcomic/jm_entity.py +++ b/src/jmcomic/jm_entity.py @@ -469,11 +469,13 @@ def __init__(self, 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 2f64dae0..cbd17e1e 100644 --- a/src/jmcomic/jm_plugin.py +++ b/src/jmcomic/jm_plugin.py @@ -749,6 +749,7 @@ def invoke(self, 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 @@ def invoke(self, 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 @@ def write_img_2_pdf(self, pdf_filepath, album: JmAlbumDetail, photo: JmPhotoDeta 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 3bb39b98..e5eada1f 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'),