mirror of
https://github.com/ciromattia/kcc
synced 2026-04-15 05:28:49 +00:00
Compare commits
5 Commits
v7.2.0
...
revert-753
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04618d5bbf | ||
|
|
b35a2baf05 | ||
|
|
11a395e983 | ||
|
|
2e39a8c227 | ||
|
|
02535421a0 |
@@ -1,4 +1,4 @@
|
||||
__version__ = '7.2.0'
|
||||
__version__ = '7.2.1'
|
||||
__license__ = 'ISC'
|
||||
__copyright__ = '2012-2022, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>, darodi'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
@@ -645,6 +645,7 @@ def getWorkFolder(afile):
|
||||
if afile.lower().endswith('.pdf'):
|
||||
pdf = pdfjpgextract.PdfJpgExtract(afile)
|
||||
path, njpg = pdf.extract()
|
||||
workdir = path
|
||||
sanitizePermissions(path)
|
||||
if njpg == 0:
|
||||
rmtree(path, True)
|
||||
@@ -828,12 +829,11 @@ def sanitizePermissions(filetree):
|
||||
os.chmod(os.path.join(root, name), S_IWRITE | S_IREAD | S_IEXEC)
|
||||
|
||||
|
||||
def batch_directory(path):
|
||||
def chunk_directory(path):
|
||||
level = -1
|
||||
for root, _, files in os.walk(os.path.join(path, 'OEBPS', 'Images')):
|
||||
for f in files:
|
||||
if f.endswith('.jpg') or f.endswith('.jpeg') or f.endswith('.png') or f.endswith('.gif') or \
|
||||
f.endswith('.webp'):
|
||||
if getImageFileName(f):
|
||||
newLevel = os.path.join(root, f).replace(os.path.join(path, 'OEBPS', 'Images'), '').count(os.sep)
|
||||
if level != -1 and level != newLevel:
|
||||
level = 0
|
||||
@@ -842,16 +842,16 @@ def batch_directory(path):
|
||||
level = newLevel
|
||||
if level > 0:
|
||||
parent = pathlib.Path(path).parent
|
||||
batcher = batch_process(os.path.join(path, 'OEBPS', 'Images'), level, parent)
|
||||
chunker = chunk_process(os.path.join(path, 'OEBPS', 'Images'), level, parent)
|
||||
path = [path]
|
||||
for tome in batcher:
|
||||
for tome in chunker:
|
||||
path.append(tome)
|
||||
return path
|
||||
else:
|
||||
raise UserWarning('Unsupported directory structure.')
|
||||
|
||||
|
||||
def batch_process(path, mode, parent):
|
||||
def chunk_process(path, mode, parent):
|
||||
output = []
|
||||
currentSize = 0
|
||||
currentTarget = path
|
||||
@@ -1196,7 +1196,7 @@ def makeBook(source, qtgui=None):
|
||||
GUI.progressBarTick.emit('1')
|
||||
chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
|
||||
if options.batchsplit > 0:
|
||||
tomes = batch_directory(path)
|
||||
tomes = chunk_directory(path)
|
||||
else:
|
||||
tomes = [path]
|
||||
filepath = []
|
||||
|
||||
@@ -49,7 +49,7 @@ class HTMLStripper(HTMLParser):
|
||||
def getImageFileName(imgfile):
|
||||
name, ext = os.path.splitext(imgfile)
|
||||
ext = ext.lower()
|
||||
if (name.startswith('.') and len(name) == 1) or ext not in ['.png', '.jpg', '.jpeg', '.gif', '.webp']:
|
||||
if (name.startswith('.') and len(name) == 1) or ext not in ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.jp2', '.j2k', '.jpx']:
|
||||
return None
|
||||
return [name, ext]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user