mirror of
https://github.com/hect0x7/JMComic-Crawler-Python.git
synced 2025-09-26 22:31:30 +08:00
v2.6.4: 本子详情增加description字段,img2pdf插件支持设置pdf密码 (#458)
Some checks failed
Auto Release & Publish / release (push) Has been cancelled
Some checks failed
Auto Release & Publish / release (push) Has been cancelled
This commit is contained in:
parent
c4faf3afbb
commit
2cb5455d3b
@ -279,6 +279,8 @@ plugins:
|
|||||||
kwargs:
|
kwargs:
|
||||||
pdf_dir: D:/pdf/ # pdf存放文件夹
|
pdf_dir: D:/pdf/ # pdf存放文件夹
|
||||||
filename_rule: Pid # pdf命名规则,P代表photo, id代表使用photo.id也就是章节id
|
filename_rule: Pid # pdf命名规则,P代表photo, id代表使用photo.id也就是章节id
|
||||||
|
encrypt: # pdf密码,可选配置项
|
||||||
|
password: 123 # 密码
|
||||||
|
|
||||||
# img2pdf也支持合并整个本子,把上方的after_photo改为after_album即可。
|
# img2pdf也支持合并整个本子,把上方的after_photo改为after_album即可。
|
||||||
# https://github.com/hect0x7/JMComic-Crawler-Python/discussions/258
|
# https://github.com/hect0x7/JMComic-Crawler-Python/discussions/258
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# 被依赖方 <--- 使用方
|
# 被依赖方 <--- 使用方
|
||||||
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
|
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
|
||||||
|
|
||||||
__version__ = '2.6.3'
|
__version__ = '2.6.4'
|
||||||
|
|
||||||
from .api import *
|
from .api import *
|
||||||
from .jm_plugin import *
|
from .jm_plugin import *
|
||||||
|
@ -469,11 +469,13 @@ class JmAlbumDetail(DetailEntity, Downloadable):
|
|||||||
authors,
|
authors,
|
||||||
tags,
|
tags,
|
||||||
related_list=None,
|
related_list=None,
|
||||||
|
description='',
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.album_id: str = str(album_id)
|
self.album_id: str = str(album_id)
|
||||||
self.scramble_id: str = str(scramble_id)
|
self.scramble_id: str = str(scramble_id)
|
||||||
self.name: str = str(name).strip()
|
self.name: str = str(name).strip()
|
||||||
|
self.description = str(description).strip()
|
||||||
self.page_count: int = int(page_count) # 总页数
|
self.page_count: int = int(page_count) # 总页数
|
||||||
self.pub_date: str = pub_date # 发布日期
|
self.pub_date: str = pub_date # 发布日期
|
||||||
self.update_date: str = update_date # 更新日期
|
self.update_date: str = update_date # 更新日期
|
||||||
|
@ -749,6 +749,7 @@ class Img2pdfPlugin(JmOptionPlugin):
|
|||||||
filename_rule='Pid',
|
filename_rule='Pid',
|
||||||
dir_rule=None,
|
dir_rule=None,
|
||||||
delete_original_file=False,
|
delete_original_file=False,
|
||||||
|
encrypt=None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
if photo is None and album is None:
|
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)
|
pdf_filepath = self.decide_filepath(album, photo, filename_rule, 'pdf', pdf_dir, dir_rule)
|
||||||
|
|
||||||
# 调用 img2pdf 把 photo_dir 下的所有图片转为pdf
|
# 调用 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}')
|
self.log(f'Convert Successfully: JM{album or photo} → {pdf_filepath}')
|
||||||
|
|
||||||
# 执行删除
|
# 执行删除
|
||||||
img_path_ls += img_dir_ls
|
img_path_ls += img_dir_ls
|
||||||
self.execute_deletion(img_path_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
|
import img2pdf
|
||||||
|
|
||||||
if album is None:
|
if album is None:
|
||||||
@ -795,8 +796,22 @@ class Img2pdfPlugin(JmOptionPlugin):
|
|||||||
with open(pdf_filepath, 'wb') as f:
|
with open(pdf_filepath, 'wb') as f:
|
||||||
f.write(img2pdf.convert(img_path_ls))
|
f.write(img2pdf.convert(img_path_ls))
|
||||||
|
|
||||||
|
if encrypt:
|
||||||
|
self.encrypt_pdf(pdf_filepath, encrypt)
|
||||||
|
|
||||||
return img_path_ls, img_dir_ls
|
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):
|
class LongImgPlugin(JmOptionPlugin):
|
||||||
plugin_key = 'long_img'
|
plugin_key = 'long_img'
|
||||||
|
@ -26,6 +26,7 @@ class JmcomicText:
|
|||||||
pattern_html_album_album_id = compile(r'<span class="number">.*?:JM(\d+)</span>')
|
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_scramble_id = compile(r'var scramble_id = (\d+);')
|
||||||
pattern_html_album_name = compile(r'id="book-name"[^>]*?>([\s\S]*?)<')
|
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_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_page_count = compile(r'<span class="pagecount">.*?:(\d+)</span>')
|
||||||
pattern_html_album_pub_date = compile(r'>上架日期 : (.*?)</span>')
|
pattern_html_album_pub_date = compile(r'>上架日期 : (.*?)</span>')
|
||||||
@ -651,6 +652,7 @@ class JmApiAdaptTool:
|
|||||||
'actors',
|
'actors',
|
||||||
'related_list',
|
'related_list',
|
||||||
'name',
|
'name',
|
||||||
|
'description',
|
||||||
('id', 'album_id'),
|
('id', 'album_id'),
|
||||||
('author', 'authors'),
|
('author', 'authors'),
|
||||||
('total_views', 'views'),
|
('total_views', 'views'),
|
||||||
|
Loading…
Reference in New Issue
Block a user