1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-21 13:41:44 +00:00

"Natural sorting" for image files (closes #18)

This commit is contained in:
Ciro Mattia Gonano
2013-03-03 14:35:59 +01:00
parent 3c45ab0903
commit aaef0aaf16

View File

@@ -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)