Skip to content

Commit ff52d85

Browse files
committed
Hope I am done this time.
1 parent e8aec3e commit ff52d85

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

thumbs/kfx/reader.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ type Reader struct {
2525
width, height int
2626
fname string
2727
//
28-
asin, cdetype, assetID, bookID, cover string
29-
thumbnail []byte
28+
asin, cdetype, assetID, bookID string
29+
thumbnail []byte
3030
}
3131

3232
func (r *Reader) String() string {
3333
if r == nil {
3434
return "nil"
3535
}
36-
return fmt.Sprintf("asin: %s, cdetype: %s, asset_id: %s, book_id: %s, cover_image: %s", r.asin, r.cdetype, r.assetID, r.bookID, r.cover)
36+
return fmt.Sprintf("asin: %s, cdetype: %s, asset_id: %s, book_id: %s", r.asin, r.cdetype, r.assetID, r.bookID)
3737
}
3838

3939
func NewReader(fname string, w, h int, log *zap.Logger) (*Reader, error) {
@@ -133,6 +133,9 @@ func (r *Reader) extractThumbnail(data []byte) error {
133133
if err := decodeIon(lstProlog, metaEntys[0].data, &bmd); err != nil {
134134
return err
135135
}
136+
137+
// NOTE: we expect a single metadata entity with category "kindle_title_metadata"
138+
var coverResourceName string
136139
if index := slices.IndexFunc(bmd.CategorizedMetadata, func(p properties) bool {
137140
if p.Category == "kindle_title_metadata" {
138141
for _, prop := range p.Metadata {
@@ -146,7 +149,7 @@ func (r *Reader) extractThumbnail(data []byte) error {
146149
case "book_id":
147150
r.bookID = prop.Value.(string)
148151
case "cover_image":
149-
r.cover = prop.Value.(string)
152+
coverResourceName = prop.Value.(string)
150153
}
151154
}
152155
return true
@@ -156,12 +159,12 @@ func (r *Reader) extractThumbnail(data []byte) error {
156159
return errors.New("no kindle book metadata found")
157160
}
158161

159-
if r.cdetype != "EBOK" || len(r.asin) == 0 || len(r.cover) == 0 {
162+
if r.cdetype != "EBOK" || len(r.asin) == 0 || len(coverResourceName) == 0 {
160163
// bail out early - we are only interested in non-personal books
161164
return nil
162165
}
163166

164-
coverEnty, err := entities.getByName(r.cover, symExternalResource)
167+
coverEnty, err := entities.getByName(coverResourceName, symExternalResource)
165168
if err != nil {
166169
return fmt.Errorf("unable to get cover image entity: %w", err)
167170
}

0 commit comments

Comments
 (0)