diff --git a/third-party/libscan/libscan/media/media.c b/third-party/libscan/libscan/media/media.c index a0324cb..2f92d69 100644 --- a/third-party/libscan/libscan/media/media.c +++ b/third-party/libscan/libscan/media/media.c @@ -223,14 +223,10 @@ read_frame(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, AVCodecContext *d void append_tag_meta_if_not_exists(scan_media_ctx_t *ctx, document_t *doc, AVDictionaryEntry *tag, enum metakey key) { - meta_line_t *meta = doc->meta_head; - while (meta != NULL) { - if (meta->key == key) { - CTX_LOG_DEBUGF(doc->filepath, "Ignoring duplicate tag: '%02x=%s' and '%02x=%s'", - key, meta->str_val, key, tag->value); - return; - } - meta = meta->next; + if (meta_contains_key(doc->meta_head, key)) { + CTX_LOG_DEBUGF(doc->filepath, "Ignoring duplicate tag: '%02x=%s'", + key, tag->value); + return; } text_buffer_t tex = text_buffer_create(-1); @@ -445,7 +441,7 @@ int decode_frame_and_save_thumbnail(scan_media_ctx_t *ctx, AVFormatContext *pFor return SAVE_THUMBNAIL_FAILED; } - if (ctx->tesseract_lang != NULL && thumbnail_index == 0) { + if (ctx->tesseract_lang != NULL && thumbnail_index == 0 && !meta_contains_key(doc->meta_head, MetaContent)) { ocr_image(ctx, doc, decoder, frame_and_packet->frame); } diff --git a/third-party/libscan/libscan/util.h b/third-party/libscan/libscan/util.h index e4d9cf8..2f51eb8 100644 --- a/third-party/libscan/libscan/util.h +++ b/third-party/libscan/libscan/util.h @@ -392,4 +392,18 @@ static parse_job_t *create_parse_job(const char *filepath, int mtime, size_t st_ return job; } + +static int meta_contains_key (meta_line_t *meta_head, enum metakey key) { + + meta_line_t *meta = meta_head; + while (meta != NULL) { + if (meta->key == key) { + return TRUE; + } + meta = meta->next; + } + + return FALSE; +} + #endif