Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save ComicInfo.xml in CBZ Files (Optional) #6102

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
29 changes: 29 additions & 0 deletions src/web/mjs/engine/ComicInfoGenerator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default class ComicInfoGenerator {
apiweb marked this conversation as resolved.
Show resolved Hide resolved
static createComicInfoXML(series, title, pagesCount) {
series = this.escapeXML(series);
title = this.escapeXML(title);
return `<?xml version="1.0" encoding="utf-8"?>
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Title>${title}</Title>
<Series>${series}</Series>
<PageCount>${pagesCount}</PageCount>
</ComicInfo>`;
}

static escapeXML(str) {
return str.replace(/[<>&'"]/g, function (c) {
switch (c) {
apiweb marked this conversation as resolved.
Show resolved Hide resolved
case '<':
return '&lt;';
case '>':
return '&gt;';
case '&':
return '&amp;';
case '\'':
return '&apos;';
case '"':
return '&quot;';
}
});
}
}
9 changes: 8 additions & 1 deletion src/web/mjs/engine/Settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export default class Settings extends EventTarget {
value: extensions.img
};

this.includesComicFile = {
apiweb marked this conversation as resolved.
Show resolved Hide resolved
label: 'Include Comic File in CBZ',
description: 'Include a comic file (comicinfo.xml) in the chapter archive',
input: types.checkbox,
value: false
};

this.recompressionFormat = {
label: 'De-Scrambling Format',
description: [
Expand Down Expand Up @@ -420,4 +427,4 @@ export default class Settings extends EventTarget {
return value;
}
}
}
}
13 changes: 11 additions & 2 deletions src/web/mjs/engine/Storage.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import EbookGenerator from './EbookGenerator.mjs';
import ComicInfoGenerator from './ComicInfoGenerator.mjs';
import Chapter from './Chapter.mjs';

const extensions = {
Expand Down Expand Up @@ -448,7 +449,9 @@ export default class Storage {
}
if (Engine.Settings.chapterFormat.value === extensions.cbz) {
this._createDirectoryChain(this.path.dirname(output));
promise = this._saveChapterPagesCBZ(output, pageData)
let mangaName = chapter.manga.title;
let chapterName = chapter.title;
promise = this._saveChapterPagesCBZ(output, pageData, mangaName, chapterName)
apiweb marked this conversation as resolved.
Show resolved Hide resolved
.then(() => this._runPostChapterDownloadCommand(chapter, output));
}
if (Engine.Settings.chapterFormat.value === extensions.pdf) {
Expand Down Expand Up @@ -548,8 +551,14 @@ export default class Storage {
* Create and save pages to the given archive file.
* Callback will be executed after completion and provided with an array of errors (or an empty array when no errors occured).
*/
_saveChapterPagesCBZ(archive, pageData) {
_saveChapterPagesCBZ(archive, pageData, mangaName = '', chapterName = '') {
let zip = new JSZip();

if (Engine.Settings.includesComicFile.value) {
let comicFile = ComicInfoGenerator.createComicInfoXML(mangaName, chapterName, pageData.length);
zip.file('ComicInfo.xml', comicFile);
}

pageData.forEach(page => {
zip.file(page.name, page.data);
});
Expand Down
Loading