1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00

And one more bucket...

This commit is contained in:
Paweł Jastrzębski
2014-01-15 11:32:29 +01:00
parent 19b438844d
commit cccbd36463
8 changed files with 61 additions and 59 deletions

View File

@@ -27,7 +27,8 @@ import sys
from multiprocessing import freeze_support from multiprocessing import freeze_support
from kcc.comic2ebook import main, Copyright from kcc.comic2ebook import main, Copyright
freeze_support() if __name__ == "__main__":
Copyright() freeze_support()
main(sys.argv[1:]) Copyright()
sys.exit(0) main(sys.argv[1:])
sys.exit(0)

View File

@@ -27,7 +27,8 @@ import sys
from multiprocessing import freeze_support from multiprocessing import freeze_support
from kcc.comic2panel import main, Copyright from kcc.comic2panel import main, Copyright
freeze_support() if __name__ == "__main__":
Copyright() freeze_support()
main(sys.argv[1:]) Copyright()
sys.exit(0) main(sys.argv[1:])
sys.exit(0)

35
kcc.py
View File

@@ -94,21 +94,22 @@ class QApplicationMessaging(QtGui.QApplication):
return True return True
return False return False
freeze_support() if __name__ == "__main__":
KCCAplication = QApplicationMessaging(sys.argv) freeze_support()
if KCCAplication.isRunning(): KCCAplication = QApplicationMessaging(sys.argv)
if KCCAplication.isRunning():
if len(sys.argv) > 1:
KCCAplication.sendMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(0)
else:
messageBox = QtGui.QMessageBox()
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(':/Icon/icons/comic2ebook.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
messageBox.setWindowIcon(icon)
QtGui.QMessageBox.critical(messageBox, 'KCC - Error', 'KCC is already running!', QtGui.QMessageBox.Ok)
sys.exit(1)
KCCWindow = QtGui.QMainWindow()
KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow)
if len(sys.argv) > 1: if len(sys.argv) > 1:
KCCAplication.sendMessage(sys.argv[1].decode(sys.getfilesystemencoding())) KCCUI.handleMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(0) sys.exit(KCCAplication.exec_())
else:
messageBox = QtGui.QMessageBox()
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(':/Icon/icons/comic2ebook.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
messageBox.setWindowIcon(icon)
QtGui.QMessageBox.critical(messageBox, 'KCC - Error', 'KCC is already running!', QtGui.QMessageBox.Ok)
sys.exit(1)
KCCWindow = QtGui.QMainWindow()
KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow)
if len(sys.argv) > 1:
KCCUI.handleMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(KCCAplication.exec_())

View File

@@ -31,11 +31,11 @@ try:
except ImportError: except ImportError:
print("ERROR: Psutil is not installed!") print("ERROR: Psutil is not installed!")
if platform.startswith('linux'): if platform.startswith('linux'):
import Tkinter import tkinter
import tkMessageBox import tkinter.messagebox
importRoot = Tkinter.Tk() importRoot = tkinter.Tk()
importRoot.withdraw() importRoot.withdraw()
tkMessageBox.showerror("KCC - Error", "Psutil is not installed!") tkinter.messagebox.showerror("KCC - Error", "Psutil is not installed!")
exit(1) exit(1)
from shutil import move from shutil import move

View File

@@ -26,7 +26,6 @@ import os
import sys import sys
import re import re
import stat import stat
import string
import zipfile import zipfile
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import move, copyfile, copytree, rmtree from shutil import move, copyfile, copytree, rmtree
@@ -153,10 +152,10 @@ def buildHTML(path, imgfile):
"'{\"targetId\":\"" + boxes[i] + "-Panel-Parent\", \"ordinal\":" + str(order[i]), "'{\"targetId\":\"" + boxes[i] + "-Panel-Parent\", \"ordinal\":" + str(order[i]),
"}'></a></div>\n"]) "}'></a></div>\n"])
if options.quality == 2: if options.quality == 2:
imgfilepv = string.split(imgfile, ".") imgfilepv = str.split(imgfile, ".")
imgfilepv[0] = imgfilepv[0].split("_kccxl")[0].replace("_kccnh", "").replace("_kccnv", "") imgfilepv[0] = imgfilepv[0].split("_kccxl")[0].replace("_kccnh", "").replace("_kccnv", "")
imgfilepv[0] += "_kcchq" imgfilepv[0] += "_kcchq"
imgfilepv = string.join(imgfilepv, ".") imgfilepv = ".".join(imgfilepv)
else: else:
imgfilepv = imgfile imgfilepv = imgfile
if "_kccxl" in filename[0]: if "_kccxl" in filename[0]:
@@ -210,7 +209,7 @@ def buildHTML(path, imgfile):
def buildNCX(dstdir, title, chapters): def buildNCX(dstdir, title, chapters):
options.uuid = str(uuid4()) options.uuid = str(uuid4())
options.uuid = options.uuid.encode('utf-8') #options.uuid = options.uuid.encode('utf-8')
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx') ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
f = open(ncxfile, "w") f = open(ncxfile, "w")
f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
@@ -258,7 +257,7 @@ def buildOPF(dstdir, title, filelist, cover=None):
"<dc:language>en-US</dc:language>\n", "<dc:language>en-US</dc:language>\n",
"<dc:identifier id=\"BookID\" opf:scheme=\"UUID\">", options.uuid, "</dc:identifier>\n"]) "<dc:identifier id=\"BookID\" opf:scheme=\"UUID\">", options.uuid, "</dc:identifier>\n"])
for author in options.authors: for author in options.authors:
f.writelines(["<dc:creator>", author.encode('utf-8'), "</dc:creator>\n"]) f.writelines(["<dc:creator>", author, "</dc:creator>\n"])
f.writelines(["<meta name=\"generator\" content=\"KindleComicConverter-" + __version__ + "\"/>\n", f.writelines(["<meta name=\"generator\" content=\"KindleComicConverter-" + __version__ + "\"/>\n",
"<meta name=\"RegionMagnification\" content=\"true\"/>\n", "<meta name=\"RegionMagnification\" content=\"true\"/>\n",
"<meta name=\"region-mag\" content=\"true\"/>\n", "<meta name=\"region-mag\" content=\"true\"/>\n",
@@ -289,14 +288,14 @@ def buildOPF(dstdir, title, filelist, cover=None):
filename = getImageFileName(path[1]) filename = getImageFileName(path[1])
uniqueid = os.path.join(folder, filename[0]).replace('/', '_').replace('\\', '_') uniqueid = os.path.join(folder, filename[0]).replace('/', '_').replace('\\', '_')
reflist.append(uniqueid) reflist.append(uniqueid)
f.write("<item id=\"page_" + uniqueid + "\" href=\"" f.write("<item id=\"page_" + str(uniqueid) + "\" href=\""
+ folder.replace('Images', 'Text') + "/" + filename[0] + folder.replace('Images', 'Text') + "/" + filename[0]
+ ".html\" media-type=\"application/xhtml+xml\"/>\n") + ".html\" media-type=\"application/xhtml+xml\"/>\n")
if '.png' == filename[1]: if '.png' == filename[1]:
mt = 'image/png' mt = 'image/png'
else: else:
mt = 'image/jpeg' mt = 'image/jpeg'
f.write("<item id=\"img_" + uniqueid + "\" href=\"" + folder + "/" + path[1] + "\" media-type=\"" f.write("<item id=\"img_" + str(uniqueid) + "\" href=\"" + folder + "/" + path[1] + "\" media-type=\""
+ mt + "\"/>\n") + mt + "\"/>\n")
f.write("<item id=\"css\" href=\"Text/style.css\" media-type=\"text/css\"/>\n") f.write("<item id=\"css\" href=\"Text/style.css\" media-type=\"text/css\"/>\n")
f.write("</manifest>\n<spine toc=\"ncx\">\n") f.write("</manifest>\n<spine toc=\"ncx\">\n")
@@ -648,19 +647,19 @@ def checkComicInfo(path, originalPath):
titleSuffix += ' #' + xml.getElementsByTagName('Number')[0].firstChild.nodeValue titleSuffix += ' #' + xml.getElementsByTagName('Number')[0].firstChild.nodeValue
options.title += titleSuffix options.title += titleSuffix
if len(xml.getElementsByTagName('Writer')) != 0: if len(xml.getElementsByTagName('Writer')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Writer')[0].firstChild.nodeValue, ', ') authorsTemp = str.split(xml.getElementsByTagName('Writer')[0].firstChild.nodeValue, ', ')
for author in authorsTemp: for author in authorsTemp:
options.authors.append(author) options.authors.append(author)
if len(xml.getElementsByTagName('Penciller')) != 0: if len(xml.getElementsByTagName('Penciller')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Penciller')[0].firstChild.nodeValue, ', ') authorsTemp = str.split(xml.getElementsByTagName('Penciller')[0].firstChild.nodeValue, ', ')
for author in authorsTemp: for author in authorsTemp:
options.authors.append(author) options.authors.append(author)
if len(xml.getElementsByTagName('Inker')) != 0: if len(xml.getElementsByTagName('Inker')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Inker')[0].firstChild.nodeValue, ', ') authorsTemp = str.split(xml.getElementsByTagName('Inker')[0].firstChild.nodeValue, ', ')
for author in authorsTemp: for author in authorsTemp:
options.authors.append(author) options.authors.append(author)
if len(xml.getElementsByTagName('Colorist')) != 0: if len(xml.getElementsByTagName('Colorist')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Colorist')[0].firstChild.nodeValue, ', ') authorsTemp = str.split(xml.getElementsByTagName('Colorist')[0].firstChild.nodeValue, ', ')
for author in authorsTemp: for author in authorsTemp:
options.authors.append(author) options.authors.append(author)
if len(options.authors) > 0: if len(options.authors) > 0:
@@ -671,7 +670,7 @@ def checkComicInfo(path, originalPath):
os.remove(xmlPath) os.remove(xmlPath)
# TODO: Check if replacement work correctly # TODO: Check if replacement work correctly. No zero padding!!!
#def slugify(value): #def slugify(value):
# # Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens. # # Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
# value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') # value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
@@ -898,8 +897,7 @@ def makeZIP(zipFilename, baseDir, isEPUB=False):
def Copyright(): def Copyright():
print(('comic2ebook v%(__version__)s. ' print(('comic2ebook v%(__version__)s. Written by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
'Written 2013 by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
def Usage(): def Usage():

View File

@@ -117,14 +117,14 @@ def mergeDirectory(work):
os.remove(i[1]) os.remove(i[1])
savePath = os.path.split(imagesClear[0][1]) savePath = os.path.split(imagesClear[0][1])
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG') result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG')
except StandardError: except Exception:
return str(sys.exc_info()[1]) return str(sys.exc_info()[1])
def sanitizePanelSize(panel, opt): def sanitizePanelSize(panel, opt):
newPanels = [] newPanels = []
if panel[2] > 8 * opt.height: if panel[2] > 8 * opt.height:
diff = (panel[2] / 8) diff = int(panel[2] / 8)
newPanels.append([panel[0], panel[1] - diff*7, diff]) newPanels.append([panel[0], panel[1] - diff*7, diff])
newPanels.append([panel[1] - diff*7, panel[1] - diff*6, diff]) newPanels.append([panel[1] - diff*7, panel[1] - diff*6, diff])
newPanels.append([panel[1] - diff*6, panel[1] - diff*5, diff]) newPanels.append([panel[1] - diff*6, panel[1] - diff*5, diff])
@@ -134,14 +134,14 @@ def sanitizePanelSize(panel, opt):
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff]) newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
newPanels.append([panel[1] - diff, panel[1], diff]) newPanels.append([panel[1] - diff, panel[1], diff])
elif panel[2] > 4 * opt.height: elif panel[2] > 4 * opt.height:
diff = (panel[2] / 4) diff = int(panel[2] / 4)
newPanels.append([panel[0], panel[1] - diff*3, diff]) newPanels.append([panel[0], panel[1] - diff*3, diff])
newPanels.append([panel[1] - diff*3, panel[1] - diff*2, diff]) newPanels.append([panel[1] - diff*3, panel[1] - diff*2, diff])
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff]) newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
newPanels.append([panel[1] - diff, panel[1], diff]) newPanels.append([panel[1] - diff, panel[1], diff])
elif panel[2] > 2 * opt.height: elif panel[2] > 2 * opt.height:
newPanels.append([panel[0], panel[1] - (panel[2] / 2), (panel[2] / 2)]) newPanels.append([panel[0], panel[1] - int(panel[2] / 2), int(panel[2] / 2)])
newPanels.append([panel[1] - (panel[2] / 2), panel[1], (panel[2] / 2)]) newPanels.append([panel[1] - int(panel[2] / 2), panel[1], int(panel[2] / 2)])
else: else:
newPanels = [panel] newPanels = [panel]
return newPanels return newPanels
@@ -248,8 +248,7 @@ def splitImage(work):
def Copyright(): def Copyright():
print(('comic2panel v%(__version__)s. ' print(('comic2panel v%(__version__)s. Written by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
'Written 2013 by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
def main(argv=None, qtGUI=None): def main(argv=None, qtGUI=None):

View File

@@ -22,6 +22,7 @@ __docformat__ = 'restructuredtext en'
import os import os
from sys import platform from sys import platform
from functools import reduce
try: try:
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
from PIL import Image, ImageOps, ImageStat, ImageChops from PIL import Image, ImageOps, ImageStat, ImageChops
@@ -248,8 +249,8 @@ class ComicPage:
return self.image return self.image
# If image is smaller than target resolution and upscale is off - Just expand it by adding margins # If image is smaller than target resolution and upscale is off - Just expand it by adding margins
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1] and not upscale: if self.image.size[0] <= size[0] and self.image.size[1] <= size[1] and not upscale:
borderw = (size[0] - self.image.size[0]) / 2 borderw = int((size[0] - self.image.size[0]) / 2)
borderh = (size[1] - self.image.size[1]) / 2 borderh = int((size[1] - self.image.size[1]) / 2)
# PV is disabled when source image is smaller than device screen and upscale is off - So we drop HQ image # PV is disabled when source image is smaller than device screen and upscale is off - So we drop HQ image
if qualityMode == 2 and self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]: if qualityMode == 2 and self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
self.purge = True self.purge = True
@@ -265,7 +266,7 @@ class ComicPage:
self.image = ImageOps.expand(self.image, border=(int(diff / 2), 0), fill=fill) self.image = ImageOps.expand(self.image, border=(int(diff / 2), 0), fill=fill)
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev: elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
diff = int(self.image.size[0] / ratioDev) - self.image.size[1] diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill) self.image = ImageOps.expand(self.image, border=(0, int(diff / 2)), fill=fill)
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]: if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
method = Image.BICUBIC method = Image.BICUBIC
else: else:
@@ -286,12 +287,12 @@ class ComicPage:
self.rotated = False self.rotated = False
if width > height: if width > height:
# Source is landscape, so split by the width # Source is landscape, so split by the width
leftbox = (0, 0, width / 2, height) leftbox = (0, 0, int(width / 2), height)
rightbox = (width / 2, 0, width, height) rightbox = (int(width / 2), 0, width, height)
else: else:
# Source is portrait and target is landscape, so split by the height # Source is portrait and target is landscape, so split by the height
leftbox = (0, 0, width, height / 2) leftbox = (0, 0, width, int(height / 2))
rightbox = (0, height / 2, width, height) rightbox = (0, int(height / 2), width, height)
filename = os.path.splitext(self.filename) filename = os.path.splitext(self.filename)
fileone = targetdir + '/' + filename[0] + '_kcca' + filename[1] fileone = targetdir + '/' + filename[0] + '_kcca' + filename[1]
filetwo = targetdir + '/' + filename[0] + '_kccb' + filename[1] filetwo = targetdir + '/' + filename[0] + '_kccb' + filename[1]

View File

@@ -28,6 +28,7 @@ from random import choice
from string import ascii_uppercase, digits from string import ascii_uppercase, digits
#TODO: Check entire code. Replacing file() with open() is not enought.
class PdfJpgExtract: class PdfJpgExtract:
def __init__(self, origFileName): def __init__(self, origFileName):
self.origFileName = origFileName self.origFileName = origFileName
@@ -39,7 +40,7 @@ class PdfJpgExtract:
return self.path return self.path
def extract(self): def extract(self):
pdf = file(self.origFileName, "rb").read() pdf = open(self.origFileName, "rb").read()
startmark = "\xff\xd8" startmark = "\xff\xd8"
startfix = 0 startfix = 0
@@ -67,7 +68,7 @@ class PdfJpgExtract:
istart += startfix istart += startfix
iend += endfix iend += endfix
jpg = pdf[istart:iend] jpg = pdf[istart:iend]
jpgfile = file(self.path + "/jpg%d.jpg" % njpg, "wb") jpgfile = open(self.path + "/jpg%d.jpg" % njpg, "wb")
jpgfile.write(jpg) jpgfile.write(jpg)
jpgfile.close() jpgfile.close()