Metadata-Version: 2.4
Name: ituring-fetch
Version: 0.1.1
Summary: CLI tool to scrape purchased ebooks from ituring.com.cn
Author-email: yms_hi <yms_hi@Outlook.com>
Requires-Python: >=3.11
Requires-Dist: click>=8
Requires-Dist: httpx>=0.27
Requires-Dist: playwright>=1.40
Requires-Dist: rich>=13
Requires-Dist: weasyprint>=68.1
Description-Content-Type: text/markdown

# ituring-fetch

把图灵社区已购电子书扒下来，转成 epub/pdf/html。

## 安装

```bash
git clone <repo>
cd ituring_fetch
uv sync
playwright install chromium   # 或者用系统自带的 Chrome
```

依赖：Python 3.11+、pandoc（epub 格式需要）、Chrome/Chromium。

## 使用

```bash
# 登录（会弹出浏览器窗口）
uv run ituring-fetch login

# 看看登录没
uv run ituring-fetch status

# 列出已购电子书
uv run ituring-fetch list

# 抓取一本书
uv run ituring-fetch fetch 1143 --type=epub
uv run ituring-fetch fetch 1143 --type=pdf
uv run ituring-fetch fetch 1143 --type=html

# 指定输出文件名
uv run ituring-fetch fetch 1143 --type=pdf -o mybook.pdf

# 登出
uv run ituring-fetch logout
```

`list` 输出的第一列就是书籍 ID。

## 调试

出问题时设个环境变量看详细日志：

```bash
ITURING_DEBUG=1 uv run ituring-fetch fetch 1143 --type=pdf
```

会往 stderr 打请求/响应细节。

## 原理

登录时用 Playwright 打开浏览器，你手动登录后，程序从 localStorage 里取出 access token，跟 cookie 一起存到 `~/.ituring/credentials.json`。

后续操作：
- `list` 和书籍信息直接调 `api.ituring.com.cn` 的接口，带 Bearer token
- 章节内容用 Playwright headless 渲染页面，抽 `.article-content` 的 HTML
- 合并所有章节，pandoc 转 epub，Playwright 内置 PDF 引擎出 pdf
