mirror of
https://github.com/ciromattia/kcc
synced 2025-12-15 18:56:28 +00:00
Split comic2ebook.py main in two
Now has main() which initialises program and makeBook which does the actual work.
This commit is contained in:
@@ -955,62 +955,85 @@ def main(argv=None, qtGUI=None):
|
|||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return
|
return
|
||||||
path = getWorkFolder(args[0])
|
|
||||||
|
source = args[0]
|
||||||
|
outputPath = makeBook(source, qtGUI=qtGUI)
|
||||||
|
return outputPath
|
||||||
|
|
||||||
|
def makeBook(source, qtGUI=None):
|
||||||
|
"""Generates EPUB/CBZ comic ebook from a bunch of images."""
|
||||||
|
global GUI
|
||||||
|
GUI = qtGUI
|
||||||
|
path = getWorkFolder(source)
|
||||||
print("\nChecking images...")
|
print("\nChecking images...")
|
||||||
detectCorruption(os.path.join(path, "OEBPS", "Images"), args[0])
|
detectCorruption(os.path.join(path, "OEBPS", "Images"), source)
|
||||||
checkComicInfo(os.path.join(path, "OEBPS", "Images"), args[0])
|
checkComicInfo(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)
|
||||||
else:
|
else:
|
||||||
comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', '-m', path], qtGUI)
|
comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', '-m', path], qtGUI)
|
||||||
|
|
||||||
if options.imgproc:
|
if options.imgproc:
|
||||||
print("\nProcessing images...")
|
print("\nProcessing images...")
|
||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('Processing images')
|
GUI.progressBarTick.emit('Processing images')
|
||||||
dirImgProcess(os.path.join(path, "OEBPS", "Images"))
|
dirImgProcess(os.path.join(path, "OEBPS", "Images"))
|
||||||
|
|
||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('1')
|
GUI.progressBarTick.emit('1')
|
||||||
|
|
||||||
chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
|
chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
|
||||||
|
|
||||||
if options.batchsplit:
|
if options.batchsplit:
|
||||||
tomes = preSplitDirectory(path)
|
tomes = preSplitDirectory(path)
|
||||||
else:
|
else:
|
||||||
tomes = [path]
|
tomes = [path]
|
||||||
|
|
||||||
filepath = []
|
filepath = []
|
||||||
tomeNumber = 0
|
tomeNumber = 0
|
||||||
|
|
||||||
if GUI:
|
if GUI:
|
||||||
if options.cbzoutput:
|
if options.cbzoutput:
|
||||||
GUI.progressBarTick.emit('Compressing CBZ files')
|
GUI.progressBarTick.emit('Compressing CBZ files')
|
||||||
else:
|
else:
|
||||||
GUI.progressBarTick.emit('Compressing EPUB files')
|
GUI.progressBarTick.emit('Compressing EPUgB files')
|
||||||
GUI.progressBarTick.emit(str(len(tomes) + 1))
|
GUI.progressBarTick.emit(str(len(tomes) + 1))
|
||||||
GUI.progressBarTick.emit('tick')
|
GUI.progressBarTick.emit('tick')
|
||||||
|
|
||||||
options.baseTitle = options.title
|
options.baseTitle = options.title
|
||||||
|
|
||||||
for tome in tomes:
|
for tome in tomes:
|
||||||
if len(tomes) > 1:
|
if len(tomes) > 1:
|
||||||
tomeNumber += 1
|
tomeNumber += 1
|
||||||
options.title = options.baseTitle + ' [' + str(tomeNumber) + '/' + str(len(tomes)) + ']'
|
options.title = options.baseTitle + ' [' + str(tomeNumber) + '/' + str(len(tomes)) + ']'
|
||||||
|
|
||||||
if options.cbzoutput:
|
if options.cbzoutput:
|
||||||
# if CBZ output wanted, compress all images and return filepath
|
# if CBZ output wanted, compress all images and return filepath
|
||||||
print("\nCreating CBZ file...")
|
print("\nCreating CBZ file...")
|
||||||
if len(tomes) > 1:
|
if len(tomes) > 1:
|
||||||
filepath.append(getOutputFilename(args[0], options.output, '.cbz', ' ' + str(tomeNumber)))
|
filepath.append(getOutputFilename(source, options.output, '.cbz', ' ' + str(tomeNumber)))
|
||||||
else:
|
else:
|
||||||
filepath.append(getOutputFilename(args[0], options.output, '.cbz', ''))
|
filepath.append(getOutputFilename(source, options.output, '.cbz', ''))
|
||||||
makeZIP(tome + '_comic', os.path.join(tome, "OEBPS", "Images"))
|
makeZIP(tome + '_comic', os.path.join(tome, "OEBPS", "Images"))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("\nCreating EPUB structure...")
|
print("\nCreating EPUB structure...")
|
||||||
genEpubStruct(tome, chapterNames)
|
genEpubStruct(tome, chapterNames)
|
||||||
# actually zip the ePub
|
# actually zip the ePub
|
||||||
if len(tomes) > 1:
|
if len(tomes) > 1:
|
||||||
filepath.append(getOutputFilename(args[0], options.output, '.epub', ' ' + str(tomeNumber)))
|
filepath.append(getOutputFilename(source, options.output, '.epub', ' ' + str(tomeNumber)))
|
||||||
else:
|
else:
|
||||||
filepath.append(getOutputFilename(args[0], options.output, '.epub', ''))
|
filepath.append(getOutputFilename(source, options.output, '.epub', ''))
|
||||||
makeZIP(tome + '_comic', tome, True)
|
makeZIP(tome + '_comic', tome, True)
|
||||||
|
|
||||||
move(tome + '_comic.zip', filepath[-1])
|
move(tome + '_comic.zip', filepath[-1])
|
||||||
rmtree(tome, True)
|
rmtree(tome, True)
|
||||||
|
|
||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('tick')
|
GUI.progressBarTick.emit('tick')
|
||||||
|
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
|
||||||
@@ -1091,4 +1114,4 @@ def checkOptions():
|
|||||||
(int(X*1.5), int(Y*1.5)))
|
(int(X*1.5), int(Y*1.5)))
|
||||||
image.ProfileData.Profiles["Custom"] = newProfile
|
image.ProfileData.Profiles["Custom"] = newProfile
|
||||||
options.profile = "Custom"
|
options.profile = "Custom"
|
||||||
options.profileData = image.ProfileData.Profiles[options.profile]
|
options.profileData = image.ProfileData.Profiles[options.profile]
|
||||||
|
|||||||
Reference in New Issue
Block a user