Skip to main content

Extract text and images from EPUB files and reconstruct as Markdown

Project description

epub-content-extractor

EPUBファイルのテキストと画像を抽出し、Markdownファイル群として出力するCLIツール。FastMCPによるMCPサーバとしても動作します。

必要なもの

MCPクライアント別の設定

Claude Code

  1. 以下のコマンドを実行します。

    claude mcp add epub-content-extractor uvx epub-content-extractor
    

    または プロジェクトルートに .mcp.json を作成し、以下を記述します。

    {
      "mcpServers": {
        "epub-content-extractor": {
          "command": "uvx",
          "args": ["epub-content-extractor"]
        }
      }
    }
    
  2. Claude Code を再起動します。


Cursor

  1. プロジェクトルートに .cursor/mcp.json を作成します(グローバル設定の場合は ~/.cursor/mcp.json)。

  2. 以下の内容を記述します。

    {
      "mcpServers": {
        "epub-content-extractor": {
          "command": "uvx",
          "args": ["epub-content-extractor"]
        }
      }
    }
    
  3. Cursor を再起動します。


VS Code (GitHub Copilot)

  1. プロジェクトルートに .vscode/mcp.json を作成します。

  2. 以下の内容を記述します。

    {
      "servers": {
        "epub-content-extractor": {
          "command": "uvx",
          "args": ["epub-content-extractor"]
        }
      }
    }
    
  3. VS Code を再起動し、Copilot Chat から MCP ツールが利用可能になっていることを確認します。

CLIとして直接使う(uvx経由)

注意: uvx epub-content-extractor は MCP サーバーを起動するコマンドです。ヘルプは表示されません。 CLI ツールのエントリポイントは epub-extract です。uvx 経由では --from フラグを使って以下のように実行します。

uvx --from epub-content-extractor epub-extract INPUT.epub [OUTPUT_DIR]
  • INPUT.epub: 入力EPUBファイルのパス(必須)
  • OUTPUT_DIR: 出力先ディレクトリ(省略時は {epub_dir}/{epub_stem}/

出力例

output/
├── chapter_001.md
├── chapter_002.md
└── images/
    └── fig001.png

.md ファイルはYAML Front Matter付き:

---
title: "書籍タイトル"
authors:
  - "著者名"
language: ja
publisher: "出版社"
identifier: "urn:isbn:..."
epub_layout: fixed-layout
page_progression_direction: rtl
chapter_title: "第1章"
spine_order: 1
---

ツールリファレンス

extract_epub

EPUBの全コンテンツをMarkdownファイルとして出力します。

パラメータ

パラメータ デフォルト 説明
source string 必須 EPUBファイルの絶対パスまたは相対パス
output_dir string null 出力先ディレクトリ(省略時は {epub_dir}/{epub_stem}/

レスポンス

{
  "output_dir": "/path/to/output",
  "files": [
    "/path/to/output/chapter_001.md",
    "/path/to/output/chapter_002.md"
  ],
  "chapters": 2
}

get_epub_metadata

EPUBのメタデータを取得します(ファイル出力なし)。

パラメータ

パラメータ デフォルト 説明
source string 必須 EPUBファイルの絶対パスまたは相対パス

レスポンス

{
  "title": "書籍タイトル",
  "authors": ["著者名"],
  "language": "ja",
  "layout": "fixed-layout",
  "page_progression_direction": "rtl",
  "publisher": "出版社",
  "identifier": "urn:isbn:..."
}

list_epub_spine

スパインアイテム(章)を読み順で一覧表示します(ファイル出力なし)。

パラメータ

パラメータ デフォルト 説明
source string 必須 EPUBファイルの絶対パスまたは相対パス

レスポンス

{
  "spine": [
    {
      "id": "chapter01",
      "href": "OEBPS/chapter01.xhtml",
      "title": "第1章",
      "order": 1
    }
  ]
}

対応EPUBレイアウト

  • リフロー型: HTML構造から自然な読み順でテキスト抽出
  • フィックス型: position: absolute CSS座標によるソート(RTL/LTR対応)
  • AHL型: スパインアイテムごとにフィックス型/リフロー型を判定

開発者向け

開発環境のセットアップ

uv sync --group dev

テスト・Lint

uv run pytest tests/ -v
uv run ruff check .

TestPyPI での動作確認

リリース前に TestPyPI へアップロードされたパッケージを uvx で検証する。

TestPyPI には lxml>=5.0 が存在しないため、--extra-index-url で PyPI を補助インデックスとして追加し、--index-strategy unsafe-best-match で全インデックスから最適バージョンを選択させる必要がある。

# MCP サーバーとして起動確認
uvx --from "epub-content-extractor" \
    --index "https://test.pypi.org/simple/" \
    --extra-index-url "https://pypi.org/simple/" \
    --index-strategy unsafe-best-match \
    epub-content-extractor

# CLI ツールとして動作確認
uvx --from "epub-content-extractor" \
    --index "https://test.pypi.org/simple/" \
    --extra-index-url "https://pypi.org/simple/" \
    --index-strategy unsafe-best-match \
    epub-extract <EPUBファイルパス>

# バージョンを指定する場合
uvx --from "epub-content-extractor==0.2.2" \
    --index "https://test.pypi.org/simple/" \
    --extra-index-url "https://pypi.org/simple/" \
    --index-strategy unsafe-best-match \
    epub-content-extractor

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epub_content_extractor-0.2.6.tar.gz (160.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

epub_content_extractor-0.2.6-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file epub_content_extractor-0.2.6.tar.gz.

File metadata

  • Download URL: epub_content_extractor-0.2.6.tar.gz
  • Upload date:
  • Size: 160.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for epub_content_extractor-0.2.6.tar.gz
Algorithm Hash digest
SHA256 b7d1eedc8a7ff8462154fd3fe3a3b62bf68c0e608efb832fb32b4dc511422a49
MD5 9d7def843193d72ade61469796563491
BLAKE2b-256 4c0769ae7b8452aae610a61a65685e18c08b4a978cc2629a88018dae2af05574

See more details on using hashes here.

Provenance

The following attestation bundles were made for epub_content_extractor-0.2.6.tar.gz:

Publisher: publish.yml on HizZaniya/epub-content-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epub_content_extractor-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for epub_content_extractor-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 abcd18cdab1b368d5b9401307fd1a6eb3b2dce8fe7ec6cf6465199318bd65a37
MD5 7d4382dde5ca1e678407840577beaa5f
BLAKE2b-256 81c78cca7a73fa33559fe23b0f7f981d829fe8006d88005c96e1b1b1f77e3287

See more details on using hashes here.

Provenance

The following attestation bundles were made for epub_content_extractor-0.2.6-py3-none-any.whl:

Publisher: publish.yml on HizZaniya/epub-content-extractor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page