get size from zip
This commit is contained in:
parent
b66e76c01a
commit
08e9472d2a
1 changed files with 5 additions and 6 deletions
|
@ -19,6 +19,7 @@ from utils import find_isbns, get_language, to_isbn13
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_ratio(data):
|
def get_ratio(data):
|
||||||
try:
|
try:
|
||||||
img = Image.open(BytesIO(data))
|
img = Image.open(BytesIO(data))
|
||||||
|
@ -42,7 +43,7 @@ def cover(path):
|
||||||
if r < 0.3 or r > 2:
|
if r < 0.3 or r > 2:
|
||||||
return None
|
return None
|
||||||
return data
|
return data
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
for f in z.filelist:
|
for f in z.filelist:
|
||||||
if f.filename == 'calibre-logo.png':
|
if f.filename == 'calibre-logo.png':
|
||||||
|
@ -78,12 +79,10 @@ def cover(path):
|
||||||
filename = unquote(e.attrib['href'])
|
filename = unquote(e.attrib['href'])
|
||||||
filename = os.path.normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
filename = os.path.normpath(os.path.join(os.path.dirname(opf[0]), filename))
|
||||||
if filename in files:
|
if filename in files:
|
||||||
image_data.append((filename, z.read(filename)))
|
image_data.append(filename)
|
||||||
if image_data:
|
if image_data:
|
||||||
image_data.sort(key=lambda i: len(i[1]))
|
image_data.sort(key=lambda name: z.getinfo(name).file_size)
|
||||||
data = image_data[-1][1]
|
return use(image_data[-1])
|
||||||
logger.debug('using %s', image_data[-1][0])
|
|
||||||
return data
|
|
||||||
for e in manifest.getchildren():
|
for e in manifest.getchildren():
|
||||||
if 'html' in e.attrib['media-type']:
|
if 'html' in e.attrib['media-type']:
|
||||||
filename = unquote(e.attrib['href'])
|
filename = unquote(e.attrib['href'])
|
||||||
|
|
Loading…
Reference in a new issue