Add an option to generate a CBZ skipping all the EPUB/Mobi stuff.

Prevent output files to overwrite the source (add _kcc if duplicate is detected)
Fixes #45
This commit is contained in:
Ciro Mattia Gonano
2013-04-10 12:29:31 +02:00
parent d923299230
commit 220b4e0954
3 changed files with 77 additions and 54 deletions
+3 -1
View File
@@ -121,7 +121,9 @@ The app relies and includes the following scripts/binaries:
Rewrite of Landscape Mode support (huge readability improvement for KPW) Rewrite of Landscape Mode support (huge readability improvement for KPW)
Upscale use now BILINEAR method Upscale use now BILINEAR method
Added generic CSS file Added generic CSS file
Optimized archive extraction for zip/rar files (#40) Optimized archive extraction for zip/rar files (#40)
- 2.9: Added support for generating a plain CBZ (skipping all the EPUB/Mobi generation) (#45)
Prevent output file overwriting the source one: if a duplicate name is detected, append _kcc to the name
## COPYRIGHT ## COPYRIGHT
+35 -18
View File
@@ -556,6 +556,8 @@ def main(argv=None):
help="Comic title [Default=filename]") help="Comic title [Default=filename]")
parser.add_option("-m", "--manga-style", action="store_true", dest="righttoleft", default=False, parser.add_option("-m", "--manga-style", action="store_true", dest="righttoleft", default=False,
help="Manga style (Right-to-left reading and splitting) [Default=False]") help="Manga style (Right-to-left reading and splitting) [Default=False]")
parser.add_option("-c", "--cbz-output", action="store_true", dest="cbzoutput", default=False,
help="Outputs a CBZ archive and does not generate EPUB")
parser.add_option("--nopanelviewhq", action="store_true", dest="nopanelviewhq", default=False, parser.add_option("--nopanelviewhq", action="store_true", dest="nopanelviewhq", default=False,
help="Disable high quality Panel View [Default=False]") help="Disable high quality Panel View [Default=False]")
parser.add_option("--noprocessing", action="store_false", dest="imgproc", default=True, parser.add_option("--noprocessing", action="store_false", dest="imgproc", default=True,
@@ -578,7 +580,7 @@ def main(argv=None):
parser.add_option("--nocutpagenumbers", action="store_false", dest="cutpagenumbers", default=True, parser.add_option("--nocutpagenumbers", action="store_false", dest="cutpagenumbers", default=True,
help="Do not try to cut page numbering on images [Default=True]") help="Do not try to cut page numbering on images [Default=True]")
parser.add_option("-o", "--output", action="store", dest="output", default=None, parser.add_option("-o", "--output", action="store", dest="output", default=None,
help="Output generated EPUB to specified directory or file") help="Output generated file (EPUB or CBZ) to specified directory or file")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
help="Verbose output [Default=False]") help="Verbose output [Default=False]")
options, args = parser.parse_args(argv) options, args = parser.parse_args(argv)
@@ -593,25 +595,40 @@ def main(argv=None):
if options.imgproc: if options.imgproc:
print "Processing images..." print "Processing images..."
dirImgProcess(path + "/OEBPS/Images/") dirImgProcess(path + "/OEBPS/Images/")
print "\nCreating ePub structure..." if options.cbzoutput:
genEpubStruct(path) # if CBZ output wanted, compress all images and return filepath
# actually zip the ePub print "\nCreating CBZ file..."
if options.output is not None: filepath = getOutputFilename(args[0], options.output, '.cbz')
if options.output.endswith('.epub'): make_archive(path + '_comic', 'zip', path + '/OEBPS/Images')
epubpath = os.path.abspath(options.output)
elif os.path.isdir(args[0]):
epubpath = os.path.abspath(options.output) + "/" + os.path.basename(args[0]) + '.epub'
else:
epubpath = os.path.abspath(options.output) + "/" \
+ os.path.basename(os.path.splitext(args[0])[0]) + '.epub'
elif os.path.isdir(args[0]):
epubpath = args[0] + '.epub'
else: else:
epubpath = os.path.splitext(args[0])[0] + '.epub' print "\nCreating ePub structure..."
make_archive(path + '_comic', 'zip', path) genEpubStruct(path)
move(path + '_comic.zip', epubpath) # actually zip the ePub
filepath = getOutputFilename(args[0], options.output, '.epub')
make_archive(path + '_comic', 'zip', path)
move(path + '_comic.zip', filepath)
rmtree(path) rmtree(path)
return epubpath return filepath
def getOutputFilename(srcpath, wantedname, ext):
if not ext.startswith('.'):
ext = '.' + ext
if wantedname is not None:
if wantedname.endswith(ext):
filename = os.path.abspath(wantedname)
elif os.path.isdir(srcpath):
filename = os.path.abspath(options.output) + "/" + os.path.basename(srcpath) + ext
else:
filename = os.path.abspath(options.output) + "/" \
+ os.path.basename(os.path.splitext(srcpath)[0]) + ext
elif os.path.isdir(srcpath):
filename = srcpath + ext
else:
filename = os.path.splitext(srcpath)[0] + ext
if os.path.isfile(filename):
filename = os.path.splitext(filename)[0] + '_kcc' + ext
return filename
def checkOptions(): def checkOptions():
+39 -35
View File
@@ -93,31 +93,33 @@ class MainWindow:
self.options = { self.options = {
'Aepub_only': IntVar(None, 0), 'Aepub_only': IntVar(None, 0),
'Bmangastyle': IntVar(None, 0), 'Bcbz_only': IntVar(None, 0),
'Cnopanelviewhq': IntVar(None, 0), 'Cmangastyle': IntVar(None, 0),
'Dimage_preprocess': IntVar(None, 0), 'Dnopanelviewhq': IntVar(None, 0),
'Eforcepng': IntVar(None, 0), 'Eimage_preprocess': IntVar(None, 0),
'Fimage_gamma': DoubleVar(None, 0.0), 'Fforcepng': IntVar(None, 0),
'Gimage_upscale': IntVar(None, 0), 'Gimage_gamma': DoubleVar(None, 0.0),
'Himage_stretch': IntVar(None, 0), 'Himage_upscale': IntVar(None, 0),
'Iblack_borders': IntVar(None, 0), 'Iimage_stretch': IntVar(None, 0),
'Jrotate': IntVar(None, 0), 'Jblack_borders': IntVar(None, 0),
'Knosplitrotate': IntVar(None, 0), 'Krotate': IntVar(None, 0),
'Lcut_page_numbers': IntVar(None, 0) 'Lnosplitrotate': IntVar(None, 0),
'Mcut_page_numbers': IntVar(None, 0)
} }
self.optionlabels = { self.optionlabels = {
'Aepub_only': "Generate EPUB only", 'Aepub_only': "Generate EPUB only",
'Bmangastyle': "Manga mode", 'Bcbz_only': "Generate CBZ (skip EPUB/Mobi generation)",
'Cnopanelviewhq': "Disable high quality Panel View", 'Cmangastyle': "Manga mode",
'Dimage_preprocess': "Disable image optimizations", 'Dnopanelviewhq': "Disable high quality Panel View",
'Eforcepng': "Create PNG files instead JPEG", 'Eimage_preprocess': "Disable image optimizations",
'Fimage_gamma': "Custom gamma correction", 'Fforcepng': "Create PNG files instead of JPEG",
'Gimage_upscale': "Allow image upscaling", 'Gimage_gamma': "Custom gamma correction",
'Himage_stretch': "Stretch images", 'Himage_upscale': "Allow image upscaling",
'Iblack_borders': "Use black borders", 'Iimage_stretch': "Stretch images",
'Jrotate': "Rotate images instead splitting them", 'Jblack_borders': "Use black borders (instead of white ones)",
'Knosplitrotate': "Disable splitting and rotation", 'Krotate': "Rotate images (instead of splitting them)",
'Lcut_page_numbers': "Disable page numbers cutting" 'Lnosplitrotate': "Disable both splitting and rotation",
'Mcut_page_numbers': "Disable page numbers cutting"
} }
self.optionsButtons = {} self.optionsButtons = {}
for key in sorted(self.options): for key in sorted(self.options):
@@ -162,28 +164,30 @@ class MainWindow:
return return
profilekey = ProfileData.ProfileLabels[self.profile.get()] profilekey = ProfileData.ProfileLabels[self.profile.get()]
argv = ["-p", profilekey] argv = ["-p", profilekey]
if self.options['Bmangastyle'].get() == 1: if self.options['Bcbz_only'].get() == 1:
argv.append("-c")
if self.options['Cmangastyle'].get() == 1:
argv.append("-m") argv.append("-m")
if self.options['Cnopanelviewhq'].get() == 1: if self.options['Dnopanelviewhq'].get() == 1:
argv.append("--nopanelviewhq") argv.append("--nopanelviewhq")
if self.options['Dimage_preprocess'].get() == 1: if self.options['Eimage_preprocess'].get() == 1:
argv.append("--noprocessing") argv.append("--noprocessing")
if self.options['Eforcepng'].get() == 1: if self.options['Fforcepng'].get() == 1:
argv.append("--forcepng") argv.append("--forcepng")
if self.options['Fimage_gamma'].get() != 0.0: if self.options['Gimage_gamma'].get() != 0.0:
argv.append("--gamma") argv.append("--gamma")
argv.append(self.options['Fimage_gamma'].get()) argv.append(self.options['Gimage_gamma'].get())
if self.options['Gimage_upscale'].get() == 1: if self.options['Himage_upscale'].get() == 1:
argv.append("--upscale") argv.append("--upscale")
if self.options['Himage_stretch'].get() == 1: if self.options['Iimage_stretch'].get() == 1:
argv.append("--stretch") argv.append("--stretch")
if self.options['Iblack_borders'].get() == 1: if self.options['Jblack_borders'].get() == 1:
argv.append("--blackborders") argv.append("--blackborders")
if self.options['Jrotate'].get() == 1: if self.options['Krotate'].get() == 1:
argv.append("--rotate") argv.append("--rotate")
if self.options['Knosplitrotate'].get() == 1: if self.options['Lnosplitrotate'].get() == 1:
argv.append("--nosplitrotate") argv.append("--nosplitrotate")
if self.options['Lcut_page_numbers'].get() == 1: if self.options['Mcut_page_numbers'].get() == 1:
argv.append("--nocutpagenumbers") argv.append("--nocutpagenumbers")
errors = False errors = False
left_files = len(self.filelist) left_files = len(self.filelist)
@@ -207,7 +211,7 @@ class MainWindow:
(subargv[-1], str(err), traceback.format_tb(traceback_))) (subargv[-1], str(err), traceback.format_tb(traceback_)))
errors = True errors = True
continue continue
if self.options['Aepub_only'].get() == 0: if self.options['Aepub_only'].get() == 0 and self.options['Bcbz_only'].get() == 0:
try: try:
if os.path.getsize(epub_path) > 314572800: if os.path.getsize(epub_path) > 314572800:
# do not call kindlegen if source is bigger than 300MB # do not call kindlegen if source is bigger than 300MB