diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index b844568..780b967 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -43,7 +43,7 @@ from psutil import virtual_memory, disk_usage from html import escape as hescape import pymupdf -from .shared import getImageFileName, walkSort, walkLevel, sanitizeTrace, subprocess_run, dot_clean +from .shared import IMAGE_TYPES, getImageFileName, walkSort, walkLevel, sanitizeTrace, subprocess_run, dot_clean from .comicarchive import SEVENZIP, available_archive_tools from . import comic2panel from . import image @@ -1036,7 +1036,7 @@ def removeNonImages(filetree): for root, dirs, files in os.walk(filetree): for name in files: _, ext = getImageFileName(name) - if ext not in ('.png', '.jpg', '.jpeg', '.gif', '.webp', '.jp2', '.avif'): + if ext not in IMAGE_TYPES: if os.path.exists(os.path.join(root, name)): os.remove(os.path.join(root, name)) # remove empty nested folders diff --git a/kindlecomicconverter/comicarchive.py b/kindlecomicconverter/comicarchive.py index ba488a8..f3b6caa 100644 --- a/kindlecomicconverter/comicarchive.py +++ b/kindlecomicconverter/comicarchive.py @@ -20,12 +20,13 @@ from functools import cached_property, lru_cache import os +from pathlib import Path import platform import distro from subprocess import STDOUT, PIPE, CalledProcessError from xml.dom.minidom import parseString from xml.parsers.expat import ExpatError -from .shared import subprocess_run +from .shared import IMAGE_TYPES, subprocess_run EXTRACTION_ERROR = 'Failed to extract archive. Try extracting file outside of KCC.' SEVENZIP = '7zz' if platform.system() == 'Darwin' else '7z' @@ -65,6 +66,9 @@ class ComicArchive: def extract(self, targetdir): if not os.path.isdir(targetdir): raise OSError('Target directory doesn\'t exist.') + + if Path(self.basename).suffix.lower() in IMAGE_TYPES: + raise UserWarning('Put images into folder and drag and drop folder into KCC window.') missing = [] diff --git a/kindlecomicconverter/shared.py b/kindlecomicconverter/shared.py index c6857d2..4a82f23 100644 --- a/kindlecomicconverter/shared.py +++ b/kindlecomicconverter/shared.py @@ -27,6 +27,9 @@ import sys from traceback import format_tb +IMAGE_TYPES = ('.png', '.jpg', '.jpeg', '.gif', '.webp', '.jp2', '.avif') + + class HTMLStripper(HTMLParser): def __init__(self): HTMLParser.__init__(self)