Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/docs/sources/option_file_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.6.3'
__version__ = '2.6.4'

from .api import *
from .jm_plugin import *
Expand Down
2 changes: 2 additions & 0 deletions src/jmcomic/jm_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 更新日期
Expand Down
19 changes: 17 additions & 2 deletions src/jmcomic/jm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions src/jmcomic/jm_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class JmcomicText:
pattern_html_album_album_id = compile(r'<span class="number">.*?:JM(\d+)</span>')
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]*?)</h2>')
pattern_html_album_episode_list = compile(r'data-album="(\d+)"[^>]*>[\s\S]*?第(\d+)[话話]([\s\S]*?)<[\s\S]*?>')
pattern_html_album_page_count = compile(r'<span class="pagecount">.*?:(\d+)</span>')
pattern_html_album_pub_date = compile(r'>上架日期 : (.*?)</span>')
Expand Down Expand Up @@ -651,6 +652,7 @@ class JmApiAdaptTool:
'actors',
'related_list',
'name',
'description',
('id', 'album_id'),
('author', 'authors'),
('total_views', 'views'),
Expand Down