Compare commits

...
36 Commits
Author SHA1 Message Date
Alex Xu 4cdbb4beef bump to 11.0.3 2026-08-28 14:52:42 -07:00
Alex Xu 2c9056c524 label spread preview default is high quality (#1429) 2026-08-28 14:46:18 -07:00
Alex Xu a503f54f9f Spread labels support left to right (#1428) 2026-08-28 14:38:22 -07:00
Alex Xu fc331d4e19 bump to 11.0.2 2026-08-26 13:05:44 -07:00
Alex Xu adac558aab shift click label spreads for HQ preview (#1427) 2026-08-26 13:05:14 -07:00
Alex Xu c8cf50da0a fix spread label when it's the first page (#1426) 2026-08-26 11:40:25 -07:00
Alex Xu f38f1c45b2 update README.md 2026-08-26 09:25:07 -07:00
Alex Xu bd0328a12f bump to 11.0.1 2026-08-02 10:47:25 -07:00
Alex Xu 846a755761 fix label feature on Windows (#1413) 2026-08-01 15:58:45 -07:00
Alex Xu ff80d275e6 bump to 11.0.0 2026-07-31 22:26:11 -07:00
Alex Xu b3e1d393b6 Manually label spreads button (#1412)
* initial commit

* initial commit 2

* json it

* UI labels

* basics

* add todo

* options to getWorkFolder

* refactor options

* refactor UI

* cleanup

* pdf fixed size

* remove comment

* finalized json creation

* fix help text

* finalized

* remove print

* add youtube
2026-07-31 22:25:41 -07:00
Alex Xu b4c71b3b91 pass options to slugify (#1411) 2026-07-29 17:06:52 -07:00
Alex Xu 7e412f12ae pass options to getWorkFolder (#1410) 2026-07-29 16:41:34 -07:00
Nils Leo 2076775d94 Create the destination dir before flattening a single-subfolder archive (#1405) 2026-07-23 22:43:16 -07:00
Alex Xu 59df22b62d add sort order note to readme 2026-07-20 15:06:12 -07:00
Alex Xu ff5edc5ce5 fix: Destination path... already exists (#1404) 2026-07-20 14:21:42 -07:00
Alex Xu a52c0ce03a Merge pull request #1394 from ciromattia/axu2-patch-1
Clarify Kobo profile + EPUB -> KEPUB
2026-07-10 18:42:03 -07:00
Alex Xu 1c0506fe7d Clarify Kobo profile + EPUB -> KEPUB 2026-07-10 18:41:48 -07:00
Alex Xu 806c6232c3 bump to 10.4.0 2026-07-10 18:39:41 -07:00
Alex Xu 6f9f5067d8 Merge pull request #1384 from drshliapa/fix/912-preserve-comicinfo
add Keep ComicInfo.xml in CBZ output option
2026-07-10 18:38:05 -07:00
Alex Xu 11be0dffcc make it an option 2026-07-10 18:32:44 -07:00
Alex Xu 4c10569ab1 millisecond timestamp kindlegen log (#1393) 2026-07-10 17:47:34 -07:00
Alex Xu 2a5cd6718d new user first startup: default is Paperwhite 12th Gen, split and rotate, RTL (#1392) 2026-07-10 14:48:48 -07:00
Alex Xu fd1468904f stop webtoon unchecking automatically check customm autocontrast (#1391) 2026-07-10 14:26:41 -07:00
Alex Xu feec40ffc8 more detailed kindlegen warnings (#1390)
* show kindlegen warnings and errors

* show kindlegen warnings

* dump kindlegen logs to txt

* move warnings to end

* don't show webtoon cover warning

* fix typo

* add timestamp to kindlegen log dump

* double enter

* add TODO

* add more TODO

* fix comment

* final clean up
2026-07-10 13:57:20 -07:00
Marian Leontiev f6ae7661bc fix macOS app version showing 0.0.0 in Info.plist (#1385) 2026-07-09 15:25:42 -07:00
Alex Xu ca14a4c813 don't crash on empty nested folders (#1388) 2026-07-08 17:46:46 -07:00
Alex Xu 0c1071a358 fix Access is denied with read only input folder (2013 bug) (#1387)
* fix Access is denied on read only input folders

* minimize changes
2026-07-08 17:22:23 -07:00
Alex Xu 858251f509 show entire kindlegen error (#1386) 2026-07-07 10:02:26 -07:00
Marian Leontiev 3c66aa9a67 preserve ComicInfo.xml in CBZ output for Other profile 2026-07-05 21:07:26 +02:00
Aldijonas 077957e665 Rename 'cover.jpg' file to '##cover.jpg' (#1383) 2026-07-05 07:34:26 -07:00
Aldijonas c3f86e29c8 Rename cover.jpg to !cover.jpg in CBZ (#1381)
Change cover image filename from 'cover.jpg' to '!cover.jpg' in line 1907 for correct cover display when using CBZ file format
2026-07-02 16:41:37 -07:00
Nils Leo 72e1546c2c fix: enable unrar on all distros, not just Fedora (#1376)
* fix: enable unrar on all distros, not just Fedora

unrar was gated behind distro.id() == 'fedora', so on Debian/Ubuntu
the binary was installed but never invoked. Try unrar unconditionally
after 7z, with an optional rarfile Python fallback.

Fixes CBR extraction on non-Fedora Linux distributions.

* fix: gate unrar on Linux and drop unused distro dependency

Debian/Ubuntu's '7zip' package ships the upstream 7zz binary, which
excludes RAR support for licensing reasons, so 7z fails to read .cbr
(RAR) archives. unrar was installed but only invoked when
distro.id() == 'fedora', so on Debian it was never tried and extraction
failed.

Per maintainer feedback, gate unrar on platform.system() == 'Linux'
(not needed on Windows or macOS) and drop the rarfile PyPI fallback to
avoid a new dependency. Since the code no longer imports distro, also
remove it from the requirements files and setup.py.
2026-07-02 15:07:36 -07:00
sa-mi 544e866b51 fix crash in smart cover crop for landscape covers (#1379) 2026-07-01 21:30:08 -07:00
Alex Xu 363a36a764 reduce job list minimum height from 150 to 110 pixels (#1378) 2026-07-01 17:34:17 -07:00
Alex Xu bece5290a3 remove 2nd row of buttons (#1377) 2026-06-29 17:17:41 -07:00
23 changed files with 1912 additions and 1575 deletions
+65 -32
View File
@@ -1,4 +1,8 @@
<img src="header.jpg" alt="Header Image" width="400">
Most manga conversion methods for ereaders add margins. But KCC enables true fullscreen from top to bottom.
![header](images/header_margins.jpeg)
(feat. Ya Boy Kongming! and Fire Force from a [Humble Bundle](https://humblebundleinc.sjv.io/xL6Zv1) PDF source.)
# KCC
@@ -11,53 +15,77 @@
like Kindle, Kobo, ReMarkable, and more.
Pages display in fullscreen without margins,
with proper fixed layout support.
Supported input formats include JPG/PNG image files in folders, archives like CBZ, or PDFs.
Supported output formats include MOBI/AZW3, EPUB, KEPUB, CBZ, and PDF.
KCC runs on Windows, macOS, and Linux.
Supported input formats include JPG/PNG image files in folders, archives like CBZ/EPUB, or PDF.
Supported output formats include MOBI/AZW3, EPUB, KEPUB, CBZ, and PDF.
The absolute highest quality source files are DRM-free PDFs from [Humble Bundle](https://humblebundleinc.sjv.io/xL6Zv1)/Fanatical.
The PDFs are often x12000 resolution or better, while even the 10" Kindle Scribe is only x2480.
KCC's main goal is maximum image quality at significantly smaller file size. For example, KCC
1) can compress a 600 MB manga volume from Humble Bundle to 100 MB.
This is mostly accomplished by downscaling to the native resolution of your specific device.
This can also improve battery life, page turn speed, and general performance
on underpowered ereaders with small memory and storage capacities.
2) fixes black levels to avoid gray/faded blacks found in many Kindle Store manga
![black](images/black.jpeg)
3) fixes [the rainbow effect on Kaleido 3 color eink](https://www.youtube.com/watch?v=Dw2HTJCGMhw) without blur:
![rainbow](images/rainbow2.jpeg)
4) can [semi-automatically detect 2-page spreads](https://www.youtube.com/watch?v=kfIX67f7Aqk) from pre-split single pages:
![before](images/spreadbefore3.jpeg)
You can view combined spreads either rotated or not:
![full](images/full.jpeg)
You can view the split halves either before or after combined spreads:
![half](images/half.jpeg)
## Demo
Just drop your input files into the KCC window, hit convert, and USB drop the output files onto your device's `documents` folder!
https://github.com/user-attachments/assets/da73d625-e082-482d-91a4-ae4765e96fd7
**WARNING**: Kindle Scribe 2025 support may not be possible. Does not work well currently.
Then all your usb loaded comic files will show up next to all your normal books in your ereader library!
**NEW**: PDF output is now supported for direct conversion to reMarkable devices!
When using a reMarkable profile (Rmk1, Rmk2, RmkPP), the format automatically defaults to PDF
for optimal compatibility with your device's native PDF reader.
The final result looks incredible on my 10" Kindle Scribe: https://www.youtube.com/watch?v=2CIHW2N9Enc
The absolute highest quality source files are print quality DRM-free PDFs from Kodansha/[Humble Bundle](https://humblebundleinc.sjv.io/xL6Zv1)/Fanatical,
which can be directly converted by KCC.
**WARNING**: Kindle Scribe 2025 MOBI support may have blank pages. Use PDF instead.
Its main feature is various optional image processing steps to look good on eink screens,
which have different requirements than normal LCD screens.
Combining that with downscaling to your specific device's screen resolution
can result in filesize reductions of hundreds of MB per volume with no visible quality loss on eink.
This can also improve battery life, page turn speed, and general performance
on underpowered ereaders with small memory and storage capacities.
The GUI looks like this, built in Qt6.
There are a lot of options, but most people only care about the ones checked below.
Hover over each option to see details in a tooltip.
KCC avoids many common formatting issues (some of which occur [even on the Kindle Store](https://github.com/ciromattia/kcc/wiki/Kindle-Store-bad-formatting)), such as:
1) faded black levels causing unneccessarily low contrast, which is hard to see and can cause eyestrain.
2) unneccessary margins at the bottom of the screen
3) Not utilizing the full 1860x2480 resolution of the 10" Kindle Scribe
4) incorrect page turn direction for manga that's read right to left
5) unaligned two page spreads in landscape, where pages are shifted over by 1
6) Removing without blur the rainbow effect on color eink Kaleido 3 due to manga screentones
![settings](images/settings.png)
The GUI looks like this, built in Qt6, with my most commonly used settings:
![image](https://github.com/user-attachments/assets/36ad2131-6677-4559-bd6f-314a90c27218)
Simply drag and drop your files/folders into the KCC window,
adjust your settings (hover over each option to see details in a tooltip),
and hit convert to create ereader optimized files.
You can change the default output directory by holding `Shift` while clicking the convert button.
Then just drag and drop the generated output files onto your device's documents folder via USB.
If you are on macOS and use a 2022+ Kindle, you may need to use Amazon USB File Manager for Mac.
If you are on macOS and use a 2022+ Kindle, you may need to use Amazon USB File Manager for Mac or OpenMTP.
YouTube tutorial (please subscribe): https://www.youtube.com/watch?v=QQ6zJcMF2Iw
Installation tutorial: https://www.youtube.com/watch?v=IR2Fhcm9658
## Kindle Jailbreak for KOreader
Jailbreaking to use KOreader is optional. KCC works just fine with the native mobi manga viewer.
But if you jailbreak your Kindle, you'll unlock additional features like:
1) compatibility with image formats better suited for manga like 4-bit PNG and WEBP. This enables better quality at **half the file size** compared to JPG which must be 8-bit.
This is visually lossless since eink screens are 4-bit.
2) no dependency on kindlegen, which can mean **twice as fast conversions** since you can convert to CBZ directly.
3) You can dither by partially checking the JPG/PNG box and can crop in KCC instead of KOreader. This may increase page turn speed and battery.
### A word of warning
**KCC** _is not_ [Amazon's Kindle Comic Creator](http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1001103761) nor is in any way endorsed by Amazon.
Amazon's tool is for comic publishers and involves a lot of manual effort, while **KCC** is for comic/manga readers.
@@ -123,6 +151,8 @@ For flatpak, Docker, and AppImage versions, refer to the wiki: https://github.co
Going back a few pages and exiting and re-entering book should fix it temporarily.
- What output format should I use?
- MOBI for Kindles. CBZ for Kindle DX. CBZ for Koreader. KEPUB for Kobo. PDF for ReMarkable or Kindle Scribe 2025.
- Where is KEPUB option?
- Choosing a Kobo profile and EPUB output will output KEPUB.
- All options have additional information in tooltips if you hover over the option.
- To get the converted book onto your Kindle/Kobo, just drag and drop the mobi/kepub into the documents folder on your Kindle/Kobo via USB
- Kindle panel view not working?
@@ -145,6 +175,8 @@ You'll need to install various tools to access important but optional features.
### KindleGen
(This is not needed for Koreader users on jailbroken Kindle. Just set output to CBZ instead.)
On Windows and macOS, install [Kindle Previewer](https://www.amazon.com/Kindle-Previewer/b?ie=UTF8&node=21381691011) and `kindlegen` will be autodetected from it.
If you have issues detecting it, get stuck on the MOBI conversion step, or use Linux AppImage or Flatpak, refer to the wiki: https://github.com/ciromattia/kcc/wiki/Installation#kindlegen
@@ -293,6 +325,7 @@ OUTPUT SETTINGS:
-t TITLE, --title TITLE
Comic title [Default=filename or directory name]
--metadatatitle Write title using ComicInfo.xml or other embedded metadata. 0: Don't use Title from metadata 1: Combine Title with default schema 2: Use Title only [Default=0]
--keepcomicinfo Keep any original ComicInfo.xml files [Default=0]
-a AUTHOR, --author AUTHOR
Author name [Default=KCC]
--language EPUB language [Default=en-US]
+727 -743
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 351 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 367 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 438 KiB

View File

Before

Width:  |  Height:  |  Size: 921 KiB

After

Width:  |  Height:  |  Size: 921 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 KiB

+61
View File
@@ -0,0 +1,61 @@
# -*- mode: python ; coding: utf-8 -*-
# macOS GUI build, used by setup.py build_binary
import sys
sys.path.insert(0, SPECPATH)
from kindlecomicconverter import __version__
a = Analysis(
['kcc.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=['_cffi_backend'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='Kindle Comic Converter',
debug=False,
bootloader_ignore_signals=False,
strip=True,
upx=True,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['icons/comic2ebook.icns'],
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=True,
upx=True,
upx_exclude=[],
name='Kindle Comic Converter',
)
app = BUNDLE(
coll,
name='Kindle Comic Converter.app',
icon='icons/comic2ebook.icns',
bundle_identifier=None,
info_plist={
'CFBundleShortVersionString': __version__,
'CFBundleVersion': __version__,
},
)
+235 -141
View File
@@ -19,10 +19,11 @@
from datetime import datetime, timezone
import itertools
import json
from pathlib import Path
from PySide6.QtCore import (QSize, QUrl, Qt, Signal, QIODeviceBase, QEvent, QThread, QSettings)
from PySide6.QtGui import (QColor, QIcon, QPixmap, QDesktopServices)
from PySide6.QtWidgets import (QApplication, QLabel, QListWidgetItem, QMainWindow, QSystemTrayIcon, QFileDialog, QMessageBox, QDialog, QAbstractItemView, QListView, QTreeView)
from PySide6.QtGui import (QColor, QIcon, QImage, QKeyEvent, QPixmap, QDesktopServices)
from PySide6.QtWidgets import (QApplication, QDialogButtonBox, QHBoxLayout, QLabel, QListWidgetItem, QMainWindow, QSizePolicy, QSystemTrayIcon, QFileDialog, QMessageBox, QDialog, QAbstractItemView, QListView, QTreeView, QWidget)
from PySide6.QtNetwork import (QLocalSocket, QLocalServer)
import os
@@ -38,10 +39,15 @@ from xml.sax.saxutils import escape
from psutil import Process
from copy import copy
from packaging.version import Version
from tempfile import gettempdir
from tempfile import gettempdir, mkdtemp
from PIL import Image
from PIL.Image import Dither
from .KCC_spread_label import LabelSpreadsDialog
from .shared import HTMLStripper, sanitizeTrace, walkLevel, subprocess_run
from .comicarchive import SEVENZIP, TAR, available_archive_tools
from .comic2ebook import OS_SORT_KEY, flattenTree, getWorkFolder, removeNonImages, sanitizeTree
from . import __version__
from . import comic2ebook
from . import metadata
@@ -234,6 +240,138 @@ class ProgressThread(QThread):
self.running = False
def get_options():
parser = comic2ebook.makeParser()
options = parser.parse_args()
options.profile = GUI.profiles[str(GUI.deviceBox.currentText())]['Label']
gui_current_format = GUI.formats[str(GUI.formatBox.currentText())]['format']
options.format = gui_current_format
if GUI.mangaBox.isChecked():
options.righttoleft = True
if GUI.lightnovelBox.isChecked():
options.lightnovel = True
if GUI.ebokBox.isChecked():
options.ebok = True
if GUI.invertDirectionBox.isChecked():
options.invertdirection = True
if GUI.rotateBox.checkState() == Qt.CheckState.PartiallyChecked:
options.splitter = 2
elif GUI.rotateBox.checkState() == Qt.CheckState.Checked:
options.splitter = 1
if GUI.qualityBox.checkState() == Qt.CheckState.PartiallyChecked:
options.autoscale = True
elif GUI.qualityBox.checkState() == Qt.CheckState.Checked:
options.hq = True
if GUI.vertical4PanelBox.isChecked():
options.vertical4panel = True
if GUI.webtoonBox.isChecked():
options.webtoon = True
if GUI.upscaleBox.checkState() == Qt.CheckState.PartiallyChecked:
options.stretch = True
elif GUI.upscaleBox.checkState() == Qt.CheckState.Checked:
options.upscale = True
if GUI.gammaBox.isChecked() and float(GUI.gammaValue) > 0.09:
options.gamma = float(GUI.gammaValue)
if GUI.autoLevelBox.isChecked():
options.autolevel = True
if GUI.autocontrastBox.checkState() == Qt.CheckState.PartiallyChecked:
options.noautocontrast = True
elif GUI.autocontrastBox.checkState() == Qt.CheckState.Checked:
options.colorautocontrast = True
if GUI.croppingBox.isChecked():
if GUI.croppingBox.checkState() == Qt.CheckState.PartiallyChecked:
options.cropping = 1
else:
options.cropping = 2
else:
options.cropping = 0
if GUI.croppingBox.checkState() != Qt.CheckState.Unchecked:
options.croppingp = float(GUI.croppingPowerValue)
options.preservemargin = GUI.preserveMarginBox.value()
if GUI.interPanelCropBox.isChecked():
if GUI.interPanelCropBox.checkState() == Qt.CheckState.PartiallyChecked:
options.interpanelcrop = 1
else:
options.interpanelcrop = 2
else:
options.interpanelcrop = 0
if GUI.borderBox.checkState() == Qt.CheckState.PartiallyChecked:
options.white_borders = True
elif GUI.borderBox.checkState() == Qt.CheckState.Checked:
options.black_borders = True
if GUI.outputSplit.isChecked():
options.batchsplit = 2
if GUI.colorBox.isChecked():
options.forcecolor = True
if GUI.eraseRainbowBox.isChecked():
options.eraserainbow = True
if GUI.maximizeStrips.isChecked():
options.maximizestrips = True
if GUI.disableProcessingBox.isChecked():
options.noprocessing = True
if GUI.legacyExtractBox.isChecked():
options.legacyextract = True
if GUI.pdfWidthBox.isChecked():
options.pdfwidth = True
if GUI.smartCoverCropBox.isChecked():
options.smartcovercrop = True
if GUI.coverFillBox.isChecked():
options.coverfill = True
if GUI.metadataTitleBox.checkState() == Qt.CheckState.PartiallyChecked:
options.metadatatitle = 1
elif GUI.metadataTitleBox.checkState() == Qt.CheckState.Checked:
options.metadatatitle = 2
if GUI.keepComicInfoBox.isChecked():
options.keepcomicinfo = True
if GUI.deleteBox.isChecked():
options.delete = True
if GUI.tempDirBox.isChecked():
options.tempdir = True
if GUI.spreadShiftBox.isChecked():
options.spreadshift = True
if GUI.onePageLandscapeBox.isChecked():
options.onepagelandscape = True
if GUI.fileFusionBox.isChecked():
options.filefusion = True
else:
options.filefusion = False
if GUI.noRotateBox.isChecked():
options.norotate = True
if GUI.rotateRightBox.isChecked():
options.rotateright = True
if GUI.rotateFirstBox.isChecked():
options.rotatefirst = True
if GUI.forcePngRgbBox.isChecked():
options.force_png_rgb = True
if GUI.mozJpegBox.checkState() == Qt.CheckState.PartiallyChecked:
options.forcepng = True
elif GUI.mozJpegBox.checkState() == Qt.CheckState.Checked:
options.mozjpeg = True
if GUI.webpBox.isChecked():
options.webp = True
if GUI.pngLegacyBox.isChecked():
options.pnglegacy = True
if GUI.noQuantizeBox.isChecked():
options.noquantize = True
if GUI.jpegQualityBox.isChecked():
options.jpegquality = GUI.jpegQualitySpinBox.value()
if GUI.currentMode > 2:
options.customwidth = str(GUI.widthBox.value())
options.customheight = str(GUI.heightBox.value())
if GUI.targetDirectory != '':
options.output = GUI.targetDirectory
if GUI.titleEdit.text():
options.title = str(GUI.titleEdit.text())
if GUI.authorEdit.text():
options.author = str(GUI.authorEdit.text())
if GUI.languageEdit.text():
options.language = str(GUI.languageEdit.text())
if GUI.chunkSizeCheckBox.isChecked():
options.targetsize = int(GUI.chunkSizeBox.value())
return options, gui_current_format
class WorkerThread(QThread):
def __init__(self):
QThread.__init__(self)
@@ -263,134 +401,9 @@ class WorkerThread(QThread):
def run(self):
MW.modeConvert.emit(0)
parser = comic2ebook.makeParser()
options = parser.parse_args()
argv = ''
currentJobs = []
options.profile = GUI.profiles[str(GUI.deviceBox.currentText())]['Label']
gui_current_format = GUI.formats[str(GUI.formatBox.currentText())]['format']
options.format = gui_current_format
if GUI.mangaBox.isChecked():
options.righttoleft = True
if GUI.lightnovelBox.isChecked():
options.lightnovel = True
if GUI.ebokBox.isChecked():
options.ebok = True
if GUI.invertDirectionBox.isChecked():
options.invertdirection = True
if GUI.rotateBox.checkState() == Qt.CheckState.PartiallyChecked:
options.splitter = 2
elif GUI.rotateBox.checkState() == Qt.CheckState.Checked:
options.splitter = 1
if GUI.qualityBox.checkState() == Qt.CheckState.PartiallyChecked:
options.autoscale = True
elif GUI.qualityBox.checkState() == Qt.CheckState.Checked:
options.hq = True
if GUI.vertical4PanelBox.isChecked():
options.vertical4panel = True
if GUI.webtoonBox.isChecked():
options.webtoon = True
if GUI.upscaleBox.checkState() == Qt.CheckState.PartiallyChecked:
options.stretch = True
elif GUI.upscaleBox.checkState() == Qt.CheckState.Checked:
options.upscale = True
if GUI.gammaBox.isChecked() and float(GUI.gammaValue) > 0.09:
options.gamma = float(GUI.gammaValue)
if GUI.autoLevelBox.isChecked():
options.autolevel = True
if GUI.autocontrastBox.checkState() == Qt.CheckState.PartiallyChecked:
options.noautocontrast = True
elif GUI.autocontrastBox.checkState() == Qt.CheckState.Checked:
options.colorautocontrast = True
if GUI.croppingBox.isChecked():
if GUI.croppingBox.checkState() == Qt.CheckState.PartiallyChecked:
options.cropping = 1
else:
options.cropping = 2
else:
options.cropping = 0
if GUI.croppingBox.checkState() != Qt.CheckState.Unchecked:
options.croppingp = float(GUI.croppingPowerValue)
options.preservemargin = GUI.preserveMarginBox.value()
if GUI.interPanelCropBox.isChecked():
if GUI.interPanelCropBox.checkState() == Qt.CheckState.PartiallyChecked:
options.interpanelcrop = 1
else:
options.interpanelcrop = 2
else:
options.interpanelcrop = 0
if GUI.borderBox.checkState() == Qt.CheckState.PartiallyChecked:
options.white_borders = True
elif GUI.borderBox.checkState() == Qt.CheckState.Checked:
options.black_borders = True
if GUI.outputSplit.isChecked():
options.batchsplit = 2
if GUI.colorBox.isChecked():
options.forcecolor = True
if GUI.eraseRainbowBox.isChecked():
options.eraserainbow = True
if GUI.maximizeStrips.isChecked():
options.maximizestrips = True
if GUI.disableProcessingBox.isChecked():
options.noprocessing = True
if GUI.legacyExtractBox.isChecked():
options.legacyextract = True
if GUI.pdfWidthBox.isChecked():
options.pdfwidth = True
if GUI.smartCoverCropBox.isChecked():
options.smartcovercrop = True
if GUI.coverFillBox.isChecked():
options.coverfill = True
if GUI.metadataTitleBox.checkState() == Qt.CheckState.PartiallyChecked:
options.metadatatitle = 1
elif GUI.metadataTitleBox.checkState() == Qt.CheckState.Checked:
options.metadatatitle = 2
if GUI.deleteBox.isChecked():
options.delete = True
if GUI.tempDirBox.isChecked():
options.tempdir = True
if GUI.spreadShiftBox.isChecked():
options.spreadshift = True
if GUI.onePageLandscapeBox.isChecked():
options.onepagelandscape = True
if GUI.fileFusionBox.isChecked():
options.filefusion = True
else:
options.filefusion = False
if GUI.noRotateBox.isChecked():
options.norotate = True
if GUI.rotateRightBox.isChecked():
options.rotateright = True
if GUI.rotateFirstBox.isChecked():
options.rotatefirst = True
if GUI.forcePngRgbBox.isChecked():
options.force_png_rgb = True
if GUI.mozJpegBox.checkState() == Qt.CheckState.PartiallyChecked:
options.forcepng = True
elif GUI.mozJpegBox.checkState() == Qt.CheckState.Checked:
options.mozjpeg = True
if GUI.webpBox.isChecked():
options.webp = True
if GUI.pngLegacyBox.isChecked():
options.pnglegacy = True
if GUI.noQuantizeBox.isChecked():
options.noquantize = True
if GUI.jpegQualityBox.isChecked():
options.jpegquality = GUI.jpegQualitySpinBox.value()
if GUI.currentMode > 2:
options.customwidth = str(GUI.widthBox.value())
options.customheight = str(GUI.heightBox.value())
if GUI.targetDirectory != '':
options.output = GUI.targetDirectory
if GUI.titleEdit.text():
options.title = str(GUI.titleEdit.text())
if GUI.authorEdit.text():
options.author = str(GUI.authorEdit.text())
if GUI.languageEdit.text():
options.language = str(GUI.languageEdit.text())
if GUI.chunkSizeCheckBox.isChecked():
options.targetsize = int(GUI.chunkSizeBox.value())
options, gui_current_format = get_options()
for i in range(GUI.jobList.count()):
# Make sure that we don't consider any system message as job to do
@@ -558,8 +571,6 @@ class WorkerThread(QThread):
MW.addMessage.emit('Created EPUB file was too big. Weird file structure?', 'error', False)
MW.addMessage.emit('EPUB file: ' + str(epubSize) + 'MB. Supported size: ~350MB.', 'error',
False)
if self.kindlegenErrorCode[0] == 3221226505:
MW.addMessage.emit('Unknown Windows error. Possibly filepath too long?', 'error', False)
else:
for item in outputPath:
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(item):
@@ -659,6 +670,87 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
GUI.jobList.addItem(dname)
GUI.jobList.scrollToBottom()
def labelSpreadsStart(self):
low_quality_preview = False
if QApplication.keyboardModifiers() == Qt.ShiftModifier:
low_quality_preview = True
currentJobs = []
# TODO: make this a function since it's copy pasted
for i in range(GUI.jobList.count()):
# Make sure that we don't consider any system message as job to do
if GUI.jobList.item(i).icon().isNull():
currentJobs.append(str(GUI.jobList.item(i).text()))
for job in currentJobs:
images = []
spreads = []
options, _ = get_options()
options.profileData = [(600, 800), (600,800)]
path = getWorkFolder(job, options)
removeNonImages(path)
sanitizeTree(path, options)
flattenTree(path)
if options.tempdir:
workdir = mkdtemp('', 'KCC-', os.path.dirname(job))
else:
workdir = mkdtemp('', 'KCC-')
for root, _, files in os.walk(path):
files.sort(key=OS_SORT_KEY)
start_index = 0
if job.endswith('.pdf') or job.endswith('.epub'):
start_index = 1
if options.spreadshift:
start_index = 0 if start_index == 1 else 1
for i in range(start_index, len(files), 2):
if i == len(files) - 1:
continue
# TODO: with statements
# TODO: ignore 1% of top and bottom too?
im1 = Image.open(os.path.join(root, files[i]))
im2 = Image.open(os.path.join(root, files[i+1]))
if not options.righttoleft:
im1, im2 = im2, im1
size1 = im1.size
size2 = im2.size
preview_crop1 = im1.crop((0, 0, 0.2*size1[0], size1[1]))
if low_quality_preview:
preview_crop1 = preview_crop1.convert('1', dither=Dither.NONE)
calculation_crop1 = im1.crop((0.01*size1[0], 0, 0.04*size1[0], size1[1])).convert('1', dither=Dither.NONE)
preview_crop2 = im2.crop((0.8*size2[0], 0, size2[0], size2[1]))
if low_quality_preview:
preview_crop2 = preview_crop2.convert('1', dither=Dither.NONE)
calculation_crop2 = im2.crop((0.96*size2[0], 0, .99* size2[0], size2[1])).convert('1', dither=Dither.NONE)
# dst = Image.new('1', (im1.width + im2.width, im1.height))
# dst.paste(im2, (0, 0))
# dst.paste(im1, (im1.width, 0))
hist1 = calculation_crop1.histogram()
hist2 = calculation_crop2.histogram()
# TODO: small percentage instead of zero
if hist1[0] == 0 or hist1[-1] == 0 or hist2[0] == 0 or hist2[-1] == 0:
continue
preview_mode = '1' if low_quality_preview else 'RGB'
dst = Image.new(preview_mode, (preview_crop1.width + preview_crop2.width, preview_crop1.height))
dst.paste(preview_crop2, (0, 0))
dst.paste(preview_crop1, (preview_crop1.width, 0))
dst.save(os.path.join(workdir, f'label-{i:04}.png'))
images.append(os.path.join(workdir, f'label-{i:04}.png'))
if images:
dlg = LabelSpreadsDialog(APP.primaryScreen().availableGeometry().height(), images, spreads)
dlg.setWindowTitle(job)
if dlg.exec() == 1:
with open(job+'.json', "w") as fp:
# TODO: not very clean to grab index from filename
spreads = [int(filename[6:10]) for filename in spreads]
json.dump({'spreads': sorted(set(spreads))} , fp)
rmtree(path, True)
rmtree(workdir, True)
def selectFileMetaEditor(self, sname):
files = []
@@ -750,7 +842,6 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
else:
status = True
GUI.editorButton.setEnabled(status)
GUI.wikiButton.setEnabled(status)
GUI.deviceBox.setEnabled(status)
GUI.defaultOutputFolderButton.setEnabled(status)
GUI.clearButton.setEnabled(status)
@@ -839,7 +930,6 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
GUI.interPanelCropBox.setEnabled(True)
GUI.autoLevelBox.setEnabled(True)
GUI.autocontrastBox.setEnabled(True)
GUI.autocontrastBox.setChecked(True)
def togglequalityBox(self, value):
@@ -1113,6 +1203,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
'smartCoverCropBox': GUI.smartCoverCropBox.checkState(),
'coverFillBox': GUI.coverFillBox.checkState(),
'metadataTitleBox': GUI.metadataTitleBox.checkState(),
'keepComicInfoBox': GUI.keepComicInfoBox.checkState(),
'mozJpegBox': GUI.mozJpegBox.checkState(),
'forcePngRgbBox': GUI.forcePngRgbBox.checkState(),
'webpBox': GUI.webpBox.checkState(),
@@ -1221,11 +1312,14 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
self.defaultOutputFolder = str(self.settings.value('defaultOutputFolder', '', type=str))
if not os.path.exists(self.defaultOutputFolder):
self.defaultOutputFolder = ''
self.lastDevice = self.settings.value('lastDevice', 0, type=int)
# default is Kindle Paperwhite 12th Gen
self.lastDevice = self.settings.value('lastDevice', 3, type=int)
self.currentFormat = self.settings.value('currentFormat', 0, type=int)
self.startNumber = self.settings.value('startNumber', 0, type=int)
self.windowSize = self.settings.value('windowSize', '0x0', type=str)
default_options = {'gammaSlider': 0, 'croppingBox': 2, 'croppingPowerSlider': 100}
default_options = {'gammaSlider': 0, 'croppingBox': 2, 'croppingPowerSlider': 100, 'rotateBox': 1, 'mangaBox': 2}
try:
self.options = self.settings.value('options', default_options)
except Exception:
@@ -1252,7 +1346,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
if self.windowSize == '0x0':
MW.resize(500, 500)
elif sys.platform.startswith('darwin'):
for element in ['editorButton', 'wikiButton', 'defaultOutputFolderButton', 'clearButton', 'fileButton', 'deviceBox',
for element in ['editorButton', 'defaultOutputFolderButton', 'clearButton', 'fileButton', 'deviceBox',
'convertButton', 'formatBox']:
getattr(GUI, element).setMinimumSize(QSize(0, 0))
GUI.gridLayout.setContentsMargins(-1, -1, -1, -1)
@@ -1433,8 +1527,10 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
link_dict = {
'README': "https://github.com/ciromattia/kcc?tab=readme-ov-file#kcc",
'FAQ': "https://github.com/ciromattia/kcc/blob/master/README.md#faq",
'YOUTUBE': "https://youtu.be/IR2Fhcm9658?si=Z-2zzLaUFjmaEbrj",
'COMMISSIONS': "https://github.com/ciromattia/kcc?tab=readme-ov-file#commissions",
'WIKI': "https://github.com/ciromattia/kcc/wiki",
'YOUTUBE': "https://www.youtube.com/@eink-dude",
'TUTORIAL': "https://youtu.be/QQ6zJcMF2Iw?si=80rfm6DU6OUJdFqa",
'EMAIL': "https://github.com/ciromattia/kcc?tab=readme-ov-file#commissions",
'DONATE': "https://github.com/ciromattia/kcc/blob/master/README.md#issues--new-features--donations",
'FORUM': "http://www.mobileread.com/forums/showthread.php?t=207461",
'DISCORD': "https://discord.com/invite/qj7wpnUHav",
@@ -1466,12 +1562,10 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
GUI.fileButton.clicked.connect(self.selectFile)
GUI.directoryButton.clicked.connect(self.selectDir)
GUI.editorButton.clicked.connect(self.selectFileMetaEditor)
GUI.wikiButton.clicked.connect(self.openWiki)
GUI.kofiButton.clicked.connect(self.openKofi)
GUI.humbleButton.clicked.connect(self.openHumble)
GUI.youtubeButton.clicked.connect(self.openYouTube)
GUI.discordButton.clicked.connect(self.openDiscord)
GUI.convertButton.clicked.connect(self.convertStart)
GUI.labelSpreadsButton.clicked.connect(self.labelSpreadsStart)
GUI.gammaSlider.valueChanged.connect(self.changeGamma)
GUI.gammaBox.stateChanged.connect(self.togglegammaBox)
GUI.croppingBox.stateChanged.connect(self.togglecroppingBox)
+92
View File
@@ -0,0 +1,92 @@
import os
from PySide6.QtCore import (Qt)
from PySide6.QtGui import (QKeyEvent, QPixmap)
from PySide6.QtWidgets import (QHBoxLayout, QLabel, QDialog)
class LabelSpreadsDialog(QDialog):
def __init__(self, available_height, images, spreads):
super().__init__()
self.index = 0
self.images = images
self.spreads = spreads
self.index2page = {i: os.path.basename(image) for i, image in enumerate(images)}
self.setWindowTitle("TODO: Filename goes here")
# self.setGeometry(APP.primaryScreen().availableGeometry())
# self.setMaximumSize(APP.primaryScreen().availableSize())
self.available_height = available_height
layout = QHBoxLayout()
self.setLayout(layout)
label = QLabel()
label2 = QLabel()
self.label = label
self.label2 = label2
layout.addWidget(label)
layout.addWidget(label2)
label2.setText("not a spread")
help_text = [
"Use arrows to change index.",
"Use space bar to confirm spreads.",
"Use spread shift option to offset by 1.",
"Use enter key to confirm all spreads."
"Close window to cancel."
]
buttonLabel = QLabel('\n'.join(help_text))
layout.addWidget(buttonLabel)
# print(label.size())
# print(label.maximumSize())
# l, t, r, b = layout.getContentsMargins()
#label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
pixmap = QPixmap(images[0]).scaledToHeight(self.available_height * 0.9)
label.setPixmap(pixmap)
#label.setScaledContents(True)
#label2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
# pixmap2 = QPixmap(images[0]).scaledToHeight(self.frameGeometry().height() - t - b - t - b)
# label2.setPixmap(pixmap2)
#label2.setScaledContents(True)
#self.resize(pixmap2.width(), pixmap2.height())
def keyReleaseEvent(self, event):
# t = 20
# b = 20
if isinstance(event, QKeyEvent):
if event.key() == Qt.Key.Key_Left:
self.index = max(0, self.index - 1)
if self.index2page[self.index] in self.spreads:
self.label2.setText('spread')
else:
self.label2.setText('not a spread')
pixmap = QPixmap(self.images[self.index]).scaledToHeight(self.available_height * 0.9)
self.label.setPixmap(pixmap)
# pixmap2 = QPixmap(images[self.index]).scaledToHeight(self.frameGeometry().height() - t - b - t - b)
# self.label2.setPixmap(pixmap2)
elif event.key() == Qt.Key.Key_Right:
self.index = min(self.index + 1, len(self.images) - 1)
if self.index2page[self.index] in self.spreads:
self.label2.setText('spread')
else:
self.label2.setText('not a spread')
pixmap = QPixmap(self.images[self.index]).scaledToHeight(self.available_height * 0.9)
self.label.setPixmap(pixmap)
# pixmap2 = QPixmap(images[self.index]).scaledToHeight(self.frameGeometry().height() - t - b - t - b)
# self.label2.setPixmap(pixmap2)
elif event.key() == Qt.Key.Key_Space:
if self.label2.text() == "not a spread":
self.spreads.append(os.path.basename(self.images[self.index]))
self.label2.setText('spread')
else:
self.spreads.remove(os.path.basename(self.images[self.index]))
self.label2.setText('not a spread')
elif event.key() == Qt.Key.Key_Return or event.key() == Qt.Key.Key_Enter:
self.accept()
else:
super().keyReleaseEvent(event)
else:
super().keyReleaseEvent(event)
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
__version__ = '10.3.0'
__version__ = '11.0.3'
__license__ = 'ISC'
__copyright__ = '2012-2022, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>, darodi'
__docformat__ = 'restructuredtext en'
+106 -23
View File
@@ -19,6 +19,8 @@
#
from collections import Counter
from datetime import datetime
import json
import os
import pathlib
import re
@@ -871,7 +873,7 @@ def extract_page(vector):
def mupdf_pdf_process_pages_parallel(filename, output_dir, target_width, target_height):
def mupdf_pdf_process_pages_parallel(filename, output_dir, target_width, target_height, pdfwidth):
render = False
with pymupdf.open(filename) as doc:
for page in doc:
@@ -891,7 +893,7 @@ def mupdf_pdf_process_pages_parallel(filename, output_dir, target_width, target_
cpu = cpu_count()
# make vectors of arguments for the processes
vectors = [(i, cpu, filename, output_dir, target_width, target_height, options.pdfwidth) for i in range(cpu)]
vectors = [(i, cpu, filename, output_dir, target_width, target_height, pdfwidth) for i in range(cpu)]
print("Starting %i processes for '%s'." % (cpu, filename))
@@ -905,7 +907,7 @@ def mupdf_pdf_process_pages_parallel(filename, output_dir, target_width, target_
def getWorkFolder(afile, workdir=None):
def getWorkFolder(afile, options, workdir=None):
if not workdir:
if options.tempdir:
workdir = mkdtemp('', 'KCC-', os.path.dirname(afile))
@@ -954,7 +956,7 @@ def getWorkFolder(afile, workdir=None):
target_height *= 1.25 #Account for possible margin at the top and bottom with page number
target_width *= 1.25
try:
mupdf_pdf_process_pages_parallel(afile, fullPath, target_width, target_height)
mupdf_pdf_process_pages_parallel(afile, fullPath, target_width, target_height, options.pdfwidth)
except Exception as e:
rmtree(path, True)
raise UserWarning(f"Failed to extract images from PDF file. {e}")
@@ -978,9 +980,16 @@ def getWorkFolder(afile, workdir=None):
os.path.join(fullPath, tdir[0], 'ComicInfo.xml')
)
if len(tdir) == 1 and os.path.isdir(os.path.join(fullPath, tdir[0])):
if options.tempdir:
workdir2 = mkdtemp('', 'KCC-', os.path.dirname(afile))
else:
workdir2 = mkdtemp('', 'KCC-')
fullPath2 = os.path.join(workdir2, 'OEBPS', 'Images')
os.makedirs(fullPath2, exist_ok=True)
for file in os.listdir(os.path.join(fullPath, tdir[0])):
move(os.path.join(fullPath, tdir[0], file), fullPath)
os.rmdir(os.path.join(fullPath, tdir[0]))
move(os.path.join(fullPath, tdir[0], file), fullPath2)
rmtree(workdir, True)
return workdir2
if options.legacyextract:
return workdir
@@ -1103,6 +1112,7 @@ def getOutputFilename(srcpath, wantedname, ext, tomenumber):
def getMetadata(path, originalpath):
xmlPath = os.path.join(path, 'ComicInfo.xml')
options.comicinfo_chapters = []
options.comicinfo_xml = None
options.summary = ''
titleSuffix = ''
options.volume = ''
@@ -1159,6 +1169,10 @@ def getMetadata(path, originalpath):
options.summary = xml.data['Summary']
if xml.data['Series']:
options.series = xml.data['Series']
# ComicInfo.xml in output may break readers like the Kobo native CBZ reader
if options.keepcomicinfo and options.format == 'CBZ':
with open(xmlPath, 'rb') as f:
options.comicinfo_xml = f.read()
os.remove(xmlPath)
if originalpath.lower().endswith('.pdf'):
@@ -1201,14 +1215,22 @@ def removeNonImages(filetree):
os.remove(os.path.join(root, name))
# remove empty nested folders
for root, dirs, files in os.walk(filetree, False):
if not files and not dirs:
if not os.listdir(root):
os.rmdir(root)
if not os.listdir(Path(filetree).parent):
raise UserWarning('No images detected, nested archives are not supported.')
warning = [
'No images detected.',
'',
'Possible causes:',
'',
'1) Incompatible image file extension like .jxl. Convert to .png first outside of KCC.',
'2) Nested archive: Either extract the nested archive outside of KCC or use File Fusion option.',
]
raise RuntimeError('\n'.join(warning))
def sanitizeTree(filetree, prefix='kcc'):
def sanitizeTree(filetree, options, prefix='kcc'):
chapterNames = {}
page = 1
cover_path = None
@@ -1233,7 +1255,7 @@ def sanitizeTree(filetree, prefix='kcc'):
dirs.sort(key=OS_SORT_KEY)
for i, name in enumerate(dirs):
tmpName = name
slugified = slugify(name, is_natural_sorted)
slugified = slugify(name, options, is_natural_sorted)
while os.path.exists(os.path.join(root, slugified)) and name.upper() != slugified.upper():
slugified += "A"
chapterNames[slugified] = tmpName
@@ -1254,6 +1276,7 @@ def flattenTree(filetree):
def sanitizePermissions(filetree):
os.chmod(filetree, S_IWRITE | S_IREAD | S_IEXEC)
for root, dirs, files in os.walk(filetree, False):
for name in files:
os.chmod(os.path.join(root, name), S_IWRITE | S_IREAD)
@@ -1395,7 +1418,7 @@ def createNewTome(parent):
return tomePath, tomePathRoot
def slugify(value, is_natural_sorted):
def slugify(value, options, is_natural_sorted):
if options.format == 'CBZ' and is_natural_sorted:
return value
if options.format != 'CBZ':
@@ -1475,6 +1498,8 @@ def makeParser():
output_options.add_argument("--metadatatitle", type=int, dest="metadatatitle", default=0,
help="Write title using ComicInfo.xml or other embedded metadata. 1: Combine Title with default schema "
"2: Use Title only")
output_options.add_argument("--keepcomicinfo", type=int, dest="keepcomicinfo", default=0,
help="Keep any original ComicInfo.xml files")
output_options.add_argument("-a", "--author", action="store", dest="author", default="defaultauthor",
help="Author name [Default=KCC]")
output_options.add_argument("--language", action="store", dest="language", default="en-US",
@@ -1758,10 +1783,10 @@ def makeFusion(sources: List[str]):
else:
targetpath = fusion_path.joinpath(f'{prefix}{source_path.name}')
path = getWorkFolder(source, str(targetpath))
path = getWorkFolder(source, options, str(targetpath))
if path != str(targetpath):
move(os.path.join(path, 'OEBPS', 'Images'), targetpath)
sanitizeTree(targetpath, prefix='fusion')
sanitizeTree(targetpath, options, prefix='fusion')
# TODO: remove flattenTree when subchapters are supported
flattenTree(targetpath)
@@ -1784,7 +1809,7 @@ def makeBook(source, qtgui=None, job_progress=''):
if not options.filefusion:
checkPre('LLL-')
print(f"{job_progress}Preparing source images...")
path = getWorkFolder(source)
path = getWorkFolder(source, options)
print(f"{job_progress}Checking images...")
if options.lightnovel:
@@ -1818,7 +1843,34 @@ def makeBook(source, qtgui=None, job_progress=''):
getMetadata(os.path.join(path, "OEBPS", "Images"), source)
removeNonImages(os.path.join(path, "OEBPS", "Images"))
detectSuboptimalProcessing(os.path.join(path, "OEBPS", "Images"), source)
chapterNames, cover_path = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
chapterNames, cover_path = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'), options)
if os.path.exists(source+'.json'):
flattenTree(os.path.join(path, 'OEBPS', 'Images'))
chapterNames = {}
cover_path = None
with open(source+'.json') as f:
data = json.load(f)
for root, _, files in os.walk(os.path.join(path, 'OEBPS', 'Images')):
sorted_files = os_sorted(files)
for i in range(len(sorted_files)):
if not cover_path:
cover_path = os.path.join(root, sorted_files[i])
if i in data['spreads']:
im1 = Image.open(os.path.join(root, sorted_files[i]))
im2 = Image.open(os.path.join(root, sorted_files[i+1]))
if not options.righttoleft:
im1, im2 = im2, im1
dst = Image.new('RGB', (im1.width + im2.width, im1.height))
dst.paste(im2, (0, 0))
dst.paste(im1, (im1.width, 0))
base, _ = os.path.splitext(os.path.basename(sorted_files[i]))
dst.save(os.path.join(path, 'OEBPS', 'Images', f'{base}-merged.png'))
os.remove(os.path.join(root, sorted_files[i]))
os.remove(os.path.join(root, sorted_files[i+1]))
if not os.path.exists(cover_path):
cover_path = os.path.join(root, f'{base}-merged.png')
if options.filefusion:
# Strip the fusion_0001_ sort prefix from makeFusion if present
chapterNames = {k: sub(r'^fusion_\d{4}_', '', v) for k, v in chapterNames.items()}
@@ -1904,7 +1956,10 @@ def makeBook(source, qtgui=None, job_progress=''):
else:
filepath.append(getOutputFilename(source, options.output, '.cbz', ''))
if cover and cover.smartcover:
cover.save_to_folder(os.path.join(tome, 'OEBPS', 'Images', 'cover.jpg'), tomeNumber, len(tomes))
cover.save_to_folder(os.path.join(tome, 'OEBPS', 'Images', '##cover.jpg'), tomeNumber, len(tomes))
if options.comicinfo_xml:
with open(os.path.join(tome, 'OEBPS', 'Images', 'ComicInfo.xml'), 'wb') as xmlOutput:
xmlOutput.write(options.comicinfo_xml)
makeZIP(filepath[-1], os.path.join(tome, "OEBPS", "Images"), job_progress)
elif options.format == 'PDF':
print(f"{job_progress}Creating PDF file with PyMuPDF...")
@@ -1983,8 +2038,14 @@ def makeMOBIWorkerTick(output):
makeMOBIWorkerOutput.append(output)
if output[0] != 0:
makeMOBIWorkerPool.terminate()
for warning in output[3]:
print(warning)
if GUI:
GUI.progressBarTick.emit('tick')
if output[3]:
for warning in output[3]:
GUI.addMessage.emit(warning, 'warning', False)
GUI.addMessage.emit('', '', False)
if not GUI.conversionAlive:
makeMOBIWorkerPool.terminate()
@@ -1994,8 +2055,10 @@ def makeMOBIWorker(item):
kindlegenErrorCode = 0
kindlegenError = ''
try:
# TODO: This size check is incorrect, I think kindlegen increased the limit
if os.path.getsize(item) < 629145600:
start = perf_counter()
# TODO: should anything be done with the kindlegen output during successes?
output = subprocess_run(['kindlegen', '-dont_append_source', '-locale', 'en', item],
stdout=PIPE, stderr=STDOUT, encoding='UTF-8', errors='ignore', check=True)
end = perf_counter()
@@ -2003,27 +2066,47 @@ def makeMOBIWorker(item):
else:
# ERROR: EPUB too big
kindlegenErrorCode = 23026
return [kindlegenErrorCode, kindlegenError, item]
return [kindlegenErrorCode, kindlegenError, item, []]
except CalledProcessError as err:
warnings = []
for line in err.stdout.splitlines():
# ERROR: Generic error
if "Error(" in line:
kindlegenErrorCode = 1
kindlegenError = line
kindlegenError = '\n\n'.join(warnings + [line, 'kindlegen logs dumped'])
try:
timestamp = datetime.now().isoformat(timespec='milliseconds').replace(':', '-').replace('.', '-')
with open(os.path.join(os.path.dirname(item), f'kindlegen-log-{timestamp}.txt'), 'w') as f:
f.write(err.stdout)
except Exception as e:
print(e)
# examples
# Warning(prcgen):W14019: Cover is too small
if "Warning(" in line:
if ":W14016: Cover not specified" in line and options.webtoon:
pass
else:
warnings.append(line)
# ERROR: EPUB too big
if ":E23026:" in line:
kindlegenErrorCode = 23026
if ":E23028:" in line:
kindlegenErrorCode = 23028
if kindlegenErrorCode > 0:
break
if ":I1036: Mobi file built successfully" in line:
return [0, '', item]
return [0, '', item, warnings]
if ":I1037: Mobi file built with WARNINGS!" in line:
return [0, '', item]
return [0, '', item, warnings]
# ERROR: KCC unknown generic error
if kindlegenErrorCode == 0:
kindlegenErrorCode = err.returncode
kindlegenError = err.stdout
return [kindlegenErrorCode, kindlegenError, item]
kindlegenErrorCode = -1
if err.returncode == 3221226505:
kindlegenError = f'Error {err.returncode}: Unknown Windows error. Possibly filepath too long?'
else:
kindlegenError = f'Error {err.returncode}'
return [kindlegenErrorCode, kindlegenError, item, warnings]
def makeMOBI(work, qtgui=None):
+6 -7
View File
@@ -22,7 +22,6 @@ from functools import cached_property, lru_cache
import os
from pathlib import Path
import platform
import distro
from subprocess import STDOUT, PIPE, CalledProcessError
from xml.dom.minidom import parseString
from xml.parsers.expat import ExpatError
@@ -41,12 +40,12 @@ class ComicArchive:
self.dirname, self.basename = os.path.split(filepath)
@cached_property
def type(self):
def type(self):
extraction_commands = [
[SEVENZIP, 'l', '-y', '-p1', self.basename],
]
if distro.id() == 'fedora' or distro.like() == 'fedora':
if platform.system() == 'Linux':
extraction_commands.append(
['unrar', 'l', '-y', '-p1', self.basename],
)
@@ -85,20 +84,20 @@ class ComicArchive:
extraction_commands.reverse()
if distro.id() == 'fedora' or distro.like() == 'fedora':
if platform.system() == 'Linux':
extraction_commands.append(
['unrar', 'x', '-y', '-x__MACOSX', '-x.DS_Store', '-xthumbs.db', '-xThumbs.db', self.basename, targetdir]
)
for cmd in extraction_commands:
try:
subprocess_run(cmd, capture_output=True, check=True, cwd=self.dirname)
return targetdir
return targetdir
except FileNotFoundError:
missing.append(cmd[0])
except CalledProcessError:
pass
if missing:
raise OSError(f'Extraction failed, install <a href="https://github.com/ciromattia/kcc#7-zip">specialized extraction software.</a> ')
else:
+1 -1
View File
@@ -648,7 +648,7 @@ class Cover:
if self.options.righttoleft:
self.image = self.image.crop((w * .36, 0, w, h))
else:
self.image = self.image.crop((w, 0, .64 * w, h))
self.image = self.image.crop((0, 0, .64 * w, h))
def save_to_folder(self, target, tomeid, len_tomes=0):
try:
-1
View File
@@ -5,7 +5,6 @@ python-slugify>=8.0.4
packaging>=26.2
mozjpeg-lossless-optimization>=1.2.0
natsort>=8.4.0
distro>=1.9.0
# Below requirements are compiled in Dockefile
# numpy==2.3.4
# PyMuPDF==1.26.6
-1
View File
@@ -6,6 +6,5 @@ python-slugify>=8.0.4
packaging>=26.2
mozjpeg-lossless-optimization>=1.2.0
natsort>=8.4.0
distro>=1.9.0
numpy<2
PyMuPDF==1.25.5
-1
View File
@@ -6,6 +6,5 @@ python-slugify>=8.0.4
packaging>=26.2
mozjpeg-lossless-optimization>=1.2.0
natsort>=8.4.0
distro>=1.9.0
numpy==1.23.5
PyMuPDF>=1.16
-1
View File
@@ -6,6 +6,5 @@ python-slugify>=8.0.4,<9.0.0
packaging>=26.2
mozjpeg-lossless-optimization>=1.2.0
natsort>=8.4.0
distro>=1.9.0
numpy>=1.22.4
PyMuPDF>=1.18.0
+1 -2
View File
@@ -38,7 +38,7 @@ class BuildBinaryCommand(setuptools.Command):
def run(self):
VERSION = __version__
if sys.platform == 'darwin':
os.system('pyinstaller --hidden-import=_cffi_backend -y -D -i icons/comic2ebook.icns -n "Kindle Comic Converter" -w -s kcc.py')
os.system('pyinstaller -y kcc-macos.spec')
# TODO /usr/bin/codesign --force -s "$MACOS_CERTIFICATE_NAME" --options runtime dist/Applications/Kindle\ Comic\ Converter.app -v
min_os = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
if min_os.startswith('10.1'):
@@ -155,7 +155,6 @@ setuptools.setup(
'python-slugify>=1.2.1,<9.0.0',
'mozjpeg-lossless-optimization>=1.2.0',
'natsort>=8.4.0',
'distro>=1.8.0',
'numpy>=1.22.4',
'packaging>=23.2',
'PyMuPDF>=1.16.1',