mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When getting cover from comic files, use smart filename sorting to find the first filename, recognizing numbers inside the filenames.
This commit is contained in:
parent
f7460f138e
commit
1fcf1e01b2
@ -43,12 +43,12 @@ def extract(filename, dir):
|
|||||||
zf = zipfile.ZipFile(filename)
|
zf = zipfile.ZipFile(filename)
|
||||||
zf.extractall(dir)
|
zf.extractall(dir)
|
||||||
|
|
||||||
def extract_member(filename, match=re.compile(r'\.(jpg|jpeg|gif|png)\s*$',
|
def extract_member(filename, match=re.compile(r'\.(jpg|jpeg|gif|png)\s*$', re.I), sort_alphabetically=False):
|
||||||
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:
|
||||||
names.sort()
|
from calibre.utils.icu import numeric_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,8 +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
|
||||||
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'}])
|
{'png', 'jpg', 'jpeg', 'gif'}], key=numeric_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