mirror of
https://github.com/ciromattia/kcc
synced 2025-12-16 03:06:33 +00:00
Fully implemented new slugify library
This commit is contained in:
@@ -33,7 +33,7 @@ from optparse import OptionParser, OptionGroup
|
|||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parse
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from slugify import slugify
|
from slugify import slugify as slugifyExt
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
try:
|
try:
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
@@ -48,19 +48,19 @@ from . import pdfjpgextract
|
|||||||
def buildHTML(path, imgfile):
|
def buildHTML(path, imgfile):
|
||||||
filename = getImageFileName(imgfile)
|
filename = getImageFileName(imgfile)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
if "_kccrot" in str(filename):
|
if "-kccrot" in str(filename):
|
||||||
rotatedPage = True
|
rotatedPage = True
|
||||||
else:
|
else:
|
||||||
rotatedPage = False
|
rotatedPage = False
|
||||||
if "_kccnpv" in str(filename):
|
if "-kccnpv" in str(filename):
|
||||||
noPV = True
|
noPV = True
|
||||||
else:
|
else:
|
||||||
noPV = False
|
noPV = False
|
||||||
if "_kccnh" in str(filename):
|
if "-kccnh" in str(filename):
|
||||||
noHorizontalPV = True
|
noHorizontalPV = True
|
||||||
else:
|
else:
|
||||||
noHorizontalPV = False
|
noHorizontalPV = False
|
||||||
if "_kccnv" in str(filename):
|
if "-kccnv" in str(filename):
|
||||||
noVerticalPV = True
|
noVerticalPV = True
|
||||||
else:
|
else:
|
||||||
noVerticalPV = False
|
noVerticalPV = False
|
||||||
@@ -133,13 +133,13 @@ def buildHTML(path, imgfile):
|
|||||||
"}'></a></div>\n"])
|
"}'></a></div>\n"])
|
||||||
if options.quality == 2:
|
if options.quality == 2:
|
||||||
imgfilepv = str.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 = ".".join(imgfilepv)
|
imgfilepv = ".".join(imgfilepv)
|
||||||
else:
|
else:
|
||||||
imgfilepv = imgfile
|
imgfilepv = imgfile
|
||||||
if "_kccxl" in filename[0]:
|
if "-kccxl" in filename[0]:
|
||||||
borders = filename[0].split('_kccxl')[1]
|
borders = filename[0].split('-kccxl')[1]
|
||||||
borders = re.findall('[0-9]{1,6}', borders)
|
borders = re.findall('[0-9]{1,6}', borders)
|
||||||
xl = borders[0].lstrip("0")
|
xl = borders[0].lstrip("0")
|
||||||
yu = borders[1].lstrip("0")
|
yu = borders[1].lstrip("0")
|
||||||
@@ -539,7 +539,7 @@ def genEpubStruct(path):
|
|||||||
chapter = False
|
chapter = False
|
||||||
for afile in filenames:
|
for afile in filenames:
|
||||||
filename = getImageFileName(afile)
|
filename = getImageFileName(afile)
|
||||||
if filename is not None and not "_kcchq" in filename[0]:
|
if filename is not None and not "-kcchq" in filename[0]:
|
||||||
filelist.append(buildHTML(dirpath, afile))
|
filelist.append(buildHTML(dirpath, afile))
|
||||||
if not chapter:
|
if not chapter:
|
||||||
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1]))
|
||||||
@@ -649,15 +649,10 @@ def checkComicInfo(path, originalPath):
|
|||||||
os.remove(xmlPath)
|
os.remove(xmlPath)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Check if replacement work correctly. No zero padding!!!
|
def slugify(value):
|
||||||
#def slugify(value):
|
value = slugifyExt(value)
|
||||||
# # Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
|
value = re.sub(r'0*([0-9]{4,})', r'\1', re.sub(r'([0-9]+)', r'0000\1', value))
|
||||||
# value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
|
return value
|
||||||
# value = re.sub('[^\w\s\.-]', '', value).strip().lower()
|
|
||||||
# value = re.sub('[-\.\s]+', '-', value)
|
|
||||||
# value = re.sub(r'([0-9]+)', r'00000\1', value)
|
|
||||||
# value = re.sub(r'0*([0-9]{6,})', r'\1', value)
|
|
||||||
# return value
|
|
||||||
|
|
||||||
|
|
||||||
def sanitizeTree(filetree):
|
def sanitizeTree(filetree):
|
||||||
|
|||||||
18
kcc/image.py
18
kcc/image.py
@@ -123,21 +123,21 @@ class ComicPage:
|
|||||||
if not color and not forcepng:
|
if not color and not forcepng:
|
||||||
self.image = self.image.convert('L')
|
self.image = self.image.convert('L')
|
||||||
if self.rotated:
|
if self.rotated:
|
||||||
suffix += "_kccrot"
|
suffix += "-kccrot"
|
||||||
if wipe:
|
if wipe:
|
||||||
os.remove(os.path.join(targetdir, self.filename))
|
os.remove(os.path.join(targetdir, self.filename))
|
||||||
else:
|
else:
|
||||||
suffix += "_kcchq"
|
suffix += "-kcchq"
|
||||||
if self.noPV:
|
if self.noPV:
|
||||||
suffix += "_kccnpv"
|
suffix += "-kccnpv"
|
||||||
else:
|
else:
|
||||||
if self.noHPV:
|
if self.noHPV:
|
||||||
suffix += "_kccnh"
|
suffix += "-kccnh"
|
||||||
if self.noVPV:
|
if self.noVPV:
|
||||||
suffix += "_kccnv"
|
suffix += "-kccnv"
|
||||||
if self.border:
|
if self.border:
|
||||||
suffix += "_kccxl" + str(self.border[0]) + "_kccyu" + str(self.border[1]) + "_kccxr" +\
|
suffix += "-kccxl" + str(self.border[0]) + "-kccyu" + str(self.border[1]) + "-kccxr" +\
|
||||||
str(self.border[2]) + "_kccyd" + str(self.border[3])
|
str(self.border[2]) + "-kccyd" + str(self.border[3])
|
||||||
if not self.purge:
|
if not self.purge:
|
||||||
if forcepng:
|
if forcepng:
|
||||||
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".png"),
|
self.image.save(os.path.join(targetdir, os.path.splitext(self.filename)[0] + suffix + ".png"),
|
||||||
@@ -273,8 +273,8 @@ class ComicPage:
|
|||||||
leftbox = (0, 0, width, int(height / 2))
|
leftbox = (0, 0, width, int(height / 2))
|
||||||
rightbox = (0, int(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]
|
||||||
try:
|
try:
|
||||||
if righttoleft:
|
if righttoleft:
|
||||||
pageone = self.image.crop(rightbox)
|
pageone = self.image.crop(rightbox)
|
||||||
|
|||||||
Reference in New Issue
Block a user