library-ebooks

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

My Amazon (Kindle) Library Ebook Lookup & Download

我的Amazon (Kindle)图书库电子书查找与下载

Overview

概述

Internal tool to search and download ebooks from my personal Amazon (Kindle) library, i.e., titles I’ve purchased/added to my account (plus any personal documents synced into my library), across available formats.
Note: This skill is meant for my own licensed content. It does not bypass DRM. If a title can’t be downloaded in an accessible file format, use Amazon’s official reading/export options instead.
这是一款内部工具,用于从我的个人Amazon (Kindle)图书库中搜索和下载电子书,即我已购买/添加到账户中的书籍(以及同步到库中的个人文档),支持多种可用格式。
注意:本技能仅适用于我自己的授权内容,不会绕过DRM。如果某本书无法以可访问的文件格式下载,请改用亚马逊官方的阅读/导出选项。

Prerequisites

前提条件

IMPORTANT: Downloads require an Amazon-library access key for my account.
Before using download functionality, the user must:
  1. Have access to their Amazon (Kindle) library (purchased titles / content library)
  2. Set their API key/token:
    export LIBRARY_KEY="your-key"
The key is found in your internal library-proxy/account settings (or whatever system you use to authenticate access to your Amazon library index). Search works without a key, but downloads will fail.
If key is not set: Inform the user they need to set
LIBRARY_KEY
and provide the setup instructions above.
重要提示:下载功能需要我的账户对应的Amazon图书库访问密钥。
使用下载功能前,用户必须:
  1. 能够访问自己的Amazon (Kindle)图书库(已购书籍/内容库)
  2. 设置API密钥/令牌:
    export LIBRARY_KEY="your-key"
该密钥可在内部图书库代理/账户设置中找到(或用于验证Amazon图书库索引访问权限的任何系统)。搜索功能无需密钥,但下载功能会失败。
如果未设置密钥: 告知用户需要设置
LIBRARY_KEY
并提供上述设置说明。

When to Use

使用场景

  • User asks to find/download a book from their Amazon library
  • Need to look up content from a published book they own
  • Searching for a specific edition or format that exists in their library
  • "Get me the PDF of Clean Code (from my Kindle library)"
  • "Find the latest edition of Design Patterns (that I own)"
  • 用户要求从自己的Amazon图书库中查找/下载书籍
  • 需要查找自己拥有的某本出版书籍中的内容
  • 搜索自己库中存在的特定版本或格式的书籍
  • “帮我获取《Clean Code》的PDF版本(来自我的Kindle图书库)”
  • “查找我拥有的《Design Patterns》的最新版本”

Quick Reference

快速参考

TaskCommand
Search
python3 scripts/library.py search "query" --format pdf
Get details
python3 scripts/library.py details <md5>
Download
python3 scripts/library.py download <md5> --output /path/
Verify match
python3 scripts/library.py search "title author" --verify "expected title"
任务命令
搜索
python3 scripts/library.py search "query" --format pdf
获取详情
python3 scripts/library.py details <md5>
下载
python3 scripts/library.py download <md5> --output /path/
验证匹配
python3 scripts/library.py search "title author" --verify "expected title"

Environment Setup

环境设置

bash
export LIBRARY_KEY="your-membership-key"
The key is found in your Amazon library access setup (internal proxy/token settings).
bash
export LIBRARY_KEY="your-membership-key"
该密钥可在你的Amazon图书库访问设置(内部代理/令牌设置)中找到。

Workflow

工作流程

dot
digraph download_flow {
    rankdir=TB;
    node [shape=box];

    search [label="Search by title/author"];
    verify [label="Verify correct book\n(check title, author, year)"];
    multiple [label="Multiple editions?" shape=diamond];
    prefer_recent [label="Prefer most recent\nunless specific edition requested"];
    format_ok [label="Preferred format available?" shape=diamond];
    download [label="Download via fast API"];
    convert [label="Use ebook-extractor\nto convert to text"];

    search -> verify;
    verify -> multiple;
    multiple -> prefer_recent [label="yes"];
    multiple -> format_ok [label="no"];
    prefer_recent -> format_ok;
    format_ok -> download [label="yes"];
    format_ok -> search [label="no - try different format"];
    download -> convert;
}
dot
digraph download_flow {
    rankdir=TB;
    node [shape=box];

    search [label="Search by title/author"];
    verify [label="Verify correct book\n(check title, author, year)"];
    multiple [label="Multiple editions?" shape=diamond];
    prefer_recent [label="Prefer most recent\nunless specific edition requested"];
    format_ok [label="Preferred format available?" shape=diamond];
    download [label="Download via fast API"];
    convert [label="Use ebook-extractor\nto convert to text"];

    search -> verify;
    verify -> multiple;
    multiple -> prefer_recent [label="yes"];
    multiple -> format_ok [label="no"];
    prefer_recent -> format_ok;
    format_ok -> download [label="yes"];
    format_ok -> search [label="no - try different format"];
    download -> convert;
}

Common Patterns

常见模式

Find and download a book

查找并下载书籍

bash
undefined
bash
undefined

Search with format preference

按格式偏好搜索

python3 scripts/library.py search "Clean Code Robert Martin" --format pdf --limit 5
python3 scripts/library.py search "Clean Code Robert Martin" --format pdf --limit 5

Verify it's the right book, get details

验证是否为目标书籍并获取详情

python3 scripts/library.py details adb5293cf369256a883718e71d3771c3
python3 scripts/library.py details adb5293cf369256a883718e71d3771c3

Download

下载

python3 scripts/library.py download adb5293cf369256a883718e71d3771c3 --output ./books/
undefined
python3 scripts/library.py download adb5293cf369256a883718e71d3771c3 --output ./books/
undefined

Handle multiple editions

处理多版本情况

When search returns multiple editions:
  1. Check year - prefer most recent unless user specified edition
  2. Check format - match user's preference (pdf/epub)
  3. Verify author matches exactly
当搜索结果返回多个版本时:
  1. 查看出版年份——除非用户指定版本,否则优先选择最新版本
  2. 查看格式——匹配用户的偏好格式(pdf/epub)
  3. 验证作者是否完全匹配

Format Priority

格式优先级

Default priority when user doesn't specify:
pdf > epub > mobi > azw3 > djvu
当用户未指定格式时,默认优先级为:
pdf > epub > mobi > azw3 > djvu

API Details

API 详情

These endpoints refer to your internal Amazon-library index / proxy service (backed by your own Amazon account/library data), not a public “find-any-book” catalog.
Search endpoint:
https://library-archive.org/search
  • q
    - query string
  • ext
    - format filter (pdf, epub, mobi, azw3, djvu)
  • sort
    -
    year_desc
    for most recent first
Fast download API:
https://library-archive.org/dyn/api/fast_download.json
  • md5
    - book identifier
  • key
    - from LIBRARY_KEY env var
这些端点指向你的内部Amazon图书库索引/代理服务(由你自己的Amazon账户/图书库数据支持),而非公开的“查找任意书籍”目录。
搜索端点:
https://library-archive.org/search
  • q
    - 查询字符串
  • ext
    - 格式筛选(pdf, epub, mobi, azw3, djvu)
  • sort
    -
    year_desc
    表示按年份降序(最新优先)
快速下载API:
https://library-archive.org/dyn/api/fast_download.json
  • md5
    - 书籍标识符
  • key
    - 来自LIBRARY_KEY环境变量

Common Mistakes

常见错误

MistakeFix
Key not setCheck
echo $LIBRARY_KEY
Wrong editionUse
--verify
flag with expected title
Format mismatchExplicitly set
--format
Book not foundTry shorter query, author name variations
错误解决方法
未设置密钥检查
echo $LIBRARY_KEY
的值
版本错误使用
--verify
参数并传入预期书名
格式不匹配显式设置
--format
参数
未找到书籍尝试更短的查询词,或使用作者名的不同变体

Converting to Text

转换为文本

Downloaded files are in their original format (PDF, EPUB, MOBI, etc.). To convert to plain text for analysis or processing, use the ebook-extractor skill after downloading.
Typical workflow:
  1. Download with this skill →
    books/Clean_Code.pdf
  2. Convert with ebook-extractor →
    books/Clean_Code.txt
下载的文件为原始格式(PDF、EPUB、MOBI等)。如需转换为纯文本以进行分析或处理,请在下载后使用ebook-extractor技能。
典型工作流程:
  1. 使用本技能下载 →
    books/Clean_Code.pdf
  2. 使用ebook-extractor转换 →
    books/Clean_Code.txt

Mirror Fallback

镜像备用方案

The script automatically tries multiple mirror domains if the primary domain is unavailable:
  • library-archive.org (primary)
  • library-archive.li
  • library-archive.se
  • library-archive.in
  • library-archive.pm
The first working mirror is cached for the session. You'll see
Using mirror: <domain>
in stderr when a fallback is used.
如果主域名不可用,脚本会自动尝试多个镜像域名:
  • library-archive.org(主域名)
  • library-archive.li
  • library-archive.se
  • library-archive.in
  • library-archive.pm
会话中会缓存第一个可用的镜像。当使用备用镜像时,你会在stderr中看到
Using mirror: <domain>
的提示。

Error Handling

错误处理

  • "Invalid md5" - MD5 hash is malformed or doesn't exist
  • "Not a member" - Key is invalid or expired (i.e., your Amazon-library access token isn’t valid)
  • No results - Broaden search terms, try author-only search
  • "Could not connect to any mirror" - All mirrors are down, try again later
  • "Invalid md5" - MD5哈希格式错误或不存在
  • "Not a member" - 密钥无效或已过期(即你的Amazon图书库访问令牌无效)
  • 无结果 - 放宽搜索词,尝试仅用作者名搜索
  • "Could not connect to any mirror" - 所有镜像均不可用,请稍后再试

Troubleshooting

故障排除

SSL Certificate Error on macOS

macOS上的SSL证书错误

If you see this error:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
This happens because Python can't find the system's CA certificate bundle on macOS.
Quick Fix:
  1. Install certifi:
    bash
    pip3 install certifi
  2. Find your certificate path:
    bash
    python3 -c "import certifi; print(certifi.where())"
  3. Add to
    ~/.zshrc
    :
    bash
    export SSL_CERT_FILE=/path/from/step/2/cacert.pem
  4. Reload shell:
    source ~/.zshrc
Verify it works:
bash
python3 -c "import urllib.request; urllib.request.urlopen('https://google.com')"
Why this happens: macOS uses Keychain for certificates, but Python doesn't use it by default. Framework installs (like
/Library/Frameworks/Python.framework
) often lack certificate configuration.
Do NOT use
verify=False
or
PYTHONHTTPSVERIFY=0
- this disables SSL entirely and is insecure.
如果你遇到以下错误:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
这是因为Python在macOS上无法找到系统的CA证书包。
快速修复:
  1. 安装certifi:
    bash
    pip3 install certifi
  2. 查找证书路径:
    bash
    python3 -c "import certifi; print(certifi.where())"
  3. 添加到
    ~/.zshrc
    bash
    export SSL_CERT_FILE=/path/from/step/2/cacert.pem
  4. 重新加载shell:
    source ~/.zshrc
验证修复效果:
bash
python3 -c "import urllib.request; urllib.request.urlopen('https://google.com')"
原因: macOS使用Keychain管理证书,但Python默认不使用它。框架安装版本(如
/Library/Frameworks/Python.framework
)通常缺少证书配置。
请勿使用
verify=False
PYTHONHTTPSVERIFY=0
——这会完全禁用SSL,存在安全风险。