diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index b5977f6..e28ddcf 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -78,13 +78,14 @@ def main(argv=None): def buildHTML(path, imgfile, imgfilepath): + key = pathlib.Path(imgfilepath).name filename = getImageFileName(imgfile) deviceres = options.profileData[1] - if not options.noprocessing and "Rotated" in options.imgMetadata[imgfilepath]: + if not options.noprocessing and "Rotated" in options.imgMetadata[key]: rotatedPage = True else: rotatedPage = False - if not options.noprocessing and "BlackBackground" in options.imgMetadata[imgfilepath]: + if not options.noprocessing and "BlackBackground" in options.imgMetadata[key]: additionalStyle = 'background-color:#000000;' else: additionalStyle = '' @@ -801,19 +802,14 @@ def sanitizeTree(filetree): for name in files: splitname = os.path.splitext(name) - # file needs kcc at front AND back to avoid renaming issues + # 9999 page limit slugified = f'kcc-{page:04}' page += 1 - for suffix in '-KCC', '-KCC-A', '-KCC-B', '-KCC-C': - if splitname[0].endswith(suffix): - slugified += suffix.lower() - break newKey = os.path.join(root, slugified + splitname[1]) key = os.path.join(root, name) if key != newKey: os.replace(key, newKey) - options.imgMetadata[newKey] = options.imgMetadata.pop(key) for i, name in enumerate(dirs): tmpName = name slugified = slugify(name) @@ -825,10 +821,6 @@ def sanitizeTree(filetree): if key != newKey: os.replace(key, newKey) dirs[i] = newKey - existingImgPathKeys = list(options.imgMetadata.keys()) - for imgPath in existingImgPathKeys: - if imgPath.startswith(key): - options.imgMetadata[newKey + imgPath.removeprefix(key)] = options.imgMetadata.pop(imgPath) return chapterNames @@ -1198,6 +1190,7 @@ def makeBook(source, qtgui=None): print("Checking images...") getComicInfo(os.path.join(path, "OEBPS", "Images"), source) detectSuboptimalProcessing(os.path.join(path, "OEBPS", "Images"), source) + chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images')) if options.webtoon: y = image.ProfileData.Profiles[options.profile][1][1] comic2panel.main(['-y ' + str(y), '-i', '-m', path], qtgui) @@ -1210,7 +1203,6 @@ def makeBook(source, qtgui=None): imgDirectoryProcessing(os.path.join(path, "OEBPS", "Images")) if GUI: GUI.progressBarTick.emit('1') - chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images')) if options.batchsplit > 0: tomes = chunk_directory(path) else: diff --git a/kindlecomicconverter/image.py b/kindlecomicconverter/image.py index 4d6a655..05c2b84 100755 --- a/kindlecomicconverter/image.py +++ b/kindlecomicconverter/image.py @@ -20,6 +20,7 @@ # along with this program. If not, see . import io import os +from pathlib import Path import mozjpeg_lossless_optimization from PIL import Image, ImageOps, ImageStat, ImageChops, ImageFilter from .page_number_crop_alg import get_bbox_crop_margin_page_number, get_bbox_crop_margin @@ -320,7 +321,7 @@ class ComicPage: output_jpeg_file.write(output_jpeg_bytes) else: self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85) - return [self.targetPath, flags, self.orgPath] + return [Path(self.targetPath).name, flags, self.orgPath] except IOError as err: raise RuntimeError('Cannot save image. ' + str(err))