zero-to-prod/omdb-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zero-to-prod/omdb-api

Composer 安装命令:

composer require zero-to-prod/omdb-api

包简介

A cURL wrapper for the OMDb API

README 文档

README

Repo GitHub Actions Workflow Status Packagist Downloads Packagist Version License wakatime Hits-of-Code

Contents

Introduction

Zerotoprod\OmdbApi is a PHP cURL wrapper for the OMDb API. It allows you to search for movies, series, and other media, retrieve detailed information using IMDb IDs or titles, and fetch poster images.

TLDR

use Zerotoprod\OmdbApi\OmdbApi;

$OmdbApi = new OmdbApi('apiKey');

// Find a title by ImdbID (Internet Movie DataBase ID) or title
$OmdbApi->byIdOrTitle('Avatar')['Title']; // 2009

// Find multiple titles
$OmdbApi->search('Avatar')['Search'][0]['Year']; // 2009

// Get the poster art of a title by its ImdbID
$OmdbApi->poster('tt0499549'); // https://img.omdbapi.com/?apikey=8f8423aa&i=tt0499549

Requirements

  • PHP 8.1 or higher.
  • cURL extension enabled (typically enabled by default in most PHP installations).
  • A valid OMDb API key. A free key is typically available.

Getting an OMDb API Key

  1. Go to the OMDb API website.
  2. Sign up for a free or paid plan depending on your usage requirements.
  3. After registering, you will receive an API Key that you must pass to the OmdbApi class during initialization.

Installation

Install Zerotoprod\OmdbApi via Composer:

composer require zero-to-prod/omdb-api

This will add the package to your project’s dependencies and create an autoloader entry for it.

Usage

Initialization

use Zerotoprod\OmdbApi\OmdbApi;

$OmdbApi = new OmdbApi('apiKey');

You can also customize the base URL and the poster URL if you need to (for example, to proxy through another service):

$OmdbApi = new OmdbApi(
    apikey: 'your-omdb-api-key',
    base_url: 'https://www.omdbapi.com/',
    img_url: 'https://img.omdbapi.com/'
);

Methods Overview

Below is a summary of the primary methods exposed by this package:

byIdOrTitle()

Retrieve detailed information about a specific movie, TV series, or episode by either its IMDb ID or title.

public function byIdOrTitle(
    ?string $title = null,      // (optional): A string containing the title to look up (e.g. “Avatar”)
    ?string $imdbID = null,     // (optional): A valid IMDb ID (e.g. “tt1285016”)
    ?string $type = null,       // (optional): The type of media to search for. Acceptable values are “movie”, “series”, "game", or “episode”.
    ?int    $year = null,       // (optional): Year of release
    ?bool   $full_plot = false, // (optional): If true, returns the full plot instead of a short summary
    mixed   $callback = null,   // (optional): JSONP callback name (if needed).
    ?string $version = null,    // (optional): Reserved for future use.
    ?array  $CURLOPT = [CURLOPT_TIMEOUT => 10] // An associative array of [cURL options](https://www.php.net/manual/en/function.curl-setopt.php). Defaults to [CURLOPT_TIMEOUT => 10].
): array

Returns an error or this response:

[
  "Title" => "Avatar",
  "Year" => "2009",
  "Rated" => "PG-13",
  "Released" => "18 Dec 2009",
  "Runtime" => "162 min",
  "Genre" => "Action, Adventure, Fantasy",
  "Director" => "James Cameron",
  "Writer" => "James Cameron",
  "Actors" => "Sam Worthington, Zoe Saldana, Sigourney Weaver",
  "Plot" => "A paraplegic Marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
  "Language" => "English, Spanish",
  "Country" => "United States, United Kingdom",
  "Awards" => "Won 3 Oscars. 91 wins & 131 nominations total",
  "Poster" => "https://m.media-amazon.com/images/M/MV5BMDEzMmQwZjctZWU2My00MWNlLWE0NjItMDJlYTRlNGJiZjcyXkEyXkFqcGc@._V1_SX300.jpg",
  "Ratings" => [
    [
      "Source" => "Internet Movie Database",
      "Value" => "7.9/10"
    ],
    [
      "Source" => "Rotten Tomatoes",
      "Value" => "81%"
    ],
    [
      "Source" => "Metacritic",
      "Value" => "83/100"
    ]
  ],
  "Metascore" => "83",
  "imdbRating" => "7.9",
  "imdbVotes" => "1,411,534",
  "imdbID" => "tt0499549",
  "Type" => "movie",
  "DVD" => "N/A",
  "BoxOffice" => "$785,221,649",
  "Production" => "N/A",
  "Website" => "N/A",
  "Response" => "True"
];

search()

Search for multiple titles using a keyword.

public function search(
    string $title,          // (required): A string representing the search term (e.g. “Avatar”)
    ?string $type = null,   // (optional): “movie”, “series”, or “episode”
    ?int $year = null,      // Year of release to narrow down results
    ?int $page = 1,         // (optional): Page number for paginated results
    mixed $callback = null, // (optional): JSONP callback name
    ?string $version = null,// (optional): Reserved for future use
    ?array $CURLOPT = [CURLOPT_TIMEOUT => 10] // An associative array of [cURL options](https://www.php.net/manual/en/function.curl-setopt.php). Defaults to [CURLOPT_TIMEOUT => 10].
): array

Returns an error or this response:

[
  "Search" => [
    [
      "Title" => "Avatar",
      "Year" => "2009",
      "imdbID" => "tt0499549",
      "Type" => "movie",
      "Poster" => "https://m.media-amazon.com/images/M/MV5BMDEzMmQwZjctZWU2My00MWNlLWE0NjItMDJlYTRlNGJiZjcyXkEyXkFqcGc@._V1_SX300.jpg"
    ],
    [
      "Title" => "Avatar: The Way of Water",
      "Year" => "2022",
      "imdbID" => "tt1630029",
      "Type" => "movie",
      "Poster" => "https://m.media-amazon.com/images/M/MV5BNmQxNjZlZTctMWJiMC00NGMxLWJjNTctNTFiNjA1Njk3ZDQ5XkEyXkFqcGc@._V1_SX300.jpg"
    ]
  ],
  "totalResults" => "113",
  "Response" => "True"
];

poster()

Get the direct URL to the poster image for a given IMDb ID.

$OmdbApi->poster('tt0499549'); // https://img.omdbapi.com/?apikey=8f8423aa&i=tt0499549

Error Handling

When a request fails (for example, if no matching title is found, cURL fails to initialize, or an invalid response comes back), the returned array includes:

[
    'ErrorType' => 'validation' | 'curl' | 'server',
    'message'   => 'A descriptive message about the error.',
    'extra'     => [...optional additional data...]
]

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.

zero-to-prod/omdb-api 适用场景与选型建议

zero-to-prod/omdb-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.3k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「zero-to-prod」 「Open Movie Database API」 「omdb-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 zero-to-prod/omdb-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 zero-to-prod/omdb-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 zero-to-prod/omdb-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 15
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-29