1
0
mirror of https://github.com/ciromattia/kcc synced 2026-01-30 17:07:41 +00:00

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

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)
Upscale use now BILINEAR method
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

View File

@@ -556,6 +556,8 @@ def main(argv=None):
help="Comic title [Default=filename]")
parser.add_option("-m", "--manga-style", action="store_true", dest="righttoleft", 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,
help="Disable high quality Panel View [Default=False]")
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,
help="Do not try to cut page numbering on images [Default=True]")
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,
help="Verbose output [Default=False]")
options, args = parser.parse_args(argv)
@@ -593,25 +595,40 @@ def main(argv=None):
if options.imgproc:
print "Processing images..."
dirImgProcess(path + "/OEBPS/Images/")
print "\nCreating ePub structure..."
genEpubStruct(path)
# actually zip the ePub
if options.output is not None:
if options.output.endswith('.epub'):
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'
if options.cbzoutput:
# if CBZ output wanted, compress all images and return filepath
print "\nCreating CBZ file..."
filepath = getOutputFilename(args[0], options.output, '.cbz')
make_archive(path + '_comic', 'zip', path + '/OEBPS/Images')
else:
epubpath = os.path.splitext(args[0])[0] + '.epub'
make_archive(path + '_comic', 'zip', path)
move(path + '_comic.zip', epubpath)
print "\nCreating ePub structure..."
genEpubStruct(path)
# actually zip the ePub
filepath = getOutputFilename(args[0], options.output, '.epub')
make_archive(path + '_comic', 'zip', path)
move(path + '_comic.zip', filepath)
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():

View File

@@ -93,31 +93,33 @@ class MainWindow:
self.options = {
'Aepub_only': IntVar(None, 0),
'Bmangastyle': IntVar(None, 0),
'Cnopanelviewhq': IntVar(None, 0),
'Dimage_preprocess': IntVar(None, 0),
'Eforcepng': IntVar(None, 0),
'Fimage_gamma': DoubleVar(None, 0.0),
'Gimage_upscale': IntVar(None, 0),
'Himage_stretch': IntVar(None, 0),
'Iblack_borders': IntVar(None, 0),
'Jrotate': IntVar(None, 0),
'Knosplitrotate': IntVar(None, 0),
'Lcut_page_numbers': IntVar(None, 0)
'Bcbz_only': IntVar(None, 0),
'Cmangastyle': IntVar(None, 0),
'Dnopanelviewhq': IntVar(None, 0),
'Eimage_preprocess': IntVar(None, 0),
'Fforcepng': IntVar(None, 0),
'Gimage_gamma': DoubleVar(None, 0.0),
'Himage_upscale': IntVar(None, 0),
'Iimage_stretch': IntVar(None, 0),
'Jblack_borders': IntVar(None, 0),
'Krotate': IntVar(None, 0),
'Lnosplitrotate': IntVar(None, 0),
'Mcut_page_numbers': IntVar(None, 0)
}
self.optionlabels = {
'Aepub_only': "Generate EPUB only",
'Bmangastyle': "Manga mode",
'Cnopanelviewhq': "Disable high quality Panel View",
'Dimage_preprocess': "Disable image optimizations",
'Eforcepng': "Create PNG files instead JPEG",
'Fimage_gamma': "Custom gamma correction",
'Gimage_upscale': "Allow image upscaling",
'Himage_stretch': "Stretch images",
'Iblack_borders': "Use black borders",
'Jrotate': "Rotate images instead splitting them",
'Knosplitrotate': "Disable splitting and rotation",
'Lcut_page_numbers': "Disable page numbers cutting"
'Bcbz_only': "Generate CBZ (skip EPUB/Mobi generation)",
'Cmangastyle': "Manga mode",
'Dnopanelviewhq': "Disable high quality Panel View",
'Eimage_preprocess': "Disable image optimizations",
'Fforcepng': "Create PNG files instead of JPEG",
'Gimage_gamma': "Custom gamma correction",
'Himage_upscale': "Allow image upscaling",
'Iimage_stretch': "Stretch images",
'Jblack_borders': "Use black borders (instead of white ones)",
'Krotate': "Rotate images (instead of splitting them)",
'Lnosplitrotate': "Disable both splitting and rotation",
'Mcut_page_numbers': "Disable page numbers cutting"
}
self.optionsButtons = {}
for key in sorted(self.options):
@@ -162,28 +164,30 @@ class MainWindow:
return
profilekey = ProfileData.ProfileLabels[self.profile.get()]
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")
if self.options['Cnopanelviewhq'].get() == 1:
if self.options['Dnopanelviewhq'].get() == 1:
argv.append("--nopanelviewhq")
if self.options['Dimage_preprocess'].get() == 1:
if self.options['Eimage_preprocess'].get() == 1:
argv.append("--noprocessing")
if self.options['Eforcepng'].get() == 1:
if self.options['Fforcepng'].get() == 1:
argv.append("--forcepng")
if self.options['Fimage_gamma'].get() != 0.0:
if self.options['Gimage_gamma'].get() != 0.0:
argv.append("--gamma")
argv.append(self.options['Fimage_gamma'].get())
if self.options['Gimage_upscale'].get() == 1:
argv.append(self.options['Gimage_gamma'].get())
if self.options['Himage_upscale'].get() == 1:
argv.append("--upscale")
if self.options['Himage_stretch'].get() == 1:
if self.options['Iimage_stretch'].get() == 1:
argv.append("--stretch")
if self.options['Iblack_borders'].get() == 1:
if self.options['Jblack_borders'].get() == 1:
argv.append("--blackborders")
if self.options['Jrotate'].get() == 1:
if self.options['Krotate'].get() == 1:
argv.append("--rotate")
if self.options['Knosplitrotate'].get() == 1:
if self.options['Lnosplitrotate'].get() == 1:
argv.append("--nosplitrotate")
if self.options['Lcut_page_numbers'].get() == 1:
if self.options['Mcut_page_numbers'].get() == 1:
argv.append("--nocutpagenumbers")
errors = False
left_files = len(self.filelist)
@@ -207,7 +211,7 @@ class MainWindow:
(subargv[-1], str(err), traceback.format_tb(traceback_)))
errors = True
continue
if self.options['Aepub_only'].get() == 0:
if self.options['Aepub_only'].get() == 0 and self.options['Bcbz_only'].get() == 0:
try:
if os.path.getsize(epub_path) > 314572800:
# do not call kindlegen if source is bigger than 300MB