PT-Gen-External-Api

IMDb + Douban media metadata · Built with Hono + TypeScript · Deployable to Vercel / Netlify / Node.js / Bun / EdgeOne Makers

Runtime: node cache: 300s auth: Bearer proxy: off imdb: on douban cookie: auto PoW

Endpoints

EndpointsParameters
GET /api/v1/imdb/:idFull data by default; full=false to slim down — IMDb Title details
GET /api/v1/imdb/searchq, limit, type(MOVIE/TV/…,可逗号分隔), year_from, year_to, exact — IMDb Search titles
GET /api/v1/douban/:idFull data by default; full=false to slim down — 豆瓣 Title details(纯数字 ID)
GET /api/v1/douban/searchq, 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 }
}
codetype说明
20000OK200 · 成功
40000BAD_REQUEST400 · 参数缺失或非法
40001INVALID_IMDB_ID400 · IMDb ID 格式错误
40002INVALID_DOUBAN_ID400 · 豆瓣 ID 格式错误(需纯数字)
40100UNAUTHORIZED401 · 缺少或无效 Bearer Token
40300FORBIDDEN403 · 当前 Token 无权访问
40301UPSTREAM_BLOCKED403 · 上游拒绝当前出口 IP
40400NOT_FOUND404 · 上游没有该条目
40500METHOD_NOT_ALLOWED405 · 不支持的 HTTP 方法
42900RATE_LIMITED429 · 触发限流
50000INTERNAL_ERROR500 · 未预期的内部错误
50100NOT_IMPLEMENTED501 · 该能力在当前运行时不可用
50200UPSTREAM_ERROR502 · 上游异常状态
50300UPSTREAM_CHALLENGE503 · 持续命中 WAF 挑战
50400UPSTREAM_TIMEOUT504 · 上游超时

Standard response headers

Each response carries tracing, cache and rate-limit metadata.

Header说明
X-Request-Id全链路请求 ID,可透传上游值
X-API-VersionAPI 版本号,用于感知破坏性变更
X-Business-Code数字业务码,与响应体 code 一致
X-Data-Source数据通道:graphql / html(豆瓣接口不返回该头)
X-CacheHIT / 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"