diff --git a/README.md b/README.md index b54a166..b223b74 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,9 @@ The app relies and includes the following scripts/binaries: Added generic CSS file Optimized archive extraction for zip/rar files (#40) - 2.9: Added support for generating a plain CBZ (skipping all the EPUB/Mobi generation) (#45) - Prevent output file overwriting the source one: if a duplicate name is detected, append _kcc to the name + Prevent output file overwriting the source one: if a duplicate name is detected, append _kcc to the name + Rarfile library updated to 2.6 + Filenames slugifications (#28, #31, #9, #8) ## COPYRIGHT diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 51c1b4b..58d614d 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -128,7 +128,7 @@ def buildNCX(dstdir, title, chapters): f = open(ncxfile, "w") f.writelines(["\n", "\n", + "\"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd\">\n", "\n", "\n", "\n", @@ -356,6 +356,7 @@ def genEpubStruct(path): chapterlist = [] cover = None _, deviceres, _, _, panelviewsize = image.ProfileData.Profiles[options.profile] + slugifyFileTree(path) os.mkdir(os.path.join(path, 'OEBPS', 'Text')) f = open(os.path.join(path, 'OEBPS', 'Text', 'style.css'), 'w') #DON'T COMPRESS CSS. KINDLE WILL FAIL TO PARSE IT. @@ -535,6 +536,29 @@ def getWorkFolder(afile): return path +def slugify(value): + """ + Normalizes string, converts to lowercase, removes non-alpha characters, + and converts spaces to hyphens. + """ + import unicodedata + value = unicodedata.normalize('NFKD', unicode(value)).encode('ascii', 'ignore') + value = re.sub('[^\w\s-]', '', value).strip() + value = re.sub('[-\s]+', '-', value) + return value + + +def slugifyFileTree(filetree): + for root, dirs, files in os.walk(filetree): + for name in files: + splitname = os.path.splitext(name) + os.rename(os.path.join(root, name), + os.path.join(root, slugify(splitname[0]) + splitname[1])) + for name in dirs: + slugifyFileTree(os.path.join(root, name)) + os.rename(os.path.join(root, name), os.path.join(root, slugify(name))) + + def Copyright(): print ('comic2ebook v%(__version__)s. ' 'Written 2012 by Ciro Mattia Gonano.' % globals())