OMDb 兼容接口

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

更新于 以 Markdown 查看

按 IMDb ID 或片名查找作品

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

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

bashjspyphpgo
curl -sf "https://api.amodb.dev/omdb/?i=tt0137523&plot=short&apikey=$AMODB_KEY"
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);
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
$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;
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文本。
Posterhttps://img.amodb.dev/t/p/w300/ 上的地址。
Ratings带有 Source 和 Value 的对象数组。
Metascore、imdbRating、imdbVotes、imdbID文本,投票数带有千位逗号。
Typemovie 或 series。
DVD、BoxOffice、Production、Website仅限电影。BoxOffice 在已知时有值。DVD、Production 和 Website 始终是 N/A。
totalSeasons仅限剧集,文本形式。剧集响应没有 DVD、BoxOffice、Production 或 Website。
ResponseTrue 或 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!。

curl
curl -sf "https://api.amodb.dev/omdb/?s=Matrix&type=movie&page=1&apikey=$AMODB_KEY"
字段说明
Search最多 10 项的数组,含 Title、Year、imdbID、Type、Poster。
totalResults所有匹配项的总数,字符串形式。
ResponseTrue 或 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 评分,请改用评分接口。

错误

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

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

套餐已结束时返回 HTTP 402。见错误和速率限制。

迁移 OMDb 客户端

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

JavaScript
// 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 风格的调用共用每分钟 20、40 或 120 个请求的同一份额度。

实用说明

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