公司与电视网

公司和电视网接口按 ID 返回制片厂或电视网的名称、来源国家和标志路径,路径与 JSON 同 TMDB v3。把 ID 传给 discover 的 with_companies 和 with_networks,即可列出它们的作品。

更新于 以 Markdown 查看

获取公司详情

GET /3/company/{company_id} 返回一家制作公司:名称、来源国家和标志路径。它还带有 description、headquarters、homepage 和 parent_company,但 amodb 将它们留空。ID 就是 TMDB 的公司 ID,所以你之前保存的 ID 仍然有效。

下面的示例读取电影 550 的第一家制作公司,然后加载这家公司。

bashjspyphpgo
COMPANY_ID=$(curl -sf "https://api.amodb.dev/3/movie/550" \
  -H "Authorization: Bearer $AMODB_KEY" | jq '.production_companies[0].id')
curl -sf "https://api.amodb.dev/3/company/$COMPANY_ID" \
  -H "Authorization: Bearer $AMODB_KEY"
const base = 'https://api.amodb.dev/3';
const headers = { Authorization: `Bearer ${process.env.AMODB_KEY}` };

async function get(path) {
  const res = await fetch(base + path, { headers });
  if (!res.ok) throw new Error(`amodb returned ${res.status} for ${path}`);
  return res.json();
}

const movie = await get('/movie/550');
const company = await get(`/company/${movie.production_companies[0].id}`);
console.log(company.name, company.origin_country, company.logo_path);
import os
import requests

BASE = "https://api.amodb.dev/3"
HEADERS = {"Authorization": f"Bearer {os.environ['AMODB_KEY']}"}


def get(path):
    r = requests.get(BASE + path, headers=HEADERS, timeout=10)
    r.raise_for_status()
    return r.json()


movie = get("/movie/550")
company = get(f"/company/{movie['production_companies'][0]['id']}")
print(company["name"], company["origin_country"], company["logo_path"])
<?php
function amodb_get(string $path): array {
    $ch = curl_init('https://api.amodb.dev/3' . $path);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('AMODB_KEY')],
    ]);
    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($status !== 200) {
        throw new RuntimeException("amodb returned $status for $path");
    }
    return json_decode($body, true);
}

$movie = amodb_get('/movie/550');
$company = amodb_get('/company/' . $movie['production_companies'][0]['id']);
echo $company['name'], ' ', $company['origin_country'], PHP_EOL;
package main

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

var client = &http.Client{Timeout: 10 * time.Second}

func get(path string, out any) error {
	req, err := http.NewRequest("GET", "https://api.amodb.dev/3"+path, nil)
	if err != nil {
		return err
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("AMODB_KEY"))
	res, err := client.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		return fmt.Errorf("amodb returned %s for %s", res.Status, path)
	}
	return json.NewDecoder(res.Body).Decode(out)
}

func main() {
	var movie struct {
		Companies []struct {
			ID int `json:"id"`
		} `json:"production_companies"`
	}
	if err := get("/movie/550", &movie); err != nil || len(movie.Companies) == 0 {
		panic("movie has no production companies")
	}
	var company struct {
		Name          string `json:"name"`
		OriginCountry string `json:"origin_country"`
	}
	if err := get(fmt.Sprintf("/company/%d", movie.Companies[0].ID), &company); err != nil {
		panic(err)
	}
	fmt.Println(company.Name, company.OriginCountry)
}

参数

  • company_id路径必填
    数字形式的公司 ID,例如 25。
  • api_key查询二选一
    你的密钥。使用它,或使用 Authorization: Bearer 请求头。

响应字段

字段类型说明
descriptionstring始终为空字符串。
headquartersstring城市或地区。大多数公司为空。
homepagestring网站地址。大多数公司为空。
idinteger公司 ID。
logo_pathstring 或 null拼接到 https://img.amodb.dev/t/p/{size}。
namestring公司名称。
origin_countrystring形如 US 的 ISO 3166-1 代码。可能为空。
parent_companynull始终为 null。amodb 不填写母公司。

示例响应

JSON
{
  "description": "",
  "headquarters": "",
  "homepage": "",
  "id": 25,
  "logo_path": "/nM2MfoMqzJQRiSynsDabOtFKetD.png",
  "name": "20th Century Fox",
  "origin_country": "US",
  "parent_company": null
}

每个公司 ID 都返回同样的结构,例如 /3/company/1 是卢卡斯影业。

获取电视网详情

GET /3/network/{network_id} 返回一个电视网:名称、来源国家、标志路径、headquarters 和 homepage。它没有 description 和 parent_company。请从剧集的 networks 数组中读取电视网 ID。剧集 /3/tv/1399 列出了 ID 为 49 的 HBO。

JSON
{
  "headquarters": "",
  "homepage": "",
  "id": 49,
  "logo_path": "/tuomPhY2UtuPTqqFnKMVHvSb724.png",
  "name": "HBO",
  "origin_country": "US"
}
字段类型说明
headquartersstring大多数电视网为空。
homepagestring大多数电视网为空。
idinteger电视网 ID。
logo_pathstring 或 null标志文件路径。
namestring电视网名称。
origin_countrystringISO 3166-1 代码。像 Netflix 这样的全球流媒体服务为空字符串。

本组接口

所有路径共用基础地址 https://api.amodb.dev/3,认证方式与其他接口相同。

方法和路径返回内容参数
GET /company/{company_id}公司记录company_id
GET /network/{network_id}电视网记录network_id
GET /search/company带有 id、name、logo_path、origin_country 的公司分页列表query、page

amodb 不提供公司和电视网的 alternative_names 或 images 路径。标志就是记录本身的 logo_path。

标志

把标志地址构建为 https://img.amodb.dev/t/p/w185 加上 logo_path。GET /3/configuration 列出标志的尺寸:w92、w154、w185、w300、w500 和 original。完整的尺寸表见图片页。标志文件大多是 PNG,图片文件无需密钥。没有标志的公司,其 logo_path 为 null。

按公司或电视网筛选 discover

公司和电视网 ID 最有用的地方是作为筛选条件。discover 会把一个 ID 变成作品列表。

筛选适用于含义
with_companies/discover/movie 和 /discover/tv由这些公司制作的作品。
with_networks/discover/tv由这些电视网播出的剧集。电影 discover 会忽略它。

用逗号分隔多个 ID 表示全部都要满足,用竖线字符(编码为 %7C)分隔则表示满足任意一个即可。下面的第一个调用按热度排序列出一家公司的电影。第二个调用列出 HBO 播出的剧集。

curl
curl -sf "https://api.amodb.dev/3/discover/movie?with_companies=$COMPANY_ID&sort_by=popularity.desc&page=1" \
  -H "Authorization: Bearer $AMODB_KEY"

curl -sf "https://api.amodb.dev/3/discover/tv?with_networks=49&sort_by=popularity.desc" \
  -H "Authorization: Bearer $AMODB_KEY"

discover 结果在边缘缓存 30 分钟,每页 20 条。完整的筛选列表见发现页。

按名称查找公司

GET /3/search/company?query=lucasfilm 返回分页列表。每一行包含 id、logo_path、name 和 origin_country。结果行并不按精确匹配排序:名为 Lucasfilm Ltd. 的制片厂 ID 是 1,排在第三行,前面有两个相似的名称。取 ID 之前请先比较 name 和 origin_country。查询规则见搜索页。没有电视网搜索路径。

错误

不存在的公司或电视网会返回带有 status_code 34 的 TMDB 错误响应体。其他失败使用同样的响应体。

HTTPstatus_code何时出现
4017密钥缺失或错误。
40236套餐周期已结束。
40434没有该 ID 的公司或电视网,或 ID 不是数字。
40537你发送了写入方法。
42925超过每分钟请求数。请等待 Retry-After 秒。

完整列表见错误,响应头见速率限制。

实用说明

  • 请把公司 id 与名称一起保存。名称会变,ID 不会。
  • 渲染 logo_path 之前先检查它是否为 null。不要依赖 homepage、headquarters 或 description,因为它们是空的。
  • 公司和电视网的详情在边缘缓存 6 小时。img.amodb.dev 上的标志文件缓存 30 天。
  • 电视网是电视领域的概念。要获取它的剧集,请在 /discover/tv 上使用 with_networks,而不是在电影 discover 上。
  • 要按名称查找公司,请使用上面的公司搜索,再按 name 和 origin_country 选出正确的那一行。