This repository has been archived by the owner on Oct 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from clach04/cli
cli support
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python2 | ||
"""python mangle-cli.py extracted_cbz_folder/* | ||
-d directory_name defaults to ./ | ||
-t title defaults 'Unknown' | ||
-o book.outputFormat defaults to 'CBZ only' | ||
NOTE order of arguments for image files is significant. | ||
Example: | ||
mkdir my_comic | ||
cd my_comic | ||
7z x /full/path/my/comic.cbz | ||
cd .. | ||
python mangle-cli.py -tmy_comic my_comic/* | ||
""" | ||
|
||
import shutil | ||
import sys | ||
import os | ||
import getopt | ||
|
||
import mangle.cbz | ||
import mangle.image | ||
from mangle.image import ImageFlags | ||
|
||
|
||
class FakeBook: | ||
device = 'Kindle 2/3/Touch' # See mangle/image.py KindleData.Profiles | ||
outputFormat = 'CBZ only' | ||
title = 'Unknown' | ||
imageFlags = ImageFlags.Orient | ImageFlags.Resize | ImageFlags.Quantize | ||
|
||
|
||
try: | ||
opts, args = getopt.getopt(sys.argv[1:], 'd:t:o:') | ||
except getopt.GetoptError, err: | ||
print(str(err)) | ||
sys.exit(2) | ||
|
||
directory = '.' | ||
|
||
book = FakeBook() | ||
book.device = 'Kindle 2/3/Touch' | ||
#book.device = 'Kindle Paperwhite 1 & 2' | ||
book.outputFormat = 'CBZ only' | ||
book.title = 'Unknown' | ||
|
||
|
||
for o,a in opts: | ||
if o == '-d': | ||
directory = a | ||
elif o == '-t': | ||
book.title = a | ||
elif o == '-o': | ||
book.outputFormat = a | ||
|
||
|
||
bookPath = os.path.join(directory, book.title) | ||
|
||
archive = mangle.cbz.Archive(bookPath) | ||
|
||
if not os.path.isdir(bookPath): | ||
os.makedirs(bookPath) | ||
|
||
|
||
for index in range(0, len(args)): | ||
target = os.path.join(bookPath, '%05d.png' % index) # FIXME preserve original; format and name? | ||
|
||
print(index, args[index], target) # cheap display progress | ||
mangle.image.convertImage(args[index], target, str(book.device), book.imageFlags) | ||
archive.addFile(target); | ||
|
||
|
||
if 'Image' not in book.outputFormat: | ||
shutil.rmtree(bookPath) | ||
|
||
archive.close() | ||
|