PHP: Get movie information from IMDB

If you are building a website about movies and want to access movie information from Imdb then you can get it only by web scrapping because Imdb doesn't provide any API to access its movie database. But there are some third-party API which provides information from Imdb.
In this article I will explain how to use following two APIs

  1. omdbapi.com
  2. imdbapi.org

Working With omdbapi.com


Service Endpoint    http://www.omdbapi.com/
Parameter Value Description
s string (optional) title of a movie to search for
i string (optional) a valid IMDb movie id
t string (optional) title of a movie to return
y year (optional) year of the movie
r JSON, XML response data type (JSON default)
plot short, full short or extended plot (short default)
callback name (optional) JSONP callback name
tomatoes true (optional) adds rotten tomatoes d

Sample Request: http://www.omdbapi.com/?t=titanic&y=1997
Sample Response :

{"Title":"Titanic","Year":"1997","Rated":"PG-13","Released":"19 Dec 1997","Runtime":"3 h 14 min","Genre":"Drama, Romance","Director":"James Cameron","Writer":"James Cameron","Actors":"Leonardo DiCaprio, Kate Winslet, Billy Zane, Kathy Bates","Plot":"A seventeen-year-old aristocrat, expecting to be married to a rich claimant by her mother, falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.","Poster":"http://ia.media-imdb.com/images/M/MV5BMjExNzM0NDM0N15BMl5BanBnXkFtZTcwMzkxOTUwNw@@._V1_SX300.jpg","imdbRating":"7.6","imdbVotes":"449,162","imdbID":"tt0120338","Type":"movie","Response":"True"}

php code to access movie information omdbapi.com
  <?
  $json=file_get_contents("http://www.omdbapi.com/?t=titanic&y=1997");
  $info=json_decode($json);
  print_r($info);
  ?>
  

Working With imdbapi.org


Service Endpoint    http://imdbapi.org/
Parameter Required Valid options Default Value Description
id (or ids) No if title /^tt\d+$/   The IMDB ID of the movie you wish to get the info for (e.g. tt0120689)
id  - only one IMDb ID.
ids - max 10 IMDb ID (comma-separated).
title No if id movie title   The valid imdb title of movie you wish to get the info for.(e.g. titanic)
type No json, jsonp, xml json The data type you wish the API to return.
plot No none, simple, full simple The plot type you wish the API to return.
episode No 1,0 1 When the parameter is 0, "episodes" is not included in the result.
lang No en-US, zh-CN en-US The data language you wish the API to reutrn.
aka No simple,full simple The aka type you wish the API to return.
release No simple,full simple The release date type you wish the API to return.
business No 1, 0 0 Whether to include the business field in the result.
tech No 1, 0 0 Whether to include the technical field in the result.

Sample Request: http://imdbapi.org/?title=titanic
Sample response:

[{"runtime": ["194 min"], "rating": 7.6, "genres": ["Drama", "Romance"], "rated": "PG_13", "language": ["English", "French", "German", "Swedish", "Italian", "Russian"], "title": "Titanic", "filming_locations": "Santa Clarita, California, USA", "poster": "http://ia.media-imdb.com/images/M/MV5BMjExNzM0NDM0N15BMl5BanBnXkFtZTcwMzkxOTUwNw@@._V1._SY317_CR0,0,214,317_.jpg", "imdb_url": "http://www.imdb.com/title/tt0120338/", "writers": ["James Cameron"], "imdb_id": "tt0120338", "directors": ["James Cameron"], "rating_count": 426376, "actors": ["Leonardo DiCaprio", "Kate Winslet", "Billy Zane", "Kathy Bates", "Frances Fisher", "Gloria Stuart", "Bill Paxton", "Bernard Hill", "David Warner", "Victor Garber", "Jonathan Hyde", "Suzy Amis", "Lewis Abernathy", "Nicholas Cascone", "Anatoly M. Sagalevitch"], "plot_simple": "A seventeen-year-old aristocrat, expecting to be married to a rich claimant by her mother, falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.", "year": 1997, "country": ["USA"], "type": "M", "release_date": 19980403, "also_known_as": ["Titanic in 3D"]}]

php code to access movie information from imdbapi.org
  <?
  $json=file_get_contents("http://imdbapi.org/?title=titanic");
  $info=json_decode($json);
  print_r($info);
  ?>
  

Published on March 20, 2013 by Sunny Verma

Liked It? Get Free updates in your Email

Delivered by feedburner