From 1341163851b301073657ad5a6aee16edde0e2547 Mon Sep 17 00:00:00 2001 From: quantrancse Date: Tue, 17 Aug 2021 23:07:20 +0700 Subject: [PATCH] Fix epub name special characters --- hako2epub.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hako2epub.py b/hako2epub.py index aecfabc..308b62a 100644 --- a/hako2epub.py +++ b/hako2epub.py @@ -211,6 +211,9 @@ class EpubEngine(): def __init__(self): self.ln_info_json_file = 'ln_info.json' + def format_name(self, name): + return name.replace(' ', '-').replace('?', '').replace('!', '') + def make_cover_image(self): try: print('Making cover image...') @@ -354,11 +357,11 @@ def bind_epub_book(self): self.book.add_item(epub.EpubNcx()) self.book.add_item(epub.EpubNav()) - epub_name = self.volume.name + '-' + self.ln.name + '.epub' - epub_name = epub_name.replace(' ', '-') + epub_name = self.format_name( + self.volume.name + '-' + self.ln.name + '.epub') self.set_metadata(epub_name, self.ln.author) - epub_folder = self.ln.name.replace(' ', '-').replace('?', '').replace('!', '') + epub_folder = self.format_name(self.ln.name) if not isdir(epub_folder): mkdir(epub_folder) @@ -379,9 +382,8 @@ def create_epub(self, ln): self.save_json(ln) def update_epub(self, ln, volume): - epub_name = volume.name + '-' + ln.name + '.epub' - epub_name = epub_name.replace(' ', '-') - epub_folder = ln.name.replace(' ', '-').replace('?', '').replace('!', '') + epub_name = self.format_name(volume.name + '-' + ln.name + '.epub') + epub_folder = self.format_name(ln.name) epub_path = epub_folder + '/' + epub_name try: