mrcnpdlk / imdbphp
用于从IMDb检索电影和电视信息的库
v6.0.0
2017-12-09 21:35 UTC
Requires
- php: >=7.0
- ext-curl: *
- mrcnpdlk/psr16cache-adapter: ~0
Requires (Dev)
- mockery/mockery: ~0.9
- mrcnpdlk/monolog: ~0
- phpfastcache/phpfastcache: ~6.0
- phpunit/phpunit: ~3.7
This package is not auto-updated.
Last update: 2024-09-14 02:02:50 UTC
README
- PHP 7支持
- PSR16缓存支持
imdbphp
PHP库,用于从IMDb检索电影和电视信息。可以检索到IMDb上大部分的信息,包括电影、电视系列、电视剧集、人物等。可以在IMDb上搜索标题,包括按类型(电影、电视系列等)过滤。下载电影海报和演员照片。
快速入门
- 使用composer包含imdbphp/imdbphp,克隆此仓库或下载最新的发布压缩包。
- 查找您想要元数据的电影,例如《迷失翻译》http://www.imdb.com/title/tt0335266/
- 如果您不使用composer或自动加载器,请包含
bootstrap.php
。 - 获取一些数据
$title = new \Imdb\Title(335266); $rating = $title->rating(); $plotOutline = $title->plotoutline();
安装
此库爬取imdb.com,因此它们网站上的更改可能会导致此库的部分功能失效。您可能需要每年更新几次。在选择如何安装/配置时请记住这一点。
尝试Sibbell获取新版本通知
安装文件
- Composer(推荐)。包含imdbphp/imdbphp包。
- Git克隆。检出最新发布标签。
安装/启用curl PHP扩展
配置
日志接口 Psr\Log\LoggerInterface
$oInstanceLogger = new \Monolog\Logger('IMDB'); $oInstanceLogger->pushHandler(new \Monolog\Handler\ErrorLogHandler( \Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, \Psr\Log\LogLevel::DEBUG ) );
缓存接口(PSR16) Psr\SimpleCache\CacheInterface
$oInstanceCacheRedis = new \phpFastCache\Helper\Psr16Adapter( 'redis', [ "host" => null, // default localhost "port" => null, // default 6379 'defaultTtl' => 3600 * 24, // 24h 'ignoreSymfonyNotice' => true, ]);
依赖注入
$oImdb = new Imdb\TitleSearch(null,$oInstanceLogger,$oInstanceCacheRedis);
搜索电影
// include "bootstrap.php"; // Load the class in if you're not using an autoloader $search = new \Imdb\TitleSearch(); // Optional $config parameter $results = $search->search('The Matrix', [\Imdb\TitleSearch::MOVIE]); // Optional second parameter restricts types returned // $results is an array of Title objects // The objects will have title, year and movietype available // immediately, but any other data will have to be fetched from IMDb foreach ($results as $result) { /* @var $result \Imdb\Title */ echo $result->title() . ' ( ' . $result->year() . ')'; }
搜索人物
// include "bootstrap.php"; // Load the class in if you're not using an autoloader $search = new \Imdb\PersonSearch(); // Optional $config parameter $results = $search->search('Forest Whitaker'); // $results is an array of Person objects // The objects will have name available, everything else must be fetched from IMDb foreach ($results as $result) { /* @var $result \Imdb\Person */ echo $result->name(); }