How to Get Movie Details from IMDb using PHP/AJAX?

IMDb is undoubtedly the largest database for movies worldwide. One can say, that is not so efficient for regional movies, but there aren’t any such online databases for them either. This article is about how to get details of a movie like its poster, cast, crew, summary, etc.

To Achieve the Task we will be using an API which is not Open source, but free. It is known as OMDB Api and was built by Brian Fritz(Thanks Man!).

The Latest Version at the time of this writing is 2.1 which is quite advanced and has the options to resolve name conflicts by using years.

So, How do I get details of any Film?

All you need to do is make an Ajax call to the following URL:

http://www.omdbapi.com/?t=True Grit&y=1969

If you visit the link above, you can see some Data enclosed in Curly Braces { }. This is known as JSON(JavaScript Object Notation). There are options to process this Data in jQuery, JavaScript or PHP.

Following is an Example Script using this API:
{code type=javascript}

// IMDb ID to Search
var imdbId = “tt1285016”;

// Send Request
var http = new ActiveXObject(“Microsoft.XMLHTTP”);
http.open(“GET”, “http://www.omdbapi.com/?i=” + imdbId, false);
http.send(null);

// Response to JSON
var omdbData = http.responseText;
var omdbJSON = eval(“(” + omdbData + “)”);

// Returns Movie Title
alert(omdbJSON.Title);
{/code}

If you use Jquery instead of Javascript, the above code can be made smaller and easier to read/implement.

You can use these results in any way you wish. To Know about how to make an AJAX call from jQuery you may read here: How to Return Data From PHP File to AJAX Call (jQuery).

3 thoughts on “How to Get Movie Details from IMDb using PHP/AJAX?

Leave a Reply

Your email address will not be published. Required fields are marked *