From 6d445ae151983df50986992a0b79018b2a0534c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Thu, 16 Jan 2014 12:34:36 +0100 Subject: [PATCH] Fully implemented new slugify library --- kcc/comic2ebook.py | 33 ++++++++++++++------------------- kcc/image.py | 18 +++++++++--------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 7a7edb7..35df89b 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -33,7 +33,7 @@ from optparse import OptionParser, OptionGroup from multiprocessing import Pool from xml.dom.minidom import parse from uuid import uuid4 -from slugify import slugify +from slugify import slugify as slugifyExt from PIL import Image try: from PyQt5 import QtCore @@ -48,19 +48,19 @@ from . import pdfjpgextract def buildHTML(path, imgfile): filename = getImageFileName(imgfile) if filename is not None: - if "_kccrot" in str(filename): + if "-kccrot" in str(filename): rotatedPage = True else: rotatedPage = False - if "_kccnpv" in str(filename): + if "-kccnpv" in str(filename): noPV = True else: noPV = False - if "_kccnh" in str(filename): + if "-kccnh" in str(filename): noHorizontalPV = True else: noHorizontalPV = False - if "_kccnv" in str(filename): + if "-kccnv" in str(filename): noVerticalPV = True else: noVerticalPV = False @@ -133,13 +133,13 @@ def buildHTML(path, imgfile): "}'>\n"]) if options.quality == 2: imgfilepv = str.split(imgfile, ".") - imgfilepv[0] = imgfilepv[0].split("_kccxl")[0].replace("_kccnh", "").replace("_kccnv", "") - imgfilepv[0] += "_kcchq" + imgfilepv[0] = imgfilepv[0].split("-kccxl")[0].replace("-kccnh", "").replace("-kccnv", "") + imgfilepv[0] += "-kcchq" imgfilepv = ".".join(imgfilepv) else: imgfilepv = imgfile - if "_kccxl" in filename[0]: - borders = filename[0].split('_kccxl')[1] + if "-kccxl" in filename[0]: + borders = filename[0].split('-kccxl')[1] borders = re.findall('[0-9]{1,6}', borders) xl = borders[0].lstrip("0") yu = borders[1].lstrip("0") @@ -539,7 +539,7 @@ def genEpubStruct(path): chapter = False for afile in filenames: 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)) if not chapter: chapterlist.append((dirpath.replace('Images', 'Text'), filelist[-1][1])) @@ -649,15 +649,10 @@ def checkComicInfo(path, originalPath): os.remove(xmlPath) -# TODO: Check if replacement work correctly. No zero padding!!! -#def slugify(value): -# # Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens. -# value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') -# 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 slugify(value): + value = slugifyExt(value) + value = re.sub(r'0*([0-9]{4,})', r'\1', re.sub(r'([0-9]+)', r'0000\1', value)) + return value def sanitizeTree(filetree): diff --git a/kcc/image.py b/kcc/image.py index f6d14a8..c9e84e9 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -123,21 +123,21 @@ class ComicPage: if not color and not forcepng: self.image = self.image.convert('L') if self.rotated: - suffix += "_kccrot" + suffix += "-kccrot" if wipe: os.remove(os.path.join(targetdir, self.filename)) else: - suffix += "_kcchq" + suffix += "-kcchq" if self.noPV: - suffix += "_kccnpv" + suffix += "-kccnpv" else: if self.noHPV: - suffix += "_kccnh" + suffix += "-kccnh" if self.noVPV: - suffix += "_kccnv" + suffix += "-kccnv" if self.border: - suffix += "_kccxl" + str(self.border[0]) + "_kccyu" + str(self.border[1]) + "_kccxr" +\ - str(self.border[2]) + "_kccyd" + str(self.border[3]) + suffix += "-kccxl" + str(self.border[0]) + "-kccyu" + str(self.border[1]) + "-kccxr" +\ + str(self.border[2]) + "-kccyd" + str(self.border[3]) if not self.purge: if forcepng: 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)) rightbox = (0, int(height / 2), width, height) filename = os.path.splitext(self.filename) - fileone = targetdir + '/' + filename[0] + '_kcca' + filename[1] - filetwo = targetdir + '/' + filename[0] + '_kccb' + filename[1] + fileone = targetdir + '/' + filename[0] + '-kcca' + filename[1] + filetwo = targetdir + '/' + filename[0] + '-kccb' + filename[1] try: if righttoleft: pageone = self.image.crop(rightbox)