diff --git a/src/calibre/ebooks/metadata/book/__init__.py b/src/calibre/ebooks/metadata/book/__init__.py index e7f58ce858..84a88606f2 100644 --- a/src/calibre/ebooks/metadata/book/__init__.py +++ b/src/calibre/ebooks/metadata/book/__init__.py @@ -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( diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index f2031afd0e..7812f81180 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -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] diff --git a/src/calibre/ebooks/metadata/book/json_codec.py b/src/calibre/ebooks/metadata/book/json_codec.py index ea0de07342..51b9722803 100644 --- a/src/calibre/ebooks/metadata/book/json_codec.py +++ b/src/calibre/ebooks/metadata/book/json_codec.py @@ -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): diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index b81628cd27..4e8e9a10bd 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -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