S-08 CBZ 归档完善
这个提交存在于:
父节点
ce1ab6db1b
当前提交
ea098a79e4
共有 4 个文件被更改,包括 36 次插入 和 2 次删除
|
|
@ -20,6 +20,11 @@
|
|||
|
||||
Komga 扫描时会把父文件夹识别为 Series,把文件识别为 Book,所以 `archive_root` 建议直接填写 Komga library 的根目录。插件也保留 `pdf` 输出,用于兼容原 NoneBot 插件习惯。
|
||||
|
||||
CBZ 内部会包含:
|
||||
|
||||
- `ComicInfo.xml`:标题、系列、页数、JM ID、来源链接等 Komga 可读取的元数据。
|
||||
- `0001.jpg`、`0002.jpg` ...:按下载顺序编号的页面图片。
|
||||
|
||||
## Komga 联动
|
||||
|
||||
在 AstrBot 插件配置里填写:
|
||||
|
|
|
|||
1
main.py
1
main.py
|
|
@ -125,6 +125,7 @@ class JMDownloadPlugin(Star):
|
|||
[
|
||||
f"JMDownload 完成:{existed}",
|
||||
f"系列:{archive_result.series_name}",
|
||||
f"格式:{archive_result.archive_format}",
|
||||
f"页数:{archive_result.page_count}",
|
||||
f"文件:{archive_result.path}",
|
||||
f"Komga: {scan_result.message}",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import asyncio
|
|||
import os
|
||||
import zipfile
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ class ArchiveResult:
|
|||
series_dir: Path
|
||||
series_name: str
|
||||
book_name: str
|
||||
archive_format: str
|
||||
existed: bool
|
||||
page_count: int
|
||||
|
||||
|
|
@ -49,6 +51,7 @@ class ArchiveService:
|
|||
series_dir=series_dir,
|
||||
series_name=series_name,
|
||||
book_name=book_name,
|
||||
archive_format=self.settings.archive_format,
|
||||
existed=True,
|
||||
page_count=len(downloaded.image_files),
|
||||
)
|
||||
|
|
@ -68,6 +71,7 @@ class ArchiveService:
|
|||
series_dir=series_dir,
|
||||
series_name=series_name,
|
||||
book_name=book_name,
|
||||
archive_format=self.settings.archive_format,
|
||||
existed=False,
|
||||
page_count=len(downloaded.image_files),
|
||||
)
|
||||
|
|
@ -80,9 +84,10 @@ class ArchiveService:
|
|||
book_name: str,
|
||||
) -> None:
|
||||
with zipfile.ZipFile(target_path, "w", compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
archive.writestr(
|
||||
self._writestr(
|
||||
archive,
|
||||
"ComicInfo.xml",
|
||||
self._comic_info_xml(downloaded, series_name, book_name),
|
||||
self._comic_info_xml(downloaded, series_name, book_name).encode("utf-8"),
|
||||
)
|
||||
for index, image_path in enumerate(downloaded.image_files, start=1):
|
||||
page_name = f"{index:04d}{image_path.suffix.lower()}"
|
||||
|
|
@ -116,6 +121,7 @@ class ArchiveService:
|
|||
series_name: str,
|
||||
book_name: str,
|
||||
) -> str:
|
||||
now = datetime.now()
|
||||
return "\n".join(
|
||||
[
|
||||
'<?xml version="1.0" encoding="utf-8"?>',
|
||||
|
|
@ -124,8 +130,26 @@ class ArchiveService:
|
|||
f" <Series>{escape(series_name)}</Series>",
|
||||
f" <Number>{escape(downloaded.comic_id)}</Number>",
|
||||
f" <PageCount>{len(downloaded.image_files)}</PageCount>",
|
||||
f" <Year>{now.year}</Year>",
|
||||
f" <Month>{now.month}</Month>",
|
||||
f" <Day>{now.day}</Day>",
|
||||
" <Format>Digital</Format>",
|
||||
" <Manga>YesAndRightToLeft</Manga>",
|
||||
" <LanguageISO>zh</LanguageISO>",
|
||||
f" <Web>{escape(downloaded.source_url)}</Web>",
|
||||
f" <Summary>{escape('JM album ' + downloaded.comic_id)}</Summary>",
|
||||
"</ComicInfo>",
|
||||
"",
|
||||
],
|
||||
)
|
||||
|
||||
def _writestr(
|
||||
self,
|
||||
archive: zipfile.ZipFile,
|
||||
archive_name: str,
|
||||
content: bytes,
|
||||
) -> None:
|
||||
info = zipfile.ZipInfo(archive_name)
|
||||
info.compress_type = zipfile.ZIP_DEFLATED
|
||||
info.external_attr = 0o644 << 16
|
||||
archive.writestr(info, content)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ class DownloadedComic:
|
|||
download_dir: Path
|
||||
image_files: list[Path]
|
||||
|
||||
@property
|
||||
def source_url(self) -> str:
|
||||
return f"https://18comic.vip/album/{self.comic_id}"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DownloadProgress:
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用