about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblue <[email protected]>2014-05-18 00:02:04 +0100
committerPaweł Jastrzębski <[email protected]>2014-05-29 18:28:14 +0200
commita722e5fa49983651004ad874e826e4c1aafd757f (patch)
treec7347ebb29d875e82396c27f6d3a50032d15e6b2
parentUpdated to Python 3.4 and PyQt 5.3 (close #94) (diff)
downloadkcc-a722e5fa49983651004ad874e826e4c1aafd757f.tar.gz
kcc-a722e5fa49983651004ad874e826e4c1aafd757f.tar.bz2
kcc-a722e5fa49983651004ad874e826e4c1aafd757f.zip
Split comic2ebook.py main in two
Now has main() which initialises program and makeBook which does the
actual work.
-rwxr-xr-xkcc/comic2ebook.py41
1 files changed, 32 insertions, 9 deletions
diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py
index f84382e..2140ba0 100755
--- a/kcc/comic2ebook.py
+++ b/kcc/comic2ebook.py
@@ -955,62 +955,85 @@ def main(argv=None, qtGUI=None):
     if len(args) != 1:
         parser.print_help()
         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...")
-    detectCorruption(os.path.join(path, "OEBPS", "Images"), args[0])
-    checkComicInfo(os.path.join(path, "OEBPS", "Images"), args[0])
+    detectCorruption(os.path.join(path, "OEBPS", "Images"), source)
+    checkComicInfo(os.path.join(path, "OEBPS", "Images"), source)
+
     if options.webtoon:
         if options.customheight > 0:
             comic2panel.main(['-y ' + str(options.customheight), '-i', '-m', path], qtGUI)
         else:
             comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', '-m', path], qtGUI)
+
     if options.imgproc:
         print("\nProcessing images...")
         if GUI:
             GUI.progressBarTick.emit('Processing images')
         dirImgProcess(os.path.join(path, "OEBPS", "Images"))
+
     if GUI:
         GUI.progressBarTick.emit('1')
+
     chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
+
     if options.batchsplit:
         tomes = preSplitDirectory(path)
     else:
         tomes = [path]
+
     filepath = []
     tomeNumber = 0
+
     if GUI:
         if options.cbzoutput:
             GUI.progressBarTick.emit('Compressing CBZ files')
         else:
-            GUI.progressBarTick.emit('Compressing EPUB files')
+            GUI.progressBarTick.emit('Compressing EPUgB files')
         GUI.progressBarTick.emit(str(len(tomes) + 1))
         GUI.progressBarTick.emit('tick')
+
     options.baseTitle = options.title
+
     for tome in tomes:
         if len(tomes) > 1:
             tomeNumber += 1
             options.title = options.baseTitle + ' [' + str(tomeNumber) + '/' + str(len(tomes)) + ']'
+
         if options.cbzoutput:
             # if CBZ output wanted, compress all images and return filepath
             print("\nCreating CBZ file...")
             if len(tomes) > 1:
-                filepath.append(getOutputFilename(args[0], options.output, '.cbz', ' ' + str(tomeNumber)))
+                filepath.append(getOutputFilename(source, options.output, '.cbz', ' ' + str(tomeNumber)))
             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"))
+
         else:
             print("\nCreating EPUB structure...")
             genEpubStruct(tome, chapterNames)
             # actually zip the ePub
             if len(tomes) > 1:
-                filepath.append(getOutputFilename(args[0], options.output, '.epub', ' ' + str(tomeNumber)))
+                filepath.append(getOutputFilename(source, options.output, '.epub', ' ' + str(tomeNumber)))
             else:
-                filepath.append(getOutputFilename(args[0], options.output, '.epub', ''))
+                filepath.append(getOutputFilename(source, options.output, '.epub', ''))
             makeZIP(tome + '_comic', tome, True)
+
         move(tome + '_comic.zip', filepath[-1])
         rmtree(tome, True)
+
         if GUI:
             GUI.progressBarTick.emit('tick')
+
     return filepath
 
 
@@ -1091,4 +1114,4 @@ def checkOptions():
                       (int(X*1.5), int(Y*1.5)))
         image.ProfileData.Profiles["Custom"] = newProfile
         options.profile = "Custom"
-    options.profileData = image.ProfileData.Profiles[options.profile]
\ No newline at end of file
+    options.profileData = image.ProfileData.Profiles[options.profile]