mrcnpdlk/imdbphp

用于从IMDb检索电影和电视信息的库

v6.0.0 2017-12-09 21:35 UTC

README

tboothman/imdbphp分支

  • PHP 7支持
  • PSR16缓存支持

imdbphp

PHP库,用于从IMDb检索电影和电视信息。可以检索到IMDb上大部分的信息,包括电影、电视系列、电视剧集、人物等。可以在IMDb上搜索标题,包括按类型(电影、电视系列等)过滤。下载电影海报和演员照片。

快速入门

$title = new \Imdb\Title(335266);
$rating = $title->rating();
$plotOutline = $title->plotoutline();

安装

此库爬取imdb.com,因此它们网站上的更改可能会导致此库的部分功能失效。您可能需要每年更新几次。在选择如何安装/配置时请记住这一点。

尝试Sibbell获取新版本通知

安装文件

安装/启用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();
}