From 9249390043b839b823555f068bad108df32ee83d Mon Sep 17 00:00:00 2001 From: Andriy Zasypkin Date: Thu, 14 Dec 2017 10:39:25 -0500 Subject: [PATCH] comic book read file order fixed --- cps/web.py | 12 +++++++++--- optional-requirements.txt | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cps/web.py b/cps/web.py index 30b31378..2dd2b371 100755 --- a/cps/web.py +++ b/cps/web.py @@ -30,6 +30,12 @@ try: except ImportError: rar_support=False +try: + from natsort import natsorted as sorted +except ImportError: + pass # Just use regular sort then + # may cause issues with badly named pages in cbz/cbr files + import mimetypes import logging from logging.handlers import RotatingFileHandler @@ -931,7 +937,7 @@ def get_comic_book(book_id, book_format, page): rarfile.UNRAR_TOOL = config.config_rarfile_location try: rf = rarfile.RarFile(cbr_file) - rarNames = rf.namelist() + rarNames = sorted(rf.namelist()) b64 = codecs.encode(rf.read(rarNames[page]), 'base64').decode() extractedfile="data:image/png;base64," + b64 fileData={"name": rarNames[page],"page":page, "last":rarNames.__len__()-1, "content": extractedfile} @@ -945,7 +951,7 @@ def get_comic_book(book_id, book_format, page): return "", 204 if book_format == "cbz": zf = zipfile.ZipFile(cbr_file) - zipNames=zf.namelist() + zipNames=sorted(zf.namelist()) if sys.version_info.major >= 3: b64 = codecs.encode(zf.read(zipNames[page]), 'base64').decode() else: @@ -955,7 +961,7 @@ def get_comic_book(book_id, book_format, page): if book_format == "cbt": tf = tarfile.TarFile(u'D:\\zip\\test.cbt') - tarNames=tf.getnames() + tarNames=sorted(tf.getnames()) if sys.version_info.major >= 3: b64 = codecs.encode(tf.extractfile(tarNames[page]).read(), 'base64').decode() else: diff --git a/optional-requirements.txt b/optional-requirements.txt index fe37ed61..3c8bed2b 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -14,3 +14,4 @@ uritemplate==3.0.0 goodreads>=0.3.2 python-Levenshtein>=0.12.0 rarfile>=2.7 +natsort>=2.2.0