aharen/omdbapi
Composer 安装命令:
composer require aharen/omdbapi
包简介
PHP package for OMDbAPI.com by Brian Fritz
README 文档
README
PHP class to communicate with OMDbAPI.com API by Brian Fritz
How to Use
Include the file
composer require aharen/omdbapi
Or update your composer.json file accordingly
require {
"aharen/omdbapi" : "2.0.*"
}
Initiating
Since the API will be going private (read about it) & would be requiring the API key, a small change has been made to how the API will be initiated and how the Poster API will be used.
use aharen\OMDbAPI(); $omdb = new OMDbAPI($api_key, $image_host, $assoc);
The first parameter will be the API Key, the secound is the host to use (false = omdbapi, true = poster api, false by default) & third is assoc (true = assoc on, false = assoc off, false by default)
Search OMDb API
Requires search keyword and accepts type (movie, series or episode) & year
use aharen\OMDbAPI; $omdb = new OMDbAPI(); $omdb->search($keyword, $type, $year);
Example usage
$omdb->search('spider');
Output
stdClass Object ( [code] => 200 [message] => OK [data] => stdClass Object ( [0] => stdClass Object ( [Title] => Spider-Man [Year] => 2002 [imdbID] => tt0145487 [Type] => movie ) [1] => stdClass Object ( [Title] => The Amazing Spider-Man [Year] => 2012 [imdbID] => tt0948470 [Type] => movie ) [2] => stdClass Object ( [Title] => Spider-Man 2 [Year] => 2004 [imdbID] => tt0316654 [Type] => movie ) [3] => stdClass Object ( [Title] => Spider-Man 3 [Year] => 2007 [imdbID] => tt0413300 [Type] => movie ) [4] => stdClass Object ( [Title] => The Amazing Spider-Man 2 [Year] => 2014 [imdbID] => tt1872181 [Type] => movie ) [5] => stdClass Object ( [Title] => Along Came a Spider [Year] => 2001 [imdbID] => tt0164334 [Type] => movie ) [6] => stdClass Object ( [Title] => Spider [Year] => 2002 [imdbID] => tt0278731 [Type] => movie ) [7] => stdClass Object ( [Title] => Spider-Man [Year] => 1994–1998 [imdbID] => tt0112175 [Type] => series ) [8] => stdClass Object ( [Title] => Kiss of the Spider Woman [Year] => 1985 [imdbID] => tt0089424 [Type] => movie ) [9] => stdClass Object ( [Title] => The Spectacular Spider-Man [Year] => 2008–2009 [imdbID] => tt0976192 [Type] => series ) ) )
Usage examples
// search for all 'series' that contain 'spider' in the title $omdb->search('spider', 'series'); // search for all 'series' that contain 'spider' in the title and is from '2014' $omdb->search('spider', 'series', '2014');
Associative mode
You can also use this library in associative mode, resulting in arrays instead of stdClass instances, passing the second constructor argument to true:
// Associative mode (results will be associative arrays)
$omdb = new OMDbAPI(null, true);
Fetch movie details
Fetch details of a movie, series or episode. details can be fetched by either IMDB ID or the Title
Usage example
// get details for IMDB ID 'tt0338013' $omdb->fetch('i', 'tt0338013'); // get details for title 'eternal sunshine' $omdb->fetch('t', 'eternal sunshine');
Output for both of the above queires
stdClass Object ( [code] => 200 [message] => OK [data] => stdClass Object ( [Title] => Eternal Sunshine of the Spotless Mind [Year] => 2004 [Rated] => R [Released] => 19 Mar 2004 [Runtime] => 108 min [Genre] => Drama, Romance, Sci-Fi [Director] => Michel Gondry [Writer] => Charlie Kaufman (story), Michel Gondry (story), Pierre Bismuth (story), Charlie Kaufman (screenplay) [Actors] => Jim Carrey, Kate Winslet, Gerry Robert Byrne, Elijah Wood [Plot] => When their relationship turns sour, a couple undergoes a procedure to have each other erased from their memories. But it is only through the process of loss that they discover what they had to begin with. [Language] => English [Country] => USA [Awards] => Won 1 Oscar. Another 64 wins & 62 nominations. [Poster] => http://ia.media-imdb.com/images/M/MV5BMTY4NzcwODg3Nl5BMl5BanBnXkFtZTcwNTEwOTMyMw@@._V1_SX300.jpg [Metascore] => 89 [imdbRating] => 8.4 [imdbVotes] => 533,088 [imdbID] => tt0338013 [Type] => movie [Response] => True ) )
Fetching episodes details
You can also use the fetch third parameter to add extra parameters, for instance:
// Dexter (TV show) $omdb->fetch('i', 'tt0773262', ['Season' => 1])
This will add the Season=1 parameter
Credits
Unit Tests & Associative Mode by @Gregwar (Cheers)
aharen/omdbapi 适用场景与选型建议
aharen/omdbapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.95k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2016 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「movies」 「tv shows」 「omdb api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aharen/omdbapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aharen/omdbapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aharen/omdbapi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A package to retrieve movies and TV information from IMDB using the API at omdbapi.com
An AirPlay friendly web interface to stream your movies and TV shows from a home server.
xMDB parser
A PHP wrapper for OMDb API
A fluent, fully-typed Laravel wrapper for The Movie Database (TMDB) API.
Simple, lightweight PHP-SDK for searching and downloading subtitles from Subscene.com
统计信息
- 总下载量: 27.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-22