marcwelp/laravel-tvdb

为 Laravel 提供的 TVDB API 封装。

v1.0.5 2020-12-29 14:31 UTC

This package is not auto-updated.

Last update: 2024-09-30 09:44:02 UTC


README

Latest Version on Packagist Quality Score Total Downloads

marcwelp/laravel-tvdb 包提供易于使用的函数,帮助您与 TVDB API 进行交互。

安装

您可以通过 composer 安装此包

composer require marcwelp/laravel-tvdb

使用以下 artisan 命令发布配置文件

php artisan vendor:publish --provider="marcwelp\TVDB\TVDBServiceProvider"

配置

上面的发布命令将发布一个 tvdb.php 配置文件到您的 Laravel 配置文件夹。请确保使用您的个人 API 详细信息调整这些值。
建议您不要直接修改配置文件,而是在项目的 .env 文件中定义您的 API 详细信息,如下所示

TVDB_API_KEY=ETIO2B4NO372XP0X
TVDB_USER_KEY=XXUXCXR8LYXUNM7P
TVDB_USERNAME=marcwelp

别忘了清除配置缓存。(php artisan config:cache

使用

通过 ID 查找系列

getSeries 函数返回一个 Series 对象。

// Find a series by its TVDB ID
// ID: 73739 (Lost)
$result = TVDB::getSeries(73739);

echo $result->title; // "Lost"

搜索系列

search 函数返回一系列 Series 对象的数组,如果没有找到结果则返回空数组。

// Search by title
$results = TVDB::search('Planet Earth');

// Search by IMDB ID
$results = TVDB::search(['imdbId' => 'tt5491994']);

// Search by zap2it ID
$results = TVDB::search(['zap2itId' => 'SH303483']);

获取系列图片

要获取一个系列的图片数组,您需要指定要检索的图片类型。以下列出了可用的类型。

/*
 * Get the images of the series by TVDB ID
 * ID: 73739 (Lost)
 *
 * Available image types:
 * - TVDB::IMAGE_TYPE_FANART
 * - TVDB::IMAGE_TYPE_POSTER
 * - TVDB::IMAGE_TYPE_SEASON
 * - TVDB::IMAGE_TYPE_SERIES
 */
$images = TVDB::getSeriesImages(73739, TVDB::IMAGE_TYPE_POSTER);

// Or get the images directly from a "Series" object
$series = TVDB::getSeries(73739);
$images = $series->getImages(TVDB::IMAGE_TYPE_FANART);

获取系列演员

以下选项可用于检索演员数组。

/*
 * Get the actors of the series by TVDB ID
 * ID: 73739 (Lost)
 */
$actors = TVDB::getSeriesActors(73739);

// Or get the actors directly from a "Series" object
$series = TVDB::getSeries(73739);
$actors = $series->getActors();

获取系列集数

TVDB API 端点用于检索集数是分页的。这意味着您在检索集数时需要指定一个页面号。

/*
 * Get the episodes of the series by TVDB ID
 * ID: 73739 (Lost)
 *
 * The second parameter specifies the page (page 1 by default)
 */
$episodes = TVDB::getSeriesEpisodes(73739, 2);

// Or get the episodes directly from a "Series" object
$series = TVDB::getSeries(73739);

$episodes = $series->getEpisodes(2);

示例 1 - 遍历所有集数

$page = 1;

do {
    $episodes = TVDB::getSeriesEpisodes(73739, $page);

    echo "Page $page has " . count($episodes) . " episodes. <br />";

    $page++;
} while($episodes->hasNextPage());

/*
 * Output:
 * Page 1 has 100 episodes.
 * Page 2 has 49 episodes.
 */

示例 2

$episodes = TVDB::getSeriesEpisodes(73739);

foreach($episodes as $episode) {
    echo $episode->name . '<br />';
}

获取单个集数

/*
 * Retrieve the episode with ID 127131
 * .. returns an "Episode" object
 */
$episode = TVDB::getEpisode(127131);

echo $episode->name; //  "Pilot (1)"

获取您的 TVDB JWT 令牌

有时检索您的 TVDB JWT 令牌(例如用于测试 API)可能会有用。

echo TVDB::getToken();

鸣谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件