parse cb, finish cbr

This commit is contained in:
simon987 2020-04-03 09:16:37 -04:00
parent a027bcb9eb
commit 0b683bf760
8 changed files with 36 additions and 43 deletions

View File

@ -152,8 +152,7 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc) {
sub_job->ext = (int) strlen(sub_job->filepath);
}
//TODO:
// parse(sub_job);
ctx->parse(sub_job);
}
}

View File

@ -14,6 +14,7 @@ typedef int archive_mode_t;
typedef struct {
archive_mode_t mode;
parse_callback_t parse;
log_callback_t log;
logf_callback_t logf;
store_callback_t store;

View File

@ -7,18 +7,6 @@
#include <stdlib.h>
#include <archive.h>
unsigned int cbr_mime;
unsigned int cbz_mime;
void cbr_init() {
//TODO: get mime str
// cbr_mime = mime_get_mime_by_string(ScanCtx.mime_table, "application/x-cbr");
// cbz_mime = mime_get_mime_by_string(ScanCtx.mime_table, "application/x-cbz");
}
int is_cbr(unsigned int mime) {
return mime == cbr_mime;
}
void parse_cbr(scan_cbr_ctx_t *ctx, vfile_t *f, document_t *doc) {
@ -56,10 +44,7 @@ void parse_cbr(scan_cbr_ctx_t *ctx, vfile_t *f, document_t *doc) {
archive_read_close(rar_in);
archive_read_free(rar_in);
doc->mime = cbz_mime;
//TODO: get mime string
// parse_ebook(out_buf, out_buf_used, doc);
doc->mime = cbr_mime;
parse_ebook_mem(&ctx->ebook_ctx, out_buf, out_buf_used, "application/x-cbz", doc);
doc->mime = ctx->cbr_mime;
free(out_buf);
}

View File

@ -5,14 +5,17 @@
#include "../scan.h"
typedef struct {
scan_ebook_ctx_t ebook_ctx;
unsigned int cbr_mime;
log_callback_t log;
logf_callback_t logf;
store_callback_t store;
} scan_cbr_ctx_t;
void cbr_init();
int is_cbr(unsigned int mime);
__always_inline
static int is_cbr(scan_cbr_ctx_t *ctx, unsigned int mime) {
return mime == ctx->cbr_mime;
}
void parse_cbr(scan_cbr_ctx_t *ctx, vfile_t *f, document_t *doc);

View File

@ -165,10 +165,7 @@ void fill_image(fz_context *fzctx, UNUSED(fz_device *dev),
}
}
void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, document_t *doc) {
size_t buf_len;
void * buf = read_all(f, &buf_len);
void parse_ebook_mem(scan_ebook_ctx_t *ctx, void* buf, size_t buf_len, const char* mime_str, document_t *doc) {
static int mu_is_initialized = 0;
if (!mu_is_initialized) {
@ -188,10 +185,10 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, docum
fz_var(err);
fz_try(fzctx)
{
stream = fz_open_memory(fzctx, buf, buf_len);
fzdoc = fz_open_document_with_stream(fzctx, mime_str, stream);
}
{
stream = fz_open_memory(fzctx, buf, buf_len);
fzdoc = fz_open_document_with_stream(fzctx, mime_str, stream);
}
fz_catch(fzctx)
err = fzctx->error.errcode;
@ -204,7 +201,7 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, docum
char title[4096] = {'\0',};
fz_try(fzctx)
fz_lookup_metadata(fzctx, fzdoc, FZ_META_INFO_TITLE, title, sizeof(title));
fz_lookup_metadata(fzctx, fzdoc, FZ_META_INFO_TITLE, title, sizeof(title));
fz_catch(fzctx)
;
@ -218,7 +215,7 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, docum
int page_count = -1;
fz_var(err);
fz_try(fzctx)
page_count = fz_count_pages(fzctx, fzdoc);
page_count = fz_count_pages(fzctx, fzdoc);
fz_catch(fzctx)
err = fzctx->error.errcode;
@ -249,7 +246,7 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, docum
fz_page *page = NULL;
fz_var(err);
fz_try(fzctx)
page = fz_load_page(fzctx, fzdoc, current_page);
page = fz_load_page(fzctx, fzdoc, current_page);
fz_catch(fzctx)
err = fzctx->error.errcode;
if (err != 0) {
@ -276,12 +273,12 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, docum
fz_var(err);
fz_try(fzctx)
fz_run_page(fzctx, page, dev, fz_identity, NULL);
fz_run_page(fzctx, page, dev, fz_identity, NULL);
fz_always(fzctx)
{
fz_close_device(fzctx, dev);
fz_drop_device(fzctx, dev);
}
{
fz_close_device(fzctx, dev);
fz_drop_device(fzctx, dev);
}
fz_catch(fzctx)
err = fzctx->error.errcode;
@ -325,3 +322,9 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, docum
fz_drop_document(fzctx, fzdoc);
fz_drop_context(fzctx);
}
void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, document_t *doc) {
size_t buf_len;
void * buf = read_all(f, &buf_len);
parse_ebook_mem(ctx, buf, buf_len, mime_str, doc);
}

View File

@ -16,5 +16,6 @@ typedef struct {
} scan_ebook_ctx_t;
void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, document_t *doc);
void parse_ebook_mem(scan_ebook_ctx_t *ctx, void* buf, size_t buf_len, const char* mime_str, document_t *doc);
#endif

View File

@ -53,10 +53,6 @@ typedef int scan_code_t;
#define CTX_LOG_FATALF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_FATAL, fmt, __VA_ARGS__); exit(-1);
#define CTX_LOG_FATAL(filepath, str) ctx->log(filepath, LEVEL_FATAL, str); exit(-1);
typedef void (*store_callback_t)(char *key, size_t key_len, char *buf, size_t buf_len);
typedef void (*logf_callback_t)(char *filepath, int level, char *format, ...);
typedef void (*log_callback_t)(char *filepath, int level, char *str);
// This is written to file as a 16-bit int!
enum metakey {
MetaContent = META_STR(1),
@ -157,3 +153,8 @@ typedef struct parse_job_t {
#include "media/media.h"
#include "ooxml/ooxml.h"
#include "text/text.h"
typedef void (*store_callback_t)(char *key, size_t key_len, char *buf, size_t buf_len);
typedef void (*logf_callback_t)(char *filepath, int level, char *format, ...);
typedef void (*log_callback_t)(char *filepath, int level, char *str);
typedef void (*parse_callback_t)(parse_job_t *job);

View File

@ -7,7 +7,7 @@ scan_code_t parse_text(scan_text_ctx_t *ctx, struct vfile *f, document_t *doc) {
char *buf = malloc(to_read);
int ret = f->read(f, buf, to_read);
if (ret < 0) {
//TODO: log
CTX_LOG_ERRORF(doc->filepath, "read() returned error code: [%d]", ret)
return SCAN_ERR_READ;
}