# OMDb 兼容接口

> GET https://api.amodb.dev/omdb/ 响应 OMDb 风格的请求，参数和字段名都相同。用 i 按 IMDb ID 查找，用 t 按片名查找，或用 s 搜索。海报指向 img.amodb.dev。只支持 r=json，只提供电影和剧集。

## 接口

`GET /omdb/`

```bash
curl "https://api.amodb.dev/omdb/?i=tt0137523&plot=short&apikey=$AMODB_KEY"
```

响应:

```json
{
  "Title": "Fight Club",
  "Year": "1999",
  "Rated": "R",
  "Released": "15 Oct 1999",
  "Runtime": "139 min",
  "Genre": "Crime, Drama, Thriller",
  "Director": "David Fincher",
  "Writer": "Chuck Palahniuk, Jim Uhls",
  "Actors": "Brad Pitt, Edward Norton, Meat Loaf",
  "Plot": "A nameless first-person narrator attends support groups in an attempt to subdue his emotional state and relieve his insomniac state.",
  "Language": "English",
  "Country": "United States, Germany",
  "Awards": "Nominated for 1 Oscar. 12 wins & 38 nominations total",
  "Poster": "https://img.amodb.dev/t/p/w300/pfPob0mrC1KiPVP9NXZnqvpks9u.jpg",
  "Ratings": [
    {
      "Source": "Internet Movie Database",
      "Value": "8.8/10"
    },
    {
      "Source": "Rotten Tomatoes",
      "Value": "81%"
    },
    {
      "Source": "Metacritic",
      "Value": "67/100"
    }
  ],
  "Metascore": "67",
  "imdbRating": "8.8",
  "imdbVotes": "2,669,989",
  "imdbID": "tt0137523",
  "Type": "movie",
  "DVD": "N/A",
  "BoxOffice": "$38,003,039",
  "Production": "N/A",
  "Website": "N/A",
  "Response": "True"
}
```

## 按 IMDb ID 或片名查找作品

`GET https://api.amodb.dev/omdb/` 以扁平 JSON 返回一部作品，字段名与 OMDb 相同。用 `i` 传入 `tt0137523` 这样的 IMDb ID，或用 `t` 传入片名。认证方式是 `apikey` 查询参数。成功时响应中的 `Response` 为 `True`，失败时为 `False`。

示例按 IMDb ID 加载《搏击俱乐部》，当 `Response` 为 `False` 时用 OMDb 的错误文本停止。

```bash
curl -sf "https://api.amodb.dev/omdb/?i=tt0137523&plot=short&apikey=$AMODB_KEY"
```

```js
const params = new URLSearchParams({ i: 'tt0137523', plot: 'short', apikey: process.env.AMODB_KEY });
const res = await fetch(`https://api.amodb.dev/omdb/?${params}`);
if (!res.ok) throw new Error(`amodb returned ${res.status}`);
const data = await res.json();
if (data.Response === 'False') throw new Error(data.Error);
console.log(data.Title, data.Year, data.imdbRating);
```

```python
import os
import requests

r = requests.get(
    "https://api.amodb.dev/omdb/",
    params={"i": "tt0137523", "plot": "short", "apikey": os.environ["AMODB_KEY"]},
    timeout=10,
)
r.raise_for_status()
data = r.json()
if data["Response"] == "False":
    raise SystemExit(data["Error"])
print(data["Title"], data["Year"], data["imdbRating"])
```

```php
<?php
$query = http_build_query(['i' => 'tt0137523', 'plot' => 'short', 'apikey' => getenv('AMODB_KEY')]);
$ch = curl_init('https://api.amodb.dev/omdb/?' . $query);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 200) {
    throw new RuntimeException("amodb returned $status");
}
$data = json_decode($body, true);
if ($data['Response'] === 'False') {
    throw new RuntimeException($data['Error']);
}
echo $data['Title'], ' ', $data['Year'], ' ', $data['imdbRating'], PHP_EOL;
```

```go
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"
	"os"
	"time"
)

type Title struct {
	Title      string `json:"Title"`
	Year       string `json:"Year"`
	ImdbRating string `json:"imdbRating"`
	Response   string `json:"Response"`
	Error      string `json:"Error"`
}

func main() {
	q := url.Values{"i": {"tt0137523"}, "plot": {"short"}, "apikey": {os.Getenv("AMODB_KEY")}}
	client := &http.Client{Timeout: 10 * time.Second}
	res, err := client.Get("https://api.amodb.dev/omdb/?" + q.Encode())
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		panic(res.Status)
	}
	var t Title
	if err := json.NewDecoder(res.Body).Decode(&t); err != nil {
		panic(err)
	}
	if t.Response == "False" {
		panic(t.Error)
	}
	fmt.Println(t.Title, t.Year, t.ImdbRating)
}
```

### 参数

| 参数       | 位置 | 必填             | 说明                                           |
| -------- | -- | -------------- | -------------------------------------------- |
| `apikey` | 查询 | 是              | 你的 amodb 密钥。                                 |
| `i`      | 查询 | `i`、`t`、`s` 之一 | 作品的 IMDb ID：`tt` 加 7 到 9 位数字，例如 `tt0137523`。 |
| `t`      | 查询 | `i`、`t`、`s` 之一 | 要查找的片名，返回最佳匹配。                               |
| `s`      | 查询 | `i`、`t`、`s` 之一 | 至少 3 个字母的搜索文本，返回列表。                          |
| `type`   | 查询 | 否              | `movie` 或 `series`。`episode` 查不到任何内容。        |
| `y`      | 查询 | 否              | 上映年份。                                        |
| `plot`   | 查询 | 否              | `short` 或 `full`。默认 `short`。                 |
| `page`   | 查询 | 否              | 搜索结果的页码，1 到 100。与 `s` 一起使用。                  |
| `r`      | 查询 | 否              | 只支持 `json`。其他任何值都返回 HTTP 400。                |

原版 OMDb API 的 `Season`、`Episode`、`callback` 和 `v` 参数不受支持，会被忽略。

### 响应字段

| 字段                                            | 说明                                                                |
| --------------------------------------------- | ----------------------------------------------------------------- |
| `Title`、`Year`、`Rated`、`Released`、`Runtime`   | 文本。`Released` 形如 `15 Oct 1999`。                                   |
| `Genre`、`Director`、`Writer`、`Actors`          | 用逗号分隔的名称。                                                         |
| `Plot`、`Language`、`Country`、`Awards`          | 文本。                                                               |
| `Poster`                                      | `https://img.amodb.dev/t/p/w300/` 上的地址。                           |
| `Ratings`                                     | 带有 `Source` 和 `Value` 的对象数组。                                      |
| `Metascore`、`imdbRating`、`imdbVotes`、`imdbID` | 文本，投票数带有千位逗号。                                                     |
| `Type`                                        | `movie` 或 `series`。                                               |
| `DVD`、`BoxOffice`、`Production`、`Website`      | 仅限电影。`BoxOffice` 在已知时有值。`DVD`、`Production` 和 `Website` 始终是 `N/A`。 |
| `totalSeasons`                                | 仅限剧集，文本形式。剧集响应没有 `DVD`、`BoxOffice`、`Production` 或 `Website`。      |
| `Response`                                    | `True` 或 `False`，始终是字符串。                                          |

字段遵循 OMDb，所以现有的 OMDb 解析器除了基础 URL 之外无需任何改动。

### 示例响应

```json
{
  "Title": "Fight Club",
  "Year": "1999",
  "Rated": "R",
  "Released": "15 Oct 1999",
  "Runtime": "139 min",
  "Genre": "Crime, Drama, Thriller",
  "Director": "David Fincher",
  "Writer": "Chuck Palahniuk, Jim Uhls",
  "Actors": "Brad Pitt, Edward Norton, Meat Loaf",
  "Plot": "A nameless first-person narrator attends support groups in an attempt to subdue his emotional state and relieve his insomniac state.",
  "Language": "English",
  "Country": "United States, Germany",
  "Awards": "Nominated for 1 Oscar. 12 wins & 38 nominations total",
  "Poster": "https://img.amodb.dev/t/p/w300/qkrH7rjYKU4KOwwIl6wF6H3ISvm.jpg",
  "Ratings": [
    { "Source": "Internet Movie Database", "Value": "8.8/10" },
    { "Source": "Rotten Tomatoes", "Value": "81%" },
    { "Source": "Metacritic", "Value": "67/100" }
  ],
  "Metascore": "67",
  "imdbRating": "8.8",
  "imdbVotes": "2,669,989",
  "imdbID": "tt0137523",
  "Type": "movie",
  "DVD": "N/A",
  "BoxOffice": "$38,003,039",
  "Production": "N/A",
  "Website": "N/A",
  "Response": "True"
}
```

对于《火线》（`i=tt0306414`）这样的剧集，响应以 `"Type": "series"`、`"totalSeasons": "5"` 和 `"Response": "True"` 结尾。

## 用 s 搜索

发送 `s` 可以得到列表而不是单个作品。每页 10 项，`totalResults` 以字符串给出总数。请求 `page=2` 得到第 11 到 20 项，一直读到 `totalResults` 项为止。超出最后一页会返回 `Movie not found!`。

```bash
curl -sf "https://api.amodb.dev/omdb/?s=Matrix&type=movie&page=1&apikey=$AMODB_KEY"
```

| 字段             | 说明                                                    |
| -------------- | ----------------------------------------------------- |
| `Search`       | 最多 10 项的数组，含 `Title`、`Year`、`imdbID`、`Type`、`Poster`。 |
| `totalResults` | 所有匹配项的总数，字符串形式。                                       |
| `Response`     | `True` 或 `False`。                                     |

```json
{
  "Search": [
    {
      "Title": "The Matrix",
      "Year": "1999",
      "imdbID": "tt0133093",
      "Type": "movie",
      "Poster": "https://img.amodb.dev/t/p/w300/kEDbym5htJgDQNenjUtSJxAHysB.jpg"
    },
    {
      "Title": "The Matrix Reloaded",
      "Year": "2003",
      "imdbID": "tt0234215",
      "Type": "movie",
      "Poster": "https://img.amodb.dev/t/p/w300/d0xVNNxIYxId2qHkqpgE39soOvD.jpg"
    }
  ],
  "totalResults": "20",
  "Response": "True"
}
```

列表缩减为 10 项中的 2 项。

## 读取 Ratings 数组

`Ratings` 为每个来源保存一个对象，各含 `Source` 和 `Value`，`Value` 是 `8.8/10` 这样的文本。来源有 `Internet Movie Database`、`Rotten Tomatoes` 和 `Metacritic`，只列出该作品已知的。扁平字段 `imdbRating`、`imdbVotes` 和 `Metascore` 重复了其中一部分数据。如果需要数字，请按斜杠拆分 `Value`。想要带类型的数字，以及 Kinopoisk 和 TMDB 评分，请改用[评分](https://amodb.dev/zh/ratings/)接口。

## 错误

查找失败会返回 `{"Response":"False","Error":"..."}`。其中多数伴随 HTTP 200，所以请读取 `Error` 并依据文本分支，而不是只看 HTTP 状态。

| `Error` 文本                                  | HTTP | 何时出现                                          |
| ------------------------------------------- | ---- | --------------------------------------------- |
| `Movie not found!`                          | 200  | 没有作品匹配 `t`，`i` 的值有效但未知，或搜索页码超出最后一页。           |
| `Incorrect IMDb ID.`                        | 200  | `i` 的值不具备 IMDb ID 的格式。                        |
| `Too many results.`                         | 200  | 搜索文本少于 3 个字母，或匹配的作品太多。请加长文本，或加上 `type` 或 `y`。 |
| `Something went wrong.`                     | 200  | 没有发送 `i`、`t` 和 `s` 中的任何一个。                    |
| `Only r=json is supported.`                 | 400  | `r` 被设为 `json` 之外的值。                          |
| `No API key provided.` 或 `Invalid API key!` | 401  | `apikey` 缺失或错误。                               |
| `Request limit reached!`                    | 429  | 超过每分钟请求数。请等待 `Retry-After` 秒。                 |

套餐已结束时返回 HTTP 402。见[错误](https://amodb.dev/zh/errors/)和[速率限制](https://amodb.dev/zh/rate-limits/)。

## 迁移 OMDb 客户端

迁移只需两处修改：基础 URL 和密钥。请求中的其他内容都不变。

```js
// Before: the base URL and key of your current OMDb setup.
// After:
const OMDB_BASE = 'https://api.amodb.dev/omdb/';
const OMDB_KEY = process.env.AMODB_KEY;
```

如果你发送了 `r=xml`，请删除它。读取剧集、`Season` 或 `callback` 的客户端，这些部分需要另找数据来源。速率限制按密钥计算，所以 OMDb 风格的调用和 [TMDB 风格的调用](https://amodb.dev/zh/movies/)共用每分钟 20、40 或 120 个请求的同一份额度。

## 实用说明

- 把每个值都当作文本。请自己转换 `Year`、`imdbRating` 和 `totalResults`，并把 `N/A` 视为缺失。
- 只有在显示完整剧情时才使用 `plot=full`。`short` 能让响应更小。
- 按 `i` 或 `t` 的查找比按 `s` 的搜索缓存更久，所以重复的查找会返回已存储的结果。
- 要从 IMDb ID 得到 TMDB ID，请调用[按外部 ID 查找](https://amodb.dev/zh/find-by-external-id/)。
- 海报是 `w300`。其他尺寸请根据 TMDB 风格的 `poster_path` 和[图片](https://amodb.dev/zh/images-api/)的尺寸列表自己构建地址。
- 请把密钥留在服务器上。页面 URL 中的 `apikey` 对每位访客都可见。

## 常见问题

### OMDb 接口需要另一个密钥吗？

不需要。同一个 32 位密钥可用于 TMDB 风格的路径和 OMDb 接口。像现在的 OMDb 客户端那样，把它作为 apikey 查询参数发送即可。

### 可以请求 XML 吗？

不可以。只提供 r=json。带有 r=xml 的请求返回 HTTP 400，文本为 Only r=json is supported.，所以切换基础 URL 之前请删除该参数或把它设为 json。

### 为什么所有值都是字符串？

响应体与 OMDb 逐字段一致，而该格式把 Year、imdbRating 和 totalResults 等数字以字符串发送。请在你自己的代码中转换。未知的值显示为 N/A。

### 支持季和集吗？

不支持。Season、Episode、callback 和 v 参数会被忽略，type=episode 查不到任何内容。剧集响应有 totalSeasons，但没有单集数据。季请使用 TMDB 风格的 tv 接口。

### 海报从哪里来？

Poster 字段是 img.amodb.dev 上尺寸为 w300 的地址。图片无需密钥，所以你可以把地址直接放进 img 标签。

## 相关页面

- [OMDb API 替代方案](https://amodb.dev/zh/omdb-api-alternative/): 碰到 OMDb 每日上限，或需要一次调用返回多条记录？amodb 可响应 OMDb 风格的请求，并用同一个密钥提供 TMDB v3 接口。
- [按外部 ID 查找](https://amodb.dev/zh/find-by-external-id/): 用 TMDB find 接口按 IMDb、TVDB、Wikidata 或 Kinopoisk ID 查找电影、剧集或人物，并读取外部 ID。
- [电影详情 API](https://amodb.dev/zh/movies/): 路径和 JSON 与 TMDB v3 相同的电影详情 API：按 ID 取电影，用 append_to_response 加入演职员和评分，支持 14 种语言。
- [图片 API 与图片主机](https://amodb.dev/zh/images-api/): 采用 TMDB v3 路径的电影图片 API：列出作品的海报、背景图、标志和剧照，再从 img.amodb.dev 以 10 种尺寸无密钥加载。
- [认证](https://amodb.dev/zh/authentication/): 如何发送 amodb 密钥：查询中的 api_key、Bearer 请求头，或 OMDb 的 apikey。含密钥格式、保管和 401 错误。
- [快速开始](https://amodb.dev/zh/quickstart/): 发出第一次 amodb 调用：获取密钥，用 curl、JavaScript、Python、PHP 或 Go 请求电影详情，再加载海报。

更新于: 2026-10-18. Source: https://amodb.dev/zh/omdb-endpoint/
