手始めに、ePubからメタデータや目次データ、画像データのパスなどを表示するプログラムをサンプルコードなどを参考に書いてみました。
EbookLibというPythonのライブラリを使っています。https://github.com/aerkalov/ebooklib
EbookLibの使い方の参考になれば幸いです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ebooklib | |
from ebooklib import epub, utils | |
book = epub.read_epub('.<.epubファイルのパス>') | |
# メタデータの読み込み | |
# タイトル | |
title = book.get_metadata('DC', 'title') | |
print('タイトル:', title) | |
# 執筆者 | |
creator = book.get_metadata('DC', 'creator') | |
print('執筆者:', creator) | |
# 発行者 | |
publisher = book.get_metadata('DC', 'publisher') | |
print('発行者:', publisher) | |
# 言語 | |
language = book.get_metadata('DC', 'language') | |
print('言語:', language) | |
# 発行日 | |
date = book.get_metadata('DC', 'date') | |
print('発行日:', date) | |
print('==================================') | |
# 目次(Table of contents) | |
for item in book.toc: | |
print(item.title, item.href) | |
print('==================================') | |
# カバー画像 | |
cover_image = list(book.get_items_of_type(ebooklib.ITEM_COVER))[0] | |
print('カバー画像 : ', cover_image.get_name()) | |
print('==================================') | |
# ページ画像 | |
for item in book.get_items_of_type(ebooklib.ITEM_DOCUMENT): | |
body = utils.parse_html_string(item.get_body_content()) | |
for elem in body.iter(): | |
if 'xlink:href' in elem.attrib: | |
print(item.get_name(), ':', elem.attrib.get('xlink:href')) |
出力例: