IMDB script to Find rating of a movie

By sarvsav on Aug 04, 2013

Here is the PHP code, thats using the curl function to find the IMDB rating of any movie.

How to use,

php imdb.php

Ex :

$ php imdb.php trtanic
Your movie Titanic (1997) has 7.6 ratings.

<?php
///////////////////////////////////////////////
////////  Author : Sarvsav Sharma  ///////////
//////// Email : sarvsav@gmail.com //////////
////////////////////////////////////////////
$characters = count($argv)-1;
if(isset($argv[1]))
$movie_name=$argv[1]."+";
else
exit(0);
for($i=2;$i<$characters+1;$i++)
$movie_name.= $argv[$i]."+";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://www.google.co.in/search?q='.$movie_name.'imdb');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$movie_link = curl_exec($ch);
preg_match('#www\.imdb\.com\/title\/tt\d+#',$movie_link,$matchme);
$imdb_url = $matchme[0];
curl_setopt($ch,CURLOPT_URL,$imdb_url."/");
$movie_data =  curl_exec($ch);
curl_close($ch);
preg_match('#ratingValue\"\>\d\.\d#',$movie_data,$matches);
$rating = explode(">",$matches[0]);
$name = $movie_data;
preg_match('#<title>.+</title>#',$name,$name_match);
$name_match = explode(")",$name_match[0]);
$name_match = explode(">",$name_match[0]);
echo "Your movie ".$name_match[1].") "."has ".$rating[1]." ratings.\n";

?>

Comments

Sign in to comment.
Hawkee   -  Aug 04, 2013

Simple little command line script, but for the sake of security I'd probably filter out anything but alphanumerics from the input. Would also be neat if it gave the Rottentomatoes rating and audience rating.

sarvsav  -  Aug 04, 2013

Thanks Hawkee for the suggestion. Will keep it updating.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.