about summary refs log tree commit diff
path: root/kindlecomicconverter/comic2ebook.py
diff options
context:
space:
mode:
authorPaweł Jastrzębski <pawelj@iosphe.re>2017-10-13 11:56:51 +0200
committerPaweł Jastrzębski <pawelj@iosphe.re>2017-10-13 11:56:51 +0200
commit658d2f328192b82da5cda9f66217eaa003dd9ea5 (patch)
treee0fc1798a66ecdcc9f0502d41fdc815b886112c0 /kindlecomicconverter/comic2ebook.py
parentFixed HQ mode upscaling (close #248) (diff)
downloadkcc-658d2f328192b82da5cda9f66217eaa003dd9ea5.tar.gz
kcc-658d2f328192b82da5cda9f66217eaa003dd9ea5.tar.bz2
kcc-658d2f328192b82da5cda9f66217eaa003dd9ea5.zip
Fixed directory sorting (close #235)
Diffstat (limited to '')
-rwxr-xr-xkindlecomicconverter/comic2ebook.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py
index 459695d..e27d5e6 100755
--- a/kindlecomicconverter/comic2ebook.py
+++ b/kindlecomicconverter/comic2ebook.py
@@ -699,7 +699,7 @@ def sanitizeTree(filetree):
     for root, dirs, files in os.walk(filetree, False):
         for name in files:
             splitname = os.path.splitext(name)
-            slugified = slugify(splitname[0])
+            slugified = slugify(splitname[0], False)
             while os.path.exists(os.path.join(root, slugified + splitname[1])) and splitname[0].upper()\
                     != slugified.upper():
                 slugified += "A"
@@ -709,7 +709,7 @@ def sanitizeTree(filetree):
                 os.replace(key, newKey)
         for name in dirs:
             tmpName = name
-            slugified = slugify(name)
+            slugified = slugify(name, True)
             while os.path.exists(os.path.join(root, slugified)) and name.upper() != slugified.upper():
                 slugified += "A"
             chapterNames[slugified] = tmpName
@@ -856,8 +856,11 @@ def createNewTome():
     return tomePath, tomePathRoot
 
 
-def slugify(value):
-    value = slugifyExt(value)
+def slugify(value, isDir):
+    if isDir:
+        value = slugifyExt(value, regex_pattern=r'[^-a-z0-9_\.]+')
+    else:
+        value = slugifyExt(value)
     value = sub(r'0*([0-9]{4,})', r'\1', sub(r'([0-9]+)', r'0000\1', value, count=2))
     return value