From aaef0aaf160c5c07eb051d293d1cd4f080f9c64c Mon Sep 17 00:00:00 2001 From: Ciro Mattia Gonano Date: Sun, 3 Mar 2013 14:35:59 +0100 Subject: [PATCH] "Natural sorting" for image files (closes #18) --- kcc/comic2ebook.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index b05a2d2..7598026 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -274,7 +274,9 @@ def genEpubStruct(path): copyfile(os.path.join(filelist[-1][0], filelist[-1][1]), cover) buildNCX(path, options.title, chapterlist) # ensure we're sorting files alphabetically - filelist = sorted(filelist, key=lambda name: (name[0].lower(), name[1].lower())) + convert = lambda text: int(text) if text.isdigit() else text + alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] + filelist.sort(key=lambda name: (alphanum_key(name[0].lower()), alphanum_key(name[1].lower()))) buildOPF(options.profile, path, options.title, filelist, cover, options.righttoleft)