PT-Gen-External-Api
IMDb + Douban media metadata · Built with Hono + TypeScript · Deployable to Vercel / Netlify / Node.js / Bun / EdgeOne Makers
Runtime: bun cache: 600s auth: Bearer proxy: off imdb: on douban cookie: auto PoW
Endpoints
| Endpoints | Parameters |
|---|---|
GET /api/v1/imdb/:id | Full data by default; full=false to slim down — IMDb Title details |
GET /api/v1/imdb/search | q, limit, type(MOVIE/TV/…,可逗号分隔), year_from, year_to, exact — IMDb Search titles |
GET /api/v1/douban/:id | Full data by default; full=false to slim down — 豆瓣 Title details(纯数字 ID) |
GET /api/v1/douban/search | q, limit — 豆瓣 Search titles |
GET /api/v1/egress | — 出口自检:实际出口 IP + IMDb GraphQL 可达性 |
GET /health | — |
Douban details use the mobile subject/{id} API by default (no challenge, fewer round-trips) and fill tags from subject/{id}/tags. Only if that fails does the service fall back to the sec.douban.com PoW challenge (SHA-512 leading zeros, cookie reused for 10 minutes). Data-center egress usually gets no challenge page, so after an 01004 the HTML channel is skipped for 10 minutes; set DOUBAN_BACKEND_URL (node-pt-gen-api) to have a backend fetch it instead.
Authentication
When API_TOKEN is set, every /api/v1 route requires Authorization: Bearer
curl -H "Authorization: Bearer $API_TOKEN" \
"https://your-domain/api/v1/douban/1292052"
Unified response body
Every response follows the same JSON envelope, including errors.
{
"code": 20000,
"message": "OK",
"data": { "success": true, "site": "imdb", "sid": "tt0111161", "title": "The Shawshank Redemption", "year": 1994, "rating": 9.3 },
"error": null,
"meta": {
"requestId": "3f1c…",
"timestamp": "2026-01-01T00:00:00.000Z",
"durationMs": 812,
"version": "2.0.0",
"cached": false,
"source": "graphql"
}
}
code 为数字业务码,规则是 HTTP 状态码 × 100 + 序号:
40001 表示 400 家族的第 1 种情况。因此同一个 HTTP 状态下的不同原因可区分
(40001 是 IMDb ID 格式错、40002 是豆瓣 ID 格式错),
客户端可以针对具体原因处理而不必解析文案。error.type 是对应的字符串符号,
便于日志检索与代码里 switch。同一个码也会写入 X-Business-Code 响应头。
{
"code": 50300,
"message": "IMDb 触发了 WAF 挑战,暂时无法获取数据",
"data": null,
"error": {
"type": "UPSTREAM_CHALLENGE",
"retryable": true,
"details": { "hint": "等待 1-5 分钟后重试…" }
},
"meta": { "requestId": "3f1c…", "durationMs": 25031, "version": "2.0.0", "cached": false }
}
| code | type | 说明 |
|---|---|---|
20000 | OK | 200 · 成功 |
40000 | BAD_REQUEST | 400 · 参数缺失或非法 |
40001 | INVALID_IMDB_ID | 400 · IMDb ID 格式错误 |
40002 | INVALID_DOUBAN_ID | 400 · 豆瓣 ID 格式错误(需纯数字) |
40100 | UNAUTHORIZED | 401 · 缺少或无效 Bearer Token |
40300 | FORBIDDEN | 403 · 当前 Token 无权访问 |
40301 | UPSTREAM_BLOCKED | 403 · 上游拒绝当前出口 IP |
40400 | NOT_FOUND | 404 · 上游没有该条目 |
40500 | METHOD_NOT_ALLOWED | 405 · 不支持的 HTTP 方法 |
42900 | RATE_LIMITED | 429 · 触发限流 |
50000 | INTERNAL_ERROR | 500 · 未预期的内部错误 |
50100 | NOT_IMPLEMENTED | 501 · 该能力在当前运行时不可用 |
50200 | UPSTREAM_ERROR | 502 · 上游异常状态 |
50300 | UPSTREAM_CHALLENGE | 503 · 持续命中 WAF 挑战 |
50400 | UPSTREAM_TIMEOUT | 504 · 上游超时 |
Standard response headers
Each response carries tracing, cache and rate-limit metadata.
| Header | 说明 |
|---|---|
X-Request-Id | 全链路请求 ID,可透传上游值 |
X-API-Version | API 版本号,用于感知破坏性变更 |
X-Business-Code | 数字业务码,与响应体 code 一致 |
X-Data-Source | 数据通道:graphql / html(豆瓣接口不返回该头) |
X-Cache | HIT / MISS / BYPASS |
X-RateLimit-Limit | 每分钟允许的请求数 |
X-RateLimit-Remaining | 当前窗口剩余配额 |
X-RateLimit-Reset | 配额重置时间(Unix 秒) |
Cache-Control | 成功响应 public + s-maxage,便于 CDN 缓存 |
Retry-After | 限流或上游挑战时建议的重试秒数 |
Examples
# IMDb Title details
curl "https://your-domain/api/v1/imdb/tt0111161"
# IMDb Search titles
curl "https://your-domain/api/v1/imdb/search?q=shawshank&limit=10"
# 豆瓣Title details
curl "https://your-domain/api/v1/douban/1292052"
# 豆瓣Search titles
curl "https://your-domain/api/v1/douban/search?q=盗梦空间&limit=5"