moinax / tvdb

PHPTVDB 是一个用于访问电视剧信息的 PHP 库,例如剧集、演员、播出时间和描述。

v1.0.6 2016-10-25 08:14 UTC

This package is not auto-updated.

Last update: 2024-09-11 11:15:52 UTC


README

已弃用 该库是为了与 TVDB API V1 一起使用而实现的。

现在它已被弃用,我建议您寻找另一个实现新 API 的库,例如 https://github.com/adrenth/thetvdb2

Join the chat at https://gitter.im/Moinax/TvDb

基于知名的 phptvdb 库(可在 http://code.google.com/p/phptvdb/ 上找到),这个版本已经完全重构,以使用 PHP 5.3 命名空间提供了更多来自 tvdb api(可在 http://www.thetvdb.com/wiki/index.php/Programmers_API 上找到)的功能,这对于像 Symfony 2 这样的大型项目非常有用。

它做什么

客户端实现了 almost all api 函数 from thetvdb,除了 ZIP 格式下载

用法

use Moinax\TvDb\Client;
$apiKey = 'YOURAPIKEY';

$tvdb = new Client("http://thetvdb.com", $apiKey);
$tvdb->getSerie(75710);

缓存使用

为了节省带宽、减少延迟或两者都要,您可以使用具有缓存功能的 HTTP 客户端。HTTP 客户端使用 If-Modified-Since 头部来获取完整内容,仅当资源已修改时。这节省了带宽。HTTP 客户端还使用一个时间生存参数,以完全避免在资源足够新鲜时发起请求。这减少了延迟。

<?php
use Moinax\TvDb\Http\Cache\FilesystemCache;
use Moinax\TvDb\Http\CacheClient;
use Moinax\TvDb\Client;

$ttl = 600; # how long things should get cached, in seconds.
$apiKey = 'YOURAPIKEY';

$cache = new FilesystemCache(__DIR__ . '/cache');
$httpClient = new CacheClient($cache, $ttl);

$tvdb = new Client("http://thetvdb.com", $apiKey);
$tvdb->setHttpClient($httpClient);

$tvdb->getSerie(75710); //This request will fetch the resource online.
$tvdb->getSerie(75710); //Cache content is fresh enough. We don't make any request.
sleep(600);
$tvdb->getSerie(75710); //The content is not fresh enough. We make a request with
                        //the If-Modified-Since header. The server respond 304 Not
                        //modified, so we load content from the cache.

示例

使用 index.php 来测试 API。如果您想测试,将 settings.php.dist 重命名为 settings.php 并输入由 http://thetvdb.com 提供的自己的 API 密钥。

状态

这个版本相当稳定,已在 http://nextepisode.tv 上投入生产使用。