mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix thumbnail handling in metadata objects
This commit is contained in:
commit
895942c332
@ -110,7 +110,7 @@ COPYABLE_METADATA_FIELDS = SOCIAL_METADATA_FIELDS.union(
|
||||
frozenset(['title', 'title_sort', 'authors',
|
||||
'author_sort', 'author_sort_map' 'comments',
|
||||
'cover_data', 'tags', 'language', 'lpath',
|
||||
'size'])
|
||||
'size', 'thumbnail'])
|
||||
|
||||
SERIALIZABLE_FIELDS = SOCIAL_METADATA_FIELDS.union(
|
||||
USER_METADATA_FIELDS).union(
|
||||
|
@ -223,7 +223,7 @@ class Metadata(object):
|
||||
self.author_sort = other.author_sort
|
||||
|
||||
if replace_metadata:
|
||||
SPECIAL_FIELDS = frozenset(['lpath', 'size', 'comments'])
|
||||
SPECIAL_FIELDS = frozenset(['lpath', 'size', 'comments', 'thumbnail'])
|
||||
for attr in COPYABLE_METADATA_FIELDS:
|
||||
setattr(self, attr, getattr(other, attr, 1.0 if \
|
||||
attr == 'series_index' else None))
|
||||
@ -238,6 +238,7 @@ class Metadata(object):
|
||||
for attr in COPYABLE_METADATA_FIELDS:
|
||||
if hasattr(other, attr):
|
||||
copy_not_none(self, other, attr)
|
||||
copy_not_none(self, other, 'thumbnail')
|
||||
if other.tags:
|
||||
# Case-insensitive but case preserving merging
|
||||
lotags = [t.lower() for t in other.tags]
|
||||
|
@ -12,6 +12,7 @@ from calibre.ebooks.metadata.book import SERIALIZABLE_FIELDS
|
||||
from calibre.constants import filesystem_encoding, preferred_encoding
|
||||
from calibre.library.field_metadata import FieldMetadata
|
||||
from calibre.utils.date import parse_date, isoformat, UNDEFINED_DATE
|
||||
from calibre.utils.magick import Image
|
||||
from calibre import isbytestring
|
||||
|
||||
# Translate datetimes to and from strings. The string form is the datetime in
|
||||
@ -32,6 +33,14 @@ def encode_thumbnail(thumbnail):
|
||||
'''
|
||||
if thumbnail is None:
|
||||
return None
|
||||
if not isinstance(thumbnail, tuple):
|
||||
try:
|
||||
img = Image()
|
||||
img.load(thumbnail)
|
||||
width, height = img.size
|
||||
thumbnail = (width, height, thumbnail)
|
||||
except:
|
||||
return None
|
||||
return (thumbnail[0], thumbnail[1], b64encode(str(thumbnail[2])))
|
||||
|
||||
def decode_thumbnail(tup):
|
||||
|
@ -1056,7 +1056,10 @@ class DeviceBooksModel(BooksModel): # {{{
|
||||
if hasattr(cdata, 'image_path'):
|
||||
img.load(cdata.image_path)
|
||||
elif cdata:
|
||||
img.loadFromData(cdata)
|
||||
if isinstance(cdata, tuple):
|
||||
img.loadFromData(cdata[2])
|
||||
else:
|
||||
img.loadFromData(cdata)
|
||||
if img.isNull():
|
||||
img = self.default_image
|
||||
data['cover'] = img
|
||||
|
Loading…
x
Reference in New Issue
Block a user