about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <you@example.com>2022-02-08 16:54:24 +0000
committerBaitinq <you@example.com>2022-02-08 17:24:34 +0000
commite9d82cc0efb90200e199c9982d80cf5940257a31 (patch)
treeffad770e90dfff76875c54080817cb736903cff1
parentAdd profile for Kindle PW5/Signature (diff)
downloadkcc-e9d82cc0efb90200e199c9982d80cf5940257a31.tar.gz
kcc-e9d82cc0efb90200e199c9982d80cf5940257a31.tar.bz2
kcc-e9d82cc0efb90200e199c9982d80cf5940257a31.zip
Add outputMerge option (removed outputSplit) kindle_signature
-rw-r--r--gui/KCC.ui10
-rw-r--r--kindlecomicconverter/KCC_gui.py33
-rw-r--r--kindlecomicconverter/KCC_ui.py18
-rwxr-xr-xkindlecomicconverter/image.py2
4 files changed, 57 insertions, 6 deletions
diff --git a/gui/KCC.ui b/gui/KCC.ui
index 09a7b92..86d76de 100644
--- a/gui/KCC.ui
+++ b/gui/KCC.ui
@@ -231,6 +231,7 @@
         </widget>
        </item>
        <item row="2" column="1">
+       <!-- 
         <widget class="QCheckBox" name="outputSplit">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p style='white-space:pre'&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Unchecked - Automatic mode&lt;br/&gt;&lt;/span&gt;The output will be split automatically.&lt;/p&gt;&lt;p style='white-space:pre'&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Checked - Volume mode&lt;br/&gt;&lt;/span&gt;Every subdirectory will be considered as a separate volume.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -239,6 +240,15 @@
           <string>Output split</string>
          </property>
         </widget>
+        -->
+        <widget class="QCheckBox" name="outputJoin">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p style='white-space:pre'&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Unchecked - Automatic mode&lt;br/&gt;&lt;/span&gt;The output will be split automatically.&lt;/p&gt;&lt;p style='white-space:pre'&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Checked - Volume mode&lt;br/&gt;&lt;/span&gt;Every subdirectory will be considered as a separate volume.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="text">
+          <string>Output Join</string>
+         </property>
+        </widget>
        </item>
        <item row="2" column="2">
         <widget class="QCheckBox" name="colorBox">
diff --git a/kindlecomicconverter/KCC_gui.py b/kindlecomicconverter/KCC_gui.py
index 56b00c5..fb10853 100644
--- a/kindlecomicconverter/KCC_gui.py
+++ b/kindlecomicconverter/KCC_gui.py
@@ -286,6 +286,39 @@ class WorkerThread(QtCore.QThread):
             if GUI.jobList.item(i).icon().isNull():
                 currentJobs.append(str(GUI.jobList.item(i).text()))
         GUI.jobList.clear()
+
+        #NEEDS TO BE CBR FILENAME (SO IT CAN BE EXTRACTED)
+        if GUI.outputMerge.isChecked():
+            import zipfile
+            from tempfile import TemporaryDirectory
+
+            MW.addMessage.emit('Merging all files...', 'info', False)
+            GUI.progress.content = 'Merging all files'
+            
+            zf = zipfile.ZipFile(currentJobs[0].split('.', 1)[0] + "-MERGED.cbz", "w")
+
+            #we should join cbz before converting
+            with TemporaryDirectory('', 'KCC-') as workdir:
+                for job in currentJobs:
+
+                    #unzip all in tmp folder
+                    name = os.path.splitext(os.path.basename(job))[0]
+                    extracted_dir = workdir + "/" + name
+
+                    with zipfile.ZipFile(job, 'r') as zip_ref:
+                        zip_ref.extractall(extracted_dir)
+
+                    for dirname, subdirs, files in os.walk(extracted_dir):
+                        for filename in files:
+                            p = os.path.join(dirname, filename)
+                            arcname = os.path.relpath(p, start=workdir)
+                            zf.write(p, arcname=arcname)#change arcname to remove tmp folder (relative path)
+            zf.close()
+
+            currentJobs = [zf.filename]
+
+            GUI.progress.content = ''
+
         for job in currentJobs:
             sleep(0.5)
             if not self.conversionAlive:
diff --git a/kindlecomicconverter/KCC_ui.py b/kindlecomicconverter/KCC_ui.py
index b70f3ef..0a60c17 100644
--- a/kindlecomicconverter/KCC_ui.py
+++ b/kindlecomicconverter/KCC_ui.py
@@ -100,7 +100,11 @@ class Ui_mainWindow(object):
         self.gridLayout_2.addWidget(self.borderBox, 2, 0, 1, 1)
         self.outputSplit = QtWidgets.QCheckBox(self.optionWidget)
         self.outputSplit.setObjectName("outputSplit")
-        self.gridLayout_2.addWidget(self.outputSplit, 2, 1, 1, 1)
+        self.outputSplit.hide()
+        #self.gridLayout_2.addWidget(self.outputSplit, 2, 1, 1, 1)
+        self.outputMerge = QtWidgets.QCheckBox(self.optionWidget)
+        self.outputMerge.setObjectName("outputMerge")
+        self.gridLayout_2.addWidget(self.outputMerge, 2, 1, 1, 1)
         self.colorBox = QtWidgets.QCheckBox(self.optionWidget)
         self.colorBox.setObjectName("colorBox")
         self.gridLayout_2.addWidget(self.colorBox, 2, 2, 1, 1)
@@ -220,8 +224,10 @@ class Ui_mainWindow(object):
         mainWindow.setTabOrder(self.webtoonBox, self.upscaleBox)
         mainWindow.setTabOrder(self.upscaleBox, self.gammaBox)
         mainWindow.setTabOrder(self.gammaBox, self.borderBox)
-        mainWindow.setTabOrder(self.borderBox, self.outputSplit)
-        mainWindow.setTabOrder(self.outputSplit, self.colorBox)
+        #mainWindow.setTabOrder(self.borderBox, self.outputSplit)
+        #mainWindow.setTabOrder(self.outputSplit, self.colorBox)
+        mainWindow.setTabOrder(self.borderBox, self.outputMerge)
+        mainWindow.setTabOrder(self.outputMerge, self.colorBox)
         mainWindow.setTabOrder(self.colorBox, self.editorButton)
         mainWindow.setTabOrder(self.editorButton, self.wikiButton)
         mainWindow.setTabOrder(self.wikiButton, self.jobList)
@@ -252,8 +258,10 @@ class Ui_mainWindow(object):
         self.gammaBox.setText(_translate("mainWindow", "Custom gamma"))
         self.borderBox.setToolTip(_translate("mainWindow", "<html><head/><body><p><span style=\" font-weight:600; text-decoration: underline;\">Unchecked - Autodetection<br/></span>The color of margins fill will be detected automatically.</p><p><span style=\" font-weight:600; text-decoration: underline;\">Indeterminate - White<br/></span>Margins will be filled with white color.</p><p><span style=\" font-weight:600; text-decoration: underline;\">Checked - Black<br/></span>Margins will be filled with black color.</p></body></html>"))
         self.borderBox.setText(_translate("mainWindow", "W/B margins"))
-        self.outputSplit.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'><span style=\" font-weight:600; text-decoration: underline;\">Unchecked - Automatic mode<br/></span>The output will be split automatically.</p><p style=\'white-space:pre\'><span style=\" font-weight:600; text-decoration: underline;\">Checked - Volume mode<br/></span>Every subdirectory will be considered as a separate volume.</p></body></html>"))
-        self.outputSplit.setText(_translate("mainWindow", "Output split"))
+        #self.outputSplit.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'><span style=\" font-weight:600; text-decoration: underline;\">Unchecked - Automatic mode<br/></span>The output will be split automatically.</p><p style=\'white-space:pre\'><span style=\" font-weight:600; text-decoration: underline;\">Checked - Volume mode<br/></span>Every subdirectory will be considered as a separate volume.</p></body></html>"))
+        #self.outputSplit.setText(_translate("mainWindow", "Output split"))
+        self.outputMerge.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'><span style=\" font-weight:600; text-decoration: underline;\">Unchecked - Automatic mode<br/></span>The output will be split automatically.</p><p style=\'white-space:pre\'><span style=\" font-weight:600; text-decoration: underline;\">Checked - Volume mode<br/></span>Every subdirectory will be considered as a separate volume.</p></body></html>"))
+        self.outputMerge.setText(_translate("mainWindow", "Output Merge"))
         self.colorBox.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Disable conversion to grayscale.</p></body></html>"))
         self.colorBox.setText(_translate("mainWindow", "Color mode"))
         self.gammaLabel.setText(_translate("mainWindow", "Gamma: Auto"))
diff --git a/kindlecomicconverter/image.py b/kindlecomicconverter/image.py
index 2bcee16..a627941 100755
--- a/kindlecomicconverter/image.py
+++ b/kindlecomicconverter/image.py
@@ -258,7 +258,7 @@ class ComicPage:
         if gamma == 1.0:
             self.image = ImageOps.autocontrast(self.image)
         else:
-            self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: 255 * (a / 255.) ** gamma))
+            self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: int(255 * (a / 255.) ** gamma)))
 
     def quantizeImage(self):
         colors = len(self.palette) // 3