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 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
6 changes: 6 additions & 0 deletions src/web/mjs/HakuNeko.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BookmarkManager from './engine/BookmarkManager.mjs';
import ChaptermarkManager from './engine/ChaptermarkManager.mjs';
import Connectors from './engine/Connectors.mjs';
import DownloadManager from './engine/DownloadManager.mjs';
import ComicInfoGenerator from './engine/ComicInfoGenerator.mjs';
//import HistoryWorker from './engine/HistoryWorker.mjs'
import Request from './engine/Request.mjs';
import Settings from './engine/Settings.mjs';
Expand All @@ -32,6 +33,7 @@ export default class HakuNeko {
this._connectors = new Connectors(ipc);
this._storage = new Storage();
this._bookmarkManager = new BookmarkManager(this._settings, new BookmarkImporter());
this._comicInfoGenerator = new ComicInfoGenerator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This instance seems not to be of global significance to be placed in the engine scope, just inject it into the Storage constructor, thats the only place where it is really needed.

this._chaptermarkManager = new ChaptermarkManager(this._settings);
this._discordPresence = new DiscordPresence(this._settings);
}
Expand Down Expand Up @@ -63,6 +65,10 @@ export default class HakuNeko {
return this._bookmarkManager;
}

get ComicInfoGenerator() {
return this._comicInfoGenerator;
}

get ChaptermarkManager() {
return this._chaptermarkManager;
}
Expand Down
26 changes: 26 additions & 0 deletions src/web/mjs/engine/ComicInfoGenerator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default class ComicInfoGenerator {
apiweb marked this conversation as resolved.
Show resolved Hide resolved
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>`;
}

escapeXML(str) {
const symbols = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'\'': '&apos;',
'"': '&quot;'
};

return str.replace(/[<>&'"]/g, function (c) {
return symbols[c];
});
}
}
2 changes: 1 addition & 1 deletion src/web/mjs/engine/Settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,4 @@ export default class Settings extends EventTarget {
return value;
}
}
}
}
10 changes: 7 additions & 3 deletions src/web/mjs/engine/Storage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export default class Storage {
}
if (Engine.Settings.chapterFormat.value === extensions.cbz) {
this._createDirectoryChain(this.path.dirname(output));
promise = this._saveChapterPagesCBZ(output, pageData)
promise = this._saveChapterPagesCBZ(output, pageData, chapter.manga.title, chapter.title)
.then(() => this._runPostChapterDownloadCommand(chapter, output));
}
if (Engine.Settings.chapterFormat.value === extensions.pdf) {
Expand Down Expand Up @@ -548,8 +548,12 @@ 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();

let comicFile = Engine.ComicInfoGenerator.createComicInfoXML(mangaName, chapterName, pageData.length);
zip.file('ComicInfo.xml', comicFile);

pageData.forEach(page => {
zip.file(page.name, page.data);
});
Expand Down Expand Up @@ -893,4 +897,4 @@ export default class Storage {
});
});
}
}
}
Loading