Example #1
0
def get_acr(book_path, book_fmt):
    if book_fmt == 'KFX':
        from calibre_plugins.kfx_input.kfxlib import YJ_Book

        return getattr(YJ_Book(book_path).get_metadata(), 'asset_id', None)
    else:
        with open(book_path, 'rb') as f:
            return f.read(32).rstrip(b'\x00').decode('utf-8')  # Palm db name
Example #2
0
def parse_kfx(path_of_book):
    from calibre_plugins.kfx_input.kfxlib import YJ_Book

    book = YJ_Book(path_of_book)
    data = book.convert_to_json_content()
    for entry in json.loads(data)['data']:
        yield from parse_text(entry['position'],
                              entry['content'].encode('utf-8'))
Example #3
0
def get_asin(book_path, book_fmt):
    if book_fmt == 'KFX':
        from calibre_plugins.kfx_input.kfxlib import YJ_Book

        return getattr(YJ_Book(book_path).get_metadata(), 'asin', None)
    else:
        with open(book_path, 'rb') as f:
            mu = MetadataUpdater(f)
            if (asin := mu.original_exth_records.get(113)) is None:
                asin = mu.original_exth_records.get(504)
            return asin.decode('utf-8') if asin else None
Example #4
0
def set_kfx_asin(book_path, asin):
    from calibre_plugins.kfx_input.kfxlib import YJ_Book, YJ_Metadata

    book = YJ_Book(book_path)
    md = YJ_Metadata()
    md.asin = asin
    md.cde_content_type = "EBOK"
    book.decode_book(set_metadata=md)
    updated_book = book.convert_to_single_kfx()

    with open(book_path, 'wb') as f:
        f.write(updated_book)
Example #5
0
def parse_kfx(path_of_book):
    from calibre_plugins.kfx_input.kfxlib import YJ_Book

    data = YJ_Book(path_of_book).convert_to_json_content()
    for entry in json.loads(data)['data']:
        yield (entry['content'], entry['position'])