mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When sorting filenames in comics treat the file extension as a secondary sort key.
This commit is contained in:
parent
d7ee646be6
commit
c3aa3b241f
@ -5,6 +5,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
from calibre.utils import zipfile
|
from calibre.utils import zipfile
|
||||||
|
from calibre.utils.icu import numeric_sort_key
|
||||||
|
|
||||||
def update(pathtozip, patterns, filepaths, names, compression=zipfile.ZIP_DEFLATED, verbose=True):
|
def update(pathtozip, patterns, filepaths, names, compression=zipfile.ZIP_DEFLATED, verbose=True):
|
||||||
'''
|
'''
|
||||||
@ -43,12 +44,15 @@ def extract(filename, dir):
|
|||||||
zf = zipfile.ZipFile(filename)
|
zf = zipfile.ZipFile(filename)
|
||||||
zf.extractall(dir)
|
zf.extractall(dir)
|
||||||
|
|
||||||
|
def sort_key(filename):
|
||||||
|
bn, ext = filename.rpartition('.')[::2]
|
||||||
|
return (numeric_sort_key(bn), numeric_sort_key(ext))
|
||||||
|
|
||||||
def extract_member(filename, match=re.compile(r'\.(jpg|jpeg|gif|png)\s*$', re.I), sort_alphabetically=False):
|
def extract_member(filename, match=re.compile(r'\.(jpg|jpeg|gif|png)\s*$', re.I), sort_alphabetically=False):
|
||||||
zf = zipfile.ZipFile(filename)
|
zf = zipfile.ZipFile(filename)
|
||||||
names = list(zf.namelist())
|
names = list(zf.namelist())
|
||||||
if sort_alphabetically:
|
if sort_alphabetically:
|
||||||
from calibre.utils.icu import numeric_sort_key
|
names.sort(key=sort_key)
|
||||||
names.sort(key=numeric_sort_key)
|
|
||||||
for name in names:
|
for name in names:
|
||||||
if match.search(name):
|
if match.search(name):
|
||||||
return name, zf.read(name)
|
return name, zf.read(name)
|
||||||
|
@ -185,9 +185,9 @@ def extract_member(stream, match=re.compile(r'\.(jpg|jpeg|gif|png)\s*$', re.I),
|
|||||||
return h['filename'], et.getvalue()
|
return h['filename'], et.getvalue()
|
||||||
|
|
||||||
def extract_first_alphabetically(stream):
|
def extract_first_alphabetically(stream):
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.libunzip import sort_key
|
||||||
names_ = sorted([x for x in names(stream) if os.path.splitext(x)[1][1:].lower() in
|
names_ = sorted([x for x in names(stream) if os.path.splitext(x)[1][1:].lower() in
|
||||||
{'png', 'jpg', 'jpeg', 'gif'}], key=numeric_sort_key)
|
{'png', 'jpg', 'jpeg', 'gif', 'webp'}], key=sort_key)
|
||||||
return extract_member(stream, name=names_[0], match=None)
|
return extract_member(stream, name=names_[0], match=None)
|
||||||
|
|
||||||
# Test normal RAR file {{{
|
# Test normal RAR file {{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user