ignore covers that are to tall or to wide
This commit is contained in:
parent
e2b96b6ba2
commit
e6e52d53d5
2 changed files with 25 additions and 5 deletions
|
@ -311,8 +311,11 @@ class Item(db.Model):
|
|||
|
||||
def update_icons(self):
|
||||
def get_ratio(data):
|
||||
img = Image.open(BytesIO(data))
|
||||
return img.size[0]/img.size[1]
|
||||
try:
|
||||
img = Image.open(BytesIO(data))
|
||||
return img.size[0]/img.size[1]
|
||||
except:
|
||||
return 1
|
||||
key = 'cover:%s'%self.id
|
||||
cover = None
|
||||
if 'cover' in self.meta and self.meta['cover']:
|
||||
|
|
|
@ -8,6 +8,9 @@ import zipfile
|
|||
import re
|
||||
from urllib.parse import unquote
|
||||
import lxml.html
|
||||
from io import BytesIO
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from ox import strip_tags, decode_html
|
||||
|
||||
|
@ -16,6 +19,13 @@ from utils import find_isbns, get_language, to_isbn13
|
|||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_ratio(data):
|
||||
try:
|
||||
img = Image.open(BytesIO(data))
|
||||
return img.size[0]/img.size[1]
|
||||
except:
|
||||
return -1
|
||||
|
||||
def cover(path):
|
||||
logger.debug('cover %s', path)
|
||||
data = None
|
||||
|
@ -27,12 +37,19 @@ def cover(path):
|
|||
|
||||
def use(filename):
|
||||
logger.debug('using %s', filename)
|
||||
return z.read(filename)
|
||||
data = z.read(filename)
|
||||
r = get_ratio(data)
|
||||
if r < 0.3 or r > 2:
|
||||
return None
|
||||
return data
|
||||
|
||||
files = []
|
||||
for f in z.filelist:
|
||||
if f.filename == 'calibre-logo.png':
|
||||
continue
|
||||
if 'cover' in f.filename.lower() and f.filename.split('.')[-1] in ('jpg', 'jpeg', 'png'):
|
||||
return use(f.filename)
|
||||
files = [f.filename for f in z.filelist]
|
||||
files.append(f.filename)
|
||||
opf = [f for f in files if f.endswith('opf')]
|
||||
if opf:
|
||||
#logger.debug('opf: %s', z.read(opf[0]).decode())
|
||||
|
|
Loading…
Reference in a new issue