musa11971 / laravel-tvdb
Laravel的TVDB API包装器。
此包的规范存储库似乎已丢失,因此包已被冻结。
v1.0.2
2019-01-21 11:04 UTC
Requires
- php: ^7.1.3
- ext-curl: *
- ext-json: *
This package is auto-updated.
Last update: 2022-12-21 20:16:32 UTC
README
musa11971/laravel-tvdb
包提供易于使用的函数,帮助您与TVDB API交互。
安装
您可以通过Composer安装此包
composer require musa11971/laravel-tvdb
使用以下Artisan命令发布配置文件
php artisan vendor:publish --provider="musa11971\TVDB\TVDBServiceProvider"
配置
上述发布命令将把 tvdb.php
配置文件发布到您的Laravel配置文件夹中。请确保使用您的个人API详细信息调整值。
我建议不要修改配置文件,而是将API详细信息定义在项目的 .env
文件中,如下所示
TVDB_API_KEY=ETIO2B4NO372XP0X
TVDB_USER_KEY=XXUXCXR8LYXUNM7P
TVDB_USERNAME=musa11971
别忘了清除您的配置缓存。(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)。有关更多信息,请参阅许可证文件。