Skip to content

Commit

Permalink
Rename the cover thumbnail image so it can be cherry-picked later
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmassay committed Dec 13, 2020
1 parent 4478104 commit cc06199
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/kindleunpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc06199

Please sign in to comment.