mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Create thumbnail images on Kindle for KFX fomrat
This commit is contained in:
parent
43242d4f1e
commit
5a4e322ab2
@ -463,18 +463,28 @@ class KINDLE2(KINDLE):
|
|||||||
self.upload_apnx(path, filename, metadata, filepath)
|
self.upload_apnx(path, filename, metadata, filepath)
|
||||||
|
|
||||||
def thumbpath_from_filepath(self, filepath):
|
def thumbpath_from_filepath(self, filepath):
|
||||||
|
from calibre.ebooks.metadata.kfx import (CONTAINER_MAGIC, read_book_key_kfx)
|
||||||
from calibre.ebooks.mobi.reader.headers import MetadataHeader
|
from calibre.ebooks.mobi.reader.headers import MetadataHeader
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
thumb_dir = os.path.join(self._main_prefix, 'system', 'thumbnails')
|
thumb_dir = os.path.join(self._main_prefix, 'system', 'thumbnails')
|
||||||
if not os.path.exists(thumb_dir):
|
if not os.path.exists(thumb_dir):
|
||||||
return
|
return
|
||||||
with lopen(filepath, 'rb') as f:
|
with lopen(filepath, 'rb') as f:
|
||||||
|
is_kfx = f.read(4) == CONTAINER_MAGIC
|
||||||
|
f.seek(0)
|
||||||
|
if is_kfx:
|
||||||
|
uuid,cdetype = read_book_key_kfx(f)
|
||||||
|
else:
|
||||||
mh = MetadataHeader(f, default_log)
|
mh = MetadataHeader(f, default_log)
|
||||||
if mh.exth is None or not mh.exth.uuid or not mh.exth.cdetype:
|
if mh.exth is None:
|
||||||
|
return
|
||||||
|
uuid = mh.exth.uuid
|
||||||
|
cdetype = mh.exth.cdetype
|
||||||
|
if not uuid or not cdetype:
|
||||||
return
|
return
|
||||||
return os.path.join(thumb_dir,
|
return os.path.join(thumb_dir,
|
||||||
'thumbnail_{uuid}_{cdetype}_portrait.jpg'.format(
|
'thumbnail_{uuid}_{cdetype}_portrait.jpg'.format(
|
||||||
uuid=mh.exth.uuid, cdetype=mh.exth.cdetype))
|
uuid=uuid, cdetype=cdetype))
|
||||||
|
|
||||||
def upload_kindle_thumbnail(self, metadata, filepath):
|
def upload_kindle_thumbnail(self, metadata, filepath):
|
||||||
coverdata = getattr(metadata, 'thumbnail', None)
|
coverdata = getattr(metadata, 'thumbnail', None)
|
||||||
|
@ -278,6 +278,17 @@ def dump_metadata(m):
|
|||||||
pprint(d)
|
pprint(d)
|
||||||
|
|
||||||
|
|
||||||
|
def read_book_key_kfx(stream, read_cover=True):
|
||||||
|
' Read the metadata.kfx file that is found in the sdr book folder for KFX files '
|
||||||
|
c = Container(stream.read())
|
||||||
|
m = extract_metadata(c.decode())
|
||||||
|
|
||||||
|
def val(x):
|
||||||
|
return m[x][0] if x in m else ''
|
||||||
|
|
||||||
|
return (val('content_id') or val('ASIN'), val('cde_content_type'))
|
||||||
|
|
||||||
|
|
||||||
def read_metadata_kfx(stream, read_cover=True):
|
def read_metadata_kfx(stream, read_cover=True):
|
||||||
' Read the metadata.kfx file that is found in the sdr book folder for KFX files '
|
' Read the metadata.kfx file that is found in the sdr book folder for KFX files '
|
||||||
c = Container(stream.read())
|
c = Container(stream.read())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user