Skip to content

Commit 2cb5455

Browse files
authored
v2.6.4: 本子详情增加description字段,img2pdf插件支持设置pdf密码 (#458)
1 parent c4faf3a commit 2cb5455

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

assets/docs/sources/option_file_syntax.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ plugins:
279279
kwargs:
280280
pdf_dir: D:/pdf/ # pdf存放文件夹
281281
filename_rule: Pid # pdf命名规则,P代表photo, id代表使用photo.id也就是章节id
282+
encrypt: # pdf密码,可选配置项
283+
password: 123 # 密码
282284

283285
# img2pdf也支持合并整个本子,把上方的after_photo改为after_album即可。
284286
# https://github.com/hect0x7/JMComic-Crawler-Python/discussions/258

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.6.3'
5+
__version__ = '2.6.4'
66

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

src/jmcomic/jm_entity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,13 @@ def __init__(self,
469469
authors,
470470
tags,
471471
related_list=None,
472+
description='',
472473
):
473474
super().__init__()
474475
self.album_id: str = str(album_id)
475476
self.scramble_id: str = str(scramble_id)
476477
self.name: str = str(name).strip()
478+
self.description = str(description).strip()
477479
self.page_count: int = int(page_count) # 总页数
478480
self.pub_date: str = pub_date # 发布日期
479481
self.update_date: str = update_date # 更新日期

src/jmcomic/jm_plugin.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ def invoke(self,
749749
filename_rule='Pid',
750750
dir_rule=None,
751751
delete_original_file=False,
752+
encrypt=None,
752753
**kwargs,
753754
):
754755
if photo is None and album is None:
@@ -766,14 +767,14 @@ def invoke(self,
766767
pdf_filepath = self.decide_filepath(album, photo, filename_rule, 'pdf', pdf_dir, dir_rule)
767768

768769
# 调用 img2pdf 把 photo_dir 下的所有图片转为pdf
769-
img_path_ls, img_dir_ls = self.write_img_2_pdf(pdf_filepath, album, photo)
770+
img_path_ls, img_dir_ls = self.write_img_2_pdf(pdf_filepath, album, photo, encrypt)
770771
self.log(f'Convert Successfully: JM{album or photo}{pdf_filepath}')
771772

772773
# 执行删除
773774
img_path_ls += img_dir_ls
774775
self.execute_deletion(img_path_ls)
775776

776-
def write_img_2_pdf(self, pdf_filepath, album: JmAlbumDetail, photo: JmPhotoDetail):
777+
def write_img_2_pdf(self, pdf_filepath, album: JmAlbumDetail, photo: JmPhotoDetail, encrypt):
777778
import img2pdf
778779

779780
if album is None:
@@ -795,8 +796,22 @@ def write_img_2_pdf(self, pdf_filepath, album: JmAlbumDetail, photo: JmPhotoDeta
795796
with open(pdf_filepath, 'wb') as f:
796797
f.write(img2pdf.convert(img_path_ls))
797798

799+
if encrypt:
800+
self.encrypt_pdf(pdf_filepath, encrypt)
801+
798802
return img_path_ls, img_dir_ls
799803

804+
def encrypt_pdf(self, pdf_filepath: str, encrypt: dict):
805+
try:
806+
import pikepdf
807+
except ImportError:
808+
self.warning_lib_not_install('pikepdf')
809+
return
810+
811+
password = str(encrypt.get('password', ''))
812+
with pikepdf.open(pdf_filepath, allow_overwriting_input=True) as pdf:
813+
pdf.save(pdf_filepath, encryption=pikepdf.Encryption(user=password, owner=password))
814+
800815

801816
class LongImgPlugin(JmOptionPlugin):
802817
plugin_key = 'long_img'

src/jmcomic/jm_toolkit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class JmcomicText:
2626
pattern_html_album_album_id = compile(r'<span class="number">.*?:JM(\d+)</span>')
2727
pattern_html_album_scramble_id = compile(r'var scramble_id = (\d+);')
2828
pattern_html_album_name = compile(r'id="book-name"[^>]*?>([\s\S]*?)<')
29+
pattern_html_album_description = compile(r'叙述:([\s\S]*?)</h2>')
2930
pattern_html_album_episode_list = compile(r'data-album="(\d+)"[^>]*>[\s\S]*?第(\d+)[话話]([\s\S]*?)<[\s\S]*?>')
3031
pattern_html_album_page_count = compile(r'<span class="pagecount">.*?:(\d+)</span>')
3132
pattern_html_album_pub_date = compile(r'>上架日期 : (.*?)</span>')
@@ -651,6 +652,7 @@ class JmApiAdaptTool:
651652
'actors',
652653
'related_list',
653654
'name',
655+
'description',
654656
('id', 'album_id'),
655657
('author', 'authors'),
656658
('total_views', 'views'),

0 commit comments

Comments
 (0)