adrenth/thetvdb

此包已被废弃,不再维护。作者建议使用 adrenth/thetvdb2 包。

thetvdb.com 的 API 客户端

0.1.8 2016-02-25 12:59 UTC

This package is auto-updated.

Last update: 2020-05-23 14:41:44 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight

这是一个 thetvdb.com 网站的 API 客户端。它使用公开可用的 XML 订阅。

API 密钥注册

要使用此 PHP 包,您需要从 thetvdb.com 网站请求 API 密钥: http://thetvdb.com/?tab=apiregister

请遵循以下指南

  • 如果您将在商业产品或网站上使用 API 信息,您必须发送电子邮件至 scott@thetvdb.com 并在开始使用 API 之前等待授权。但是,您可以在公开发布之前使用 API 进行开发和测试。
  • 如果您有一个公开可用的程序,您必须通知您的用户此网站,并要求他们在可能的情况下帮助贡献信息和艺术品。
  • 您必须熟悉我们的数据结构,这些结构在维基文档中有详细说明。
  • 您必须不要对每个用户进行比必要更多的请求。这意味着不要下载我们的所有内容(如果需要,我们将提供数据库)。请与我们的服务器友好相处。
  • 您必须不要在不使用文档化的 API 方法的情况下直接访问我们的数据。
  • 您必须保持账户信息中的电子邮件地址最新且准确,以防我们需要联系您有关您的密钥(我们像其他人一样讨厌垃圾邮件,所以我们永远不会将您的电子邮件地址发布给任何人)。
  • 请随时联系我们,请求对我们网站和/或 API 的更改。我们将愉快地考虑所有合理的建议。

来源:thetvdb.com

API v2

还有一个 API 的第二个版本,我也为其创建了一个 PHP 客户端。请参阅 https://github.com/adrenth/thetvdb2

安装

使用 composer 安装此包

$ composer require adrenth/thetvdb

用法

创建一个客户端实例

$apiKey = 'yourapikey';
$cache = new \Doctrine\Common\Cache\FilesystemCache('path/to/cache');
$client = new Client($cache, $apiKey);

缓存

$client->setCacheTtl(3600); // in seconds

语言

$language = new Language('nl');

echo $language->getCode();
// 'nl'
echo $language->getLabel();
// 'Nederlands'

$language = $client->getUserPreferredLanguage($accountId);

管理用户评分

// Returns a UserFavoritesResponse
$favorites = $client->getUserFavorites($accountId);
$seriesIds = $favorites->getSeriesIds();

$favorites = $client->addUserFavorite($accountId, $seriesId);
$seriesIds = $favorites->getSeriesIds();

$favorites = $client->removeUserFavorite($accountId, $seriesId);
$seriesIds = $favorites->getSeriesIds();

管理用户评分

$rating = $client->addUserRatingForEpisode($accountId, $episodeId, $rating);
$rating = $client->removeUserRatingForEpisode($accountId, $episodeId);
$rating = $client->addUserRatingForSeries($accountId, $seriesId, $rating);
$rating = $client->removeUserRatingForSeries($accountId, $seriesId);

echo $rating->getUserRating();
// 7
echo $rating->getCommunityRating();
// 7.65

搜索/获取剧集

$language = new Language('nl');
$response = $client->getSeries('Ray Donovan', $language, $accountId);
$seriesCollection = $response->getSeries();

foreach ($seriesCollection as $series) {
	echo $series->getName();
}

$response = $client->getSeriesByImdbId('tt0290978');
$response = $client->getSeriesByImdbId('tt0290978', new \Adrenth\Thetvdb\Language('de'));
$response = $client->getSeriesByZap2itId('EP01579745', new \Adrenth\Thetvdb\Language('nl'));

缓存

此包需要一个 Doctrine Cache 实例。要禁用缓存(我永远不会推荐!),只需提供 VoidCacheArrayCache 实例。

有关 Doctrine Cache 的更多信息,请访问 https://github.com/doctrine/cache

贡献

请为此包做出贡献,使其更加完善。