PHP 实现了 TheTVDb API 的第 4 版。


README

Packagist Minimum PHP Version Build status codecov

这是 thetvdb.com 网站的 API 客户端。它使用的是 theTVDb API 的第 4 版。为了能够访问此 API,您必须首先在 theTVDb 上注册并获取项目密钥。

API 密钥注册

要使用此 PHP 包,您需要从 thetvdb.com 网站请求 API 密钥:[https://thetvdb.com/dashboard/account/apikeys](https://thetvdb.com/dashboard/account/apikeys)。

我们有两种 API 访问模式,两者都提供资金,使我们能够继续运行和改进网站。第一种是我们协商许可模式,允许商业公司与我们协商访问。第二种是用户订阅模式,允许最终用户订阅以访问 API。我们保留在任何时候不预先通知更改我们的接口、费用或许可条款的权利。

要创建 API 密钥,请创建账户并访问仪表板上的 API 密钥页面。

安装

使用 composer 安装此包

$ composer require canihavesomecoffee/thetvdbapi

文档

官方 API 文档可以在以下位置找到:[https://thetvdb.github.io/v4-api/](https://thetvdb.github.io/v4-api/)。

有关 API 的使用示例,请参阅示例文件夹。

API 全局翻译

您可以将主要语言和次要(回退)语言传递给 API 构造函数。

例如,如果您想使用荷兰语,但没有荷兰语翻译,则可以按以下方式设置

$theTVDbAPI = new \CanIHaveSomeCoffee\TheTVDbAPI\TheTVDbAPI("nld", "eng");

默认情况下,主要语言设置为英语,没有回退语言。

身份验证

$theTVDbAPI = new \CanIHaveSomeCoffee\TheTVDbAPI\TheTVDbAPI();

// Obtain a token. Optionally you can pass a user pin through as well.
$token = $theTVDbAPI->authentication()->login($apiKey);

// Set the token
$theTVDbAPI->setToken($token);

路由

TheTVDbAPI 提供了对 API 提供的相同路由的访问。以下列出了几个使用示例

身份验证

$theTVDbAPI->authentication()->login($apiKey);
// or in case it's a project with user-specific subscriptions
$theTVDbAPI->authentication()->login($apiKey, $pin);

语言

$theTVDbAPI->languages()->all();

剧集

$theTVDbAPI->episodes()->simple(6347388);
$theTVDbAPI->episodes()->extended(8366715);
$theTVDbAPI->episodes()->translations(8366715, "nld");

系列

$theTVDbAPI->series()->list();
$theTVDbAPI->series()->simple(280258);
$theTVDbAPI->series()->extended(280258);
$theTVDbAPI->series()->translate(280258);
$theTVDbAPI->series()->episodes(280258); // Paginated
$theTVDbAPI->series()->allEpisodes(280258); // All episodes, translated

搜索

$theTVDbAPI->search()->search("Ideale");
$theTVDbAPI->search()->search("Ideale", ["year" => 2014]);
$theTVDbAPI->search()->search("Ideale Wereld", ["type" => "series"]);

更新

获取最近更新的实体列表

$now = new DateTime();
$now->sub(new DateInterval("PT2H"));
$theTVDbAPI->updates()->query($now);

一些包装方法可用于限制结果

$now = new DateTime();
$now->sub(new DateInterval("PT2H"));
$theTVDbAPI->updates()->fetchSerieUpdates($now);
$theTVDbAPI->updates()->fetchEpisodeUpdates($now);

艺术作品

$theTVDbAPI->artwork()->simple(62001533);
$theTVDbAPI->artwork()->extended(62001533);
$theTVDbAPI->artwork()->statuses();
$theTVDbAPI->artwork()->types();

贡献

虽然目标是提供一个现成的 API,但可能有些内容缺失或过时。如果您认为缺少某些内容,或者您想添加某些内容,请随意提出问题,或者更好的是,提交一个修复或改进的 Pull Request (PR)。我们很乐意接受 PR 以改进此客户端 API。