1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 01:36:27 +00:00

Start to work on py2exe/py2app ready code.

This commit is contained in:
Ciro Mattia Gonano
2012-12-17 10:45:24 +01:00
parent 59ea7a00d8
commit dd90ab5908
5 changed files with 123 additions and 70 deletions

View File

@@ -1,19 +1,18 @@
# KindleComicConverter # KindleComicConverter
`KindleComicConverter` is a Python script wrapped by a MacOS X AppleScript droplet to convert image folders to a comic-type Mobipocket ebook to take advantage of the new Panel View mode on Amazon's Kindle. `KindleComicConverter` is a Python app which aim is to convert image folders to a comic-type (Mobipocket) ebook to take advantage of the new Panel View mode on Amazon's Kindle.
## REQUIREMENTS ## REQUIREMENTS
- Python (included in MacOS and Linux, follow the [official documentation](http://www.python.org/getit/windows/) to install on Windows)
- `kindlegen` in /usr/local/bin/ - `kindlegen` in /usr/local/bin/
- [unrar](http://www.rarlab.com/download.htm) and [rarfile.py](http://developer.berlios.de/project/showfiles.php?group_id=5373&release_id=18844) for `calibre2ebook.py` automatic CBR extracting.
### for standalone `comic2ebook.py` script: ### for compiling/running from source:
- [unrar](http://www.rarlab.com/download.htm) and [rarfile.py](http://developer.berlios.de/project/showfiles.php?group_id=5373&release_id=18844) for `calibre2ebook.py` automatic CBR extracting. - Python 2.7+ (included in MacOS and Linux, follow the [official documentation](http://www.python.org/getit/windows/) to install on Windows)
- You are strongly encouraged to get the [Python Imaging Library](http://www.pythonware.com/products/pil/) that, altough optional, provides a bunch of comic optimizations like split double pages, resize to optimal resolution, improve contrast and palette, etc.
You are strongly encouraged to get the [Python Imaging Library](http://www.pythonware.com/products/pil/) that, altough optional, provides a bunch of comic optimizations like split double pages, resize to optimal resolution, improve contrast and palette, etc. Please refer to official documentation for installing into your system.
Please refer to official documentation for installing into your system.
## USAGE ## USAGE
Drop a folder or a CBZ/CBR file over the droplet, after a while you'll get a comic-type .mobi to sideload on your Kindle. Drop a folder or a CBZ/CBR file over the app, after a while you'll get a comic-type .mobi to sideload on your Kindle.
The script takes care of calling `comic2ebook.py`, `kindlegen` and `kindlestrip.py`. The script takes care of calling `comic2ebook.py`, `kindlegen` and `kindlestrip.py`.
> **WARNING:** at the moment the droplet *ALWAYS* uses the **KHD** profile (*Kindle Paperwhite*). > **WARNING:** at the moment the droplet *ALWAYS* uses the **KHD** profile (*Kindle Paperwhite*).
@@ -52,12 +51,12 @@ and installed in `/usr/local/bin/`
- 1.20 - Comic optimizations! Split pages not target-oriented (landscape with portrait target or portrait - 1.20 - Comic optimizations! Split pages not target-oriented (landscape with portrait target or portrait
with landscape target), add palette and other image optimizations from Mangle. with landscape target), add palette and other image optimizations from Mangle.
WARNING: PIL is required for all image mangling! WARNING: PIL is required for all image mangling!
- 2.00 - GUI! AppleScript is gone and Tk is used to provide cross-platform GUI support.
## TODO ## TODO
- Add gracefully exit for CBR if no rarfile.py and no unrar executable are found - Add gracefully exit for CBR if no rarfile.py and no unrar executable are found
- Improve error reporting - Improve error reporting
- Recurse into dirtree for multiple comics - Recurse into dirtree for multiple comics
- Create a GUI to allow user control more options
- Support pages extraction from PDF files - Support pages extraction from PDF files
## COPYRIGHT ## COPYRIGHT

44
kcc.py Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env python
#
# Copyright (c) 2012 Ciro Mattia Gonano <ciromattia@gmail.com>
#
# Permission to use, copy, modify, and/or distribute this software for
# any purpose with or without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all
# copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# Changelog
# 1.00 - Initial version
# 1.10 - Added support for CBZ/CBR files
# 1.11 - Added support for ZIP/RAR extensions
# 1.20 - Comic optimizations! Split pages not target-oriented (landscape
# with portrait target or portrait with landscape target), add palette
# and other image optimizations from Mangle.
# WARNING: PIL is required for all image mangling!
#
# Todo:
# - Add gracefully exit for CBR if no rarfile.py and no unrar
# executable are found
# - Improve error reporting
# - recurse into dirtree for multiple comics
__version__ = '1.30'
import sys
from kcc import comic2ebook
if __name__ == "__main__":
print ('kcc v%(__version__)s. '
'Written 2012 by Ciro Mattia Gonano.' % globals())
for arg in sys.argv[1:]:
comic2ebook.main(['','KHD',arg])
sys.exit(0)

View File

@@ -130,56 +130,67 @@ def isInFilelist(file,list):
seen = True seen = True
return seen return seen
if __name__ == "__main__": def Copyright():
print ('comic2ebook v%(__version__)s. ' print ('comic2ebook v%(__version__)s. '
'Written 2012 by Ciro Mattia Gonano.' % globals()) 'Written 2012 by Ciro Mattia Gonano.' % globals())
def Usage():
print "Generates HTML, NCX and OPF for a Comic ebook from a bunch of images"
print "Optimized for creating Mobipockets to be read into Kindle Paperwhite"
print "Usage:"
print " %s <profile> <dir> <title>" % sys.argv[0]
print " <title> is optional"
def main(argv=None):
if argv is None:
argv = sys.argv
profile = argv[1]
dir = argv[2]
cbx = cbxarchive.CBxArchive(dir)
if cbx.isCbxFile():
cbx.extract()
dir = cbx.getPath()
if len(argv)==4:
title = argv[3]
else:
title = "comic"
filelist = []
try:
print "Splitting double pages..."
for file in os.listdir(dir):
if (getImageFileName(file) != None):
img = image.ComicPage(dir+'/'+file, profile)
img.splitPage(dir)
for file in os.listdir(dir):
if (getImageFileName(file) != None):
print "Optimizing " + file + " for " + profile
img = image.ComicPage(dir+'/'+file, profile)
img.resizeImage()
#img.frameImage()
img.quantizeImage()
img.saveToDir(dir)
except ImportError:
print "Could not load PIL, not optimizing image"
for file in os.listdir(dir):
if (getImageFileName(file) != None and isInFilelist(file,filelist) == False):
# put credits at the end
if "credits" in file.lower():
os.rename(dir+'/'+file, dir+'/ZZZ999_'+file)
file = 'ZZZ999_'+file
filename = HTMLbuilder(dir,file).getResult()
if (filename != None):
filelist.append(filename)
NCXbuilder(dir,title)
# ensure we're sorting files alphabetically
filelist = sorted(filelist, key=lambda name: name[0])
OPFBuilder(dir,title,filelist)
if __name__ == "__main__":
Copyright()
if len(sys.argv)<3 or len(sys.argv)>4: if len(sys.argv)<3 or len(sys.argv)>4:
print "Generates HTML, NCX and OPF for a Comic ebook from a bunch of images" Usage()
print "Optimized for creating Mobipockets to be read into Kindle Paperwhite"
print "Usage:"
print " %s <profile> <dir> <title>" % sys.argv[0]
print " <title> is optional"
sys.exit(1) sys.exit(1)
else: else:
profile = sys.argv[1] main()
dir = sys.argv[2]
cbx = cbxarchive.CBxArchive(dir)
if cbx.isCbxFile():
cbx.extract()
dir = cbx.getPath()
if len(sys.argv)==4:
title = sys.argv[3]
else:
title = "comic"
filelist = []
try:
print "Splitting double pages..."
for file in os.listdir(dir):
if (getImageFileName(file) != None):
img = image.ComicPage(dir+'/'+file, profile)
img.splitPage(dir)
for file in os.listdir(dir):
if (getImageFileName(file) != None):
print "Optimizing " + file + " for " + profile
img = image.ComicPage(dir+'/'+file, profile)
img.resizeImage()
#img.frameImage()
img.quantizeImage()
img.saveToDir(dir)
except ImportError:
print "Could not load PIL, not optimizing image"
for file in os.listdir(dir):
if (getImageFileName(file) != None and isInFilelist(file,filelist) == False):
# put credits at the end
if "credits" in file.lower():
os.rename(dir+'/'+file, dir+'/ZZZ999_'+file)
file = 'ZZZ999_'+file
filename = HTMLbuilder(dir,file).getResult()
if (filename != None):
filelist.append(filename)
NCXbuilder(dir,title)
# ensure we're sorting files alphabetically
filelist = sorted(filelist, key=lambda name: name[0])
OPFBuilder(dir,title,filelist)
sys.exit(0) sys.exit(0)

View File

@@ -21,7 +21,7 @@ VERSION="1.2.0"
IDENTIFIER="com.github.ciromattia.kcc" IDENTIFIER="com.github.ciromattia.kcc"
EXENAME="KindleComicConverter" EXENAME="KindleComicConverter"
APP = ['kcc/comic2ebook.py'] APP = ['kcc.py']
DATA_FILES = [] DATA_FILES = []
OPTIONS = { 'argv_emulation': True, OPTIONS = { 'argv_emulation': True,
'iconfile': 'resources/comic2ebook.icns', 'iconfile': 'resources/comic2ebook.icns',
@@ -36,20 +36,10 @@ if sys.platform == 'darwin':
plist=dict( plist=dict(
CFBundleName = NAME, CFBundleName = NAME,
CFBundleShortVersionString = VERSION, CFBundleShortVersionString = VERSION,
CFBundleGetInfoString = NAME + " " + VERSION, CFBundleGetInfoString = NAME + " " + VERSION + ", written 2012 by Ciro Mattia Gonano",
CFBundleExecutable = EXENAME, CFBundleExecutable = EXENAME,
CFBundleIdentifier = IDENTIFIER, CFBundleIdentifier = IDENTIFIER,
CFBundleDocumentTypes = dict( CFBundleSignature = 'dplt'
CFBundleTypeExtensions=["zip","rar","cbz","cbr"],
CFBundleTypeName="Comics",
CFBundleTypeRole="Editor",
LSItemContentTypes = [
"public.plain-text",
"public.text",
"public.data",
"com.apple.application-bundle"
]
)
) )
) )
) )
@@ -69,5 +59,14 @@ setup(
name=NAME, name=NAME,
app=APP, app=APP,
data_files=DATA_FILES, data_files=DATA_FILES,
classifiers=[
# make sure to use :: Python *and* :: Python :: 3 so
# that pypi can list the package on the python 3 page
'Programming Language :: Python',
'Programming Language :: Python :: 3'
],
packages=['kcc'],
# make sure to add custom_fixers to the MANIFEST.in
include_package_data=True,
**extra_options **extra_options
) )