From cc061996cebcbde9ed8b80cbe1c0e8c154d7d33e Mon Sep 17 00:00:00 2001 From: Doug Massay Date: Sun, 13 Dec 2020 15:02:31 -0500 Subject: [PATCH] Rename the cover thumbnail image so it can be cherry-picked later --- lib/kindleunpack.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/kindleunpack.py b/lib/kindleunpack.py index 628f256..6c70ee4 100644 --- a/lib/kindleunpack.py +++ b/lib/kindleunpack.py @@ -393,7 +393,7 @@ def processRESC(i, files, rscnames, sect, data, k8resc): return rscnames, k8resc -def processImage(i, files, rscnames, sect, data, beg, rsc_ptr, cover_offset): +def processImage(i, files, rscnames, sect, data, beg, rsc_ptr, cover_offset, thumb_offset): global DUMP # Extract an Image imgtype = get_image_type(None, data) @@ -412,6 +412,8 @@ def processImage(i, files, rscnames, sect, data, beg, rsc_ptr, cover_offset): imgname = "image%05d.%s" % (i, imgtype) if cover_offset is not None and i == beg + cover_offset: imgname = "cover%05d.%s" % (i, imgtype) + if thumb_offset is not None and i == beg + thumb_offset: + imgname = "thumb%05d.%s" % (i, imgtype) print("Extracting image: {0:s} from section {1:d}".format(imgname,i)) outimg = os.path.join(files.imgdir, imgname) with open(pathof(outimg), 'wb') as f: @@ -778,6 +780,12 @@ def process_all_mobi_headers(files, apnxfile, sect, mhlst, K8Boundary, k8only=Fa # processing first part of a combination file end = K8Boundary + # Not sure the try/except is necessary, but just in case + try: + thumb_offset = int(metadata.get('ThumbOffset', ['-1'])[0]) + except: + thumb_offset = None + cover_offset = int(metadata.get('CoverOffset', ['-1'])[0]) if not CREATE_COVER_PAGE: cover_offset = None @@ -827,7 +835,7 @@ def process_all_mobi_headers(files, apnxfile, sect, mhlst, K8Boundary, k8only=Fa rscnames.append(None) else: # if reached here should be an image ow treat as unknown - rscnames, rsc_ptr = processImage(i, files, rscnames, sect, data, beg, rsc_ptr, cover_offset) + rscnames, rsc_ptr = processImage(i, files, rscnames, sect, data, beg, rsc_ptr, cover_offset, thumb_offset) # done unpacking resources # Print Replica