mirror of
https://github.com/ciromattia/kcc
synced 2026-07-01 18:45:26 +00:00
Corruption detection now also delete non-image files (close #99)
This commit is contained in:
+110
-110
@@ -64,122 +64,121 @@ def main(argv=None):
|
|||||||
def buildHTML(path, imgfile, imgfilepath):
|
def buildHTML(path, imgfile, imgfilepath):
|
||||||
imgfilepath = md5Checksum(imgfilepath)
|
imgfilepath = md5Checksum(imgfilepath)
|
||||||
filename = getImageFileName(imgfile)
|
filename = getImageFileName(imgfile)
|
||||||
if filename is not None:
|
if options.imgproc:
|
||||||
if options.imgproc:
|
if "Rotated" in options.imgIndex[imgfilepath]:
|
||||||
if "Rotated" in options.imgIndex[imgfilepath]:
|
rotatedPage = True
|
||||||
rotatedPage = True
|
|
||||||
else:
|
|
||||||
rotatedPage = False
|
|
||||||
if "NoPanelView" in options.imgIndex[imgfilepath]:
|
|
||||||
noPV = True
|
|
||||||
else:
|
|
||||||
noPV = False
|
|
||||||
if "NoHorizontalPanelView" in options.imgIndex[imgfilepath]:
|
|
||||||
noHorizontalPV = True
|
|
||||||
else:
|
|
||||||
noHorizontalPV = False
|
|
||||||
if "NoVerticalPanelView" in options.imgIndex[imgfilepath]:
|
|
||||||
noVerticalPV = True
|
|
||||||
else:
|
|
||||||
noVerticalPV = False
|
|
||||||
else:
|
else:
|
||||||
rotatedPage = False
|
rotatedPage = False
|
||||||
|
if "NoPanelView" in options.imgIndex[imgfilepath]:
|
||||||
|
noPV = True
|
||||||
|
else:
|
||||||
noPV = False
|
noPV = False
|
||||||
|
if "NoHorizontalPanelView" in options.imgIndex[imgfilepath]:
|
||||||
|
noHorizontalPV = True
|
||||||
|
else:
|
||||||
noHorizontalPV = False
|
noHorizontalPV = False
|
||||||
|
if "NoVerticalPanelView" in options.imgIndex[imgfilepath]:
|
||||||
|
noVerticalPV = True
|
||||||
|
else:
|
||||||
noVerticalPV = False
|
noVerticalPV = False
|
||||||
htmlpath = ''
|
else:
|
||||||
postfix = ''
|
rotatedPage = False
|
||||||
backref = 1
|
noPV = False
|
||||||
head = path
|
noHorizontalPV = False
|
||||||
while True:
|
noVerticalPV = False
|
||||||
head, tail = os.path.split(head)
|
htmlpath = ''
|
||||||
if tail == 'Images':
|
postfix = ''
|
||||||
htmlpath = os.path.join(head, 'Text', postfix)
|
backref = 1
|
||||||
break
|
head = path
|
||||||
postfix = tail + "/" + postfix
|
while True:
|
||||||
backref += 1
|
head, tail = os.path.split(head)
|
||||||
if not os.path.exists(htmlpath):
|
if tail == 'Images':
|
||||||
os.makedirs(htmlpath)
|
htmlpath = os.path.join(head, 'Text', postfix)
|
||||||
htmlfile = os.path.join(htmlpath, filename[0] + '.html')
|
break
|
||||||
f = open(htmlfile, "w", encoding='UTF-8')
|
postfix = tail + "/" + postfix
|
||||||
f.writelines(["<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" ",
|
backref += 1
|
||||||
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n",
|
if not os.path.exists(htmlpath):
|
||||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
|
os.makedirs(htmlpath)
|
||||||
"<head>\n",
|
htmlfile = os.path.join(htmlpath, filename[0] + '.html')
|
||||||
"<title>", filename[0], "</title>\n",
|
f = open(htmlfile, "w", encoding='UTF-8')
|
||||||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n",
|
f.writelines(["<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" ",
|
||||||
"<link href=\"", "../" * (backref - 1),
|
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n",
|
||||||
"style.css\" type=\"text/css\" rel=\"stylesheet\"/>\n",
|
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
|
||||||
"</head>\n",
|
"<head>\n",
|
||||||
"<body>\n",
|
"<title>", filename[0], "</title>\n",
|
||||||
"<div class=\"fs\">\n",
|
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n",
|
||||||
"<div><img src=\"", "../" * backref, "Images/", postfix, imgfile, "\" alt=\"",
|
"<link href=\"", "../" * (backref - 1),
|
||||||
imgfile, "\" class=\"singlePage\"/></div>\n"
|
"style.css\" type=\"text/css\" rel=\"stylesheet\"/>\n",
|
||||||
])
|
"</head>\n",
|
||||||
if options.panelview and not noPV:
|
"<body>\n",
|
||||||
if not noHorizontalPV and not noVerticalPV:
|
"<div class=\"fs\">\n",
|
||||||
if rotatedPage:
|
"<div><img src=\"", "../" * backref, "Images/", postfix, imgfile, "\" alt=\"",
|
||||||
if options.righttoleft:
|
imgfile, "\" class=\"singlePage\"/></div>\n"
|
||||||
order = [1, 3, 2, 4]
|
])
|
||||||
else:
|
if options.panelview and not noPV:
|
||||||
order = [2, 4, 1, 3]
|
if not noHorizontalPV and not noVerticalPV:
|
||||||
|
if rotatedPage:
|
||||||
|
if options.righttoleft:
|
||||||
|
order = [1, 3, 2, 4]
|
||||||
else:
|
else:
|
||||||
if options.righttoleft:
|
order = [2, 4, 1, 3]
|
||||||
order = [2, 1, 4, 3]
|
else:
|
||||||
else:
|
if options.righttoleft:
|
||||||
order = [1, 2, 3, 4]
|
order = [2, 1, 4, 3]
|
||||||
boxes = ["BoxTL", "BoxTR", "BoxBL", "BoxBR"]
|
|
||||||
elif noHorizontalPV and not noVerticalPV:
|
|
||||||
if rotatedPage:
|
|
||||||
if options.righttoleft:
|
|
||||||
order = [1, 2]
|
|
||||||
else:
|
|
||||||
order = [2, 1]
|
|
||||||
else:
|
else:
|
||||||
order = [1, 2]
|
order = [1, 2, 3, 4]
|
||||||
boxes = ["BoxT", "BoxB"]
|
boxes = ["BoxTL", "BoxTR", "BoxBL", "BoxBR"]
|
||||||
elif not noHorizontalPV and noVerticalPV:
|
elif noHorizontalPV and not noVerticalPV:
|
||||||
if rotatedPage:
|
if rotatedPage:
|
||||||
|
if options.righttoleft:
|
||||||
order = [1, 2]
|
order = [1, 2]
|
||||||
else:
|
else:
|
||||||
if options.righttoleft:
|
order = [2, 1]
|
||||||
order = [2, 1]
|
|
||||||
else:
|
|
||||||
order = [1, 2]
|
|
||||||
boxes = ["BoxL", "BoxR"]
|
|
||||||
else:
|
else:
|
||||||
order = [1]
|
order = [1, 2]
|
||||||
boxes = ["BoxC"]
|
boxes = ["BoxT", "BoxB"]
|
||||||
for i in range(0, len(boxes)):
|
elif not noHorizontalPV and noVerticalPV:
|
||||||
f.writelines(["<div id=\"" + boxes[i] + "\"><a class=\"app-amzn-magnify\" data-app-amzn-magnify=",
|
if rotatedPage:
|
||||||
"'{\"targetId\":\"" + boxes[i] + "-Panel-Parent\", \"ordinal\":" + str(order[i]),
|
order = [1, 2]
|
||||||
"}'></a></div>\n"])
|
|
||||||
if options.quality == 2:
|
|
||||||
imgfilepv = str.split(imgfile, ".")
|
|
||||||
imgfilepv[0] += "-hq"
|
|
||||||
imgfilepv = ".".join(imgfilepv)
|
|
||||||
else:
|
else:
|
||||||
imgfilepv = imgfile
|
if options.righttoleft:
|
||||||
xl, yu, xr, yd = detectMargins(imgfilepath)
|
order = [2, 1]
|
||||||
boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";",
|
else:
|
||||||
"BoxTR": "right:" + xr + ";top:" + yu + ";",
|
order = [1, 2]
|
||||||
"BoxBL": "left:" + xl + ";bottom:" + yd + ";",
|
boxes = ["BoxL", "BoxR"]
|
||||||
"BoxBR": "right:" + xr + ";bottom:" + yd + ";",
|
else:
|
||||||
"BoxT": "left:-25%;top:" + yu + ";",
|
order = [1]
|
||||||
"BoxB": "left:-25%;bottom:" + yd + ";",
|
boxes = ["BoxC"]
|
||||||
"BoxL": "left:" + xl + ";top:-25%;",
|
for i in range(0, len(boxes)):
|
||||||
"BoxR": "right:" + xr + ";top:-25%;",
|
f.writelines(["<div id=\"" + boxes[i] + "\"><a class=\"app-amzn-magnify\" data-app-amzn-magnify=",
|
||||||
"BoxC": "left:-25%;top:-25%;"
|
"'{\"targetId\":\"" + boxes[i] + "-Panel-Parent\", \"ordinal\":" + str(order[i]),
|
||||||
}
|
"}'></a></div>\n"])
|
||||||
for box in boxes:
|
if options.quality == 2:
|
||||||
f.writelines(["<div id=\"" + box + "-Panel-Parent\" class=\"target-mag-parent\"><div id=\"",
|
imgfilepv = str.split(imgfile, ".")
|
||||||
"Generic-Panel\" class=\"target-mag\"><img style=\"" + boxStyles[box] + "\" src=\"",
|
imgfilepv[0] += "-hq"
|
||||||
"../" * backref, "Images/", postfix, imgfilepv, "\" alt=\"" + imgfilepv,
|
imgfilepv = ".".join(imgfilepv)
|
||||||
"\"/></div></div>\n",
|
else:
|
||||||
])
|
imgfilepv = imgfile
|
||||||
f.writelines(["</div>\n</body>\n</html>"])
|
xl, yu, xr, yd = detectMargins(imgfilepath)
|
||||||
f.close()
|
boxStyles = {"BoxTL": "left:" + xl + ";top:" + yu + ";",
|
||||||
return path, imgfile
|
"BoxTR": "right:" + xr + ";top:" + yu + ";",
|
||||||
|
"BoxBL": "left:" + xl + ";bottom:" + yd + ";",
|
||||||
|
"BoxBR": "right:" + xr + ";bottom:" + yd + ";",
|
||||||
|
"BoxT": "left:-25%;top:" + yu + ";",
|
||||||
|
"BoxB": "left:-25%;bottom:" + yd + ";",
|
||||||
|
"BoxL": "left:" + xl + ";top:-25%;",
|
||||||
|
"BoxR": "right:" + xr + ";top:-25%;",
|
||||||
|
"BoxC": "left:-25%;top:-25%;"
|
||||||
|
}
|
||||||
|
for box in boxes:
|
||||||
|
f.writelines(["<div id=\"" + box + "-Panel-Parent\" class=\"target-mag-parent\"><div id=\"",
|
||||||
|
"Generic-Panel\" class=\"target-mag\"><img style=\"" + boxStyles[box] + "\" src=\"",
|
||||||
|
"../" * backref, "Images/", postfix, imgfilepv, "\" alt=\"" + imgfilepv,
|
||||||
|
"\"/></div></div>\n",
|
||||||
|
])
|
||||||
|
f.writelines(["</div>\n</body>\n</html>"])
|
||||||
|
f.close()
|
||||||
|
return path, imgfile
|
||||||
|
|
||||||
|
|
||||||
def buildNCX(dstdir, title, chapters, chapterNames):
|
def buildNCX(dstdir, title, chapters, chapterNames):
|
||||||
@@ -410,7 +409,7 @@ def buildEPUB(path, chapterNames, tomeNumber):
|
|||||||
chapter = False
|
chapter = False
|
||||||
for afile in filenames:
|
for afile in filenames:
|
||||||
filename = getImageFileName(afile)
|
filename = getImageFileName(afile)
|
||||||
if filename is not None and not '-kcc-hq' in filename[0]:
|
if not '-kcc-hq' in filename[0]:
|
||||||
filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
|
filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
|
||||||
if not chapter:
|
if not chapter:
|
||||||
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
||||||
@@ -459,9 +458,8 @@ def imgDirectoryProcessing(path):
|
|||||||
pagenumber = 0
|
pagenumber = 0
|
||||||
for (dirpath, dirnames, filenames) in os.walk(path):
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||||
for afile in filenames:
|
for afile in filenames:
|
||||||
if getImageFileName(afile) is not None:
|
pagenumber += 1
|
||||||
pagenumber += 1
|
work.append([afile, dirpath, options])
|
||||||
work.append([afile, dirpath, options])
|
|
||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit(str(pagenumber))
|
GUI.progressBarTick.emit(str(pagenumber))
|
||||||
if len(work) > 0:
|
if len(work) > 0:
|
||||||
@@ -870,6 +868,8 @@ def detectCorruption(tmpPath, orgPath):
|
|||||||
except Exception:
|
except Exception:
|
||||||
rmtree(os.path.join(tmpPath, '..', '..'), True)
|
rmtree(os.path.join(tmpPath, '..', '..'), True)
|
||||||
raise RuntimeError('Image file %s is corrupted.' % pathOrg)
|
raise RuntimeError('Image file %s is corrupted.' % pathOrg)
|
||||||
|
else:
|
||||||
|
os.remove(os.path.join(root, name))
|
||||||
|
|
||||||
|
|
||||||
def detectMargins(path):
|
def detectMargins(path):
|
||||||
@@ -1062,8 +1062,8 @@ def makeBook(source, qtGUI=None):
|
|||||||
GUI.progressBarTick.emit('1')
|
GUI.progressBarTick.emit('1')
|
||||||
path = getWorkFolder(source)
|
path = getWorkFolder(source)
|
||||||
print("\nChecking images...")
|
print("\nChecking images...")
|
||||||
detectCorruption(os.path.join(path, "OEBPS", "Images"), source)
|
|
||||||
getComicInfo(os.path.join(path, "OEBPS", "Images"), source)
|
getComicInfo(os.path.join(path, "OEBPS", "Images"), source)
|
||||||
|
detectCorruption(os.path.join(path, "OEBPS", "Images"), source)
|
||||||
if options.webtoon:
|
if options.webtoon:
|
||||||
if options.customheight > 0:
|
if options.customheight > 0:
|
||||||
comic2panel.main(['-y ' + str(options.customheight), '-i', '-m', path], qtGUI)
|
comic2panel.main(['-y ' + str(options.customheight), '-i', '-m', path], qtGUI)
|
||||||
|
|||||||
Reference in New Issue
Block a user