getIMDbIdFromSearch(trim($title)); if($imdbId === NULL){ $arr = array(); $arr['error'] = "No Title found in Search Results!"; return $arr; } return $this->getMovieInfoById($imdbId, $getExtraInfo); } // Get movie information by IMDb Id. public function getMovieInfoById($imdbId, $getExtraInfo = true) { $arr = array(); $imdbUrl = "http://www.imdb.com/title/" . trim($imdbId) . "/"; return $this->scrapeMovieInfo($imdbUrl, $getExtraInfo); } // Scrape movie information from IMDb page and return results in an array. private function scrapeMovieInfo($imdbUrl, $getExtraInfo = true) { $arr = array(); $html = $this->geturl("${imdbUrl}combined"); $title_id = $this->match('//ms', $html, 1); if(empty($title_id) || !preg_match("/tt\d+/i", $title_id)) { $arr['error'] = "No Title found on IMDb!"; return $arr; } $arr['title_id'] = $title_id; $arr['imdb_url'] = $imdbUrl; $arr['title'] = str_replace('"', '', trim($this->match('/
(.*?)(<|<\/p>)/ms', $plotPageHtml, 1))); $releaseinfoHtml = $this->geturl("http://www.imdb.com/title/" . $arr['title_id'] . "/releaseinfo"); $arr['also_known_as'] = $this->getAkaTitles($releaseinfoHtml); $arr['release_dates'] = $this->getReleaseDates($releaseinfoHtml); $arr['recommended_titles'] = $this->getRecommendedTitles($arr['title_id']); $arr['media_images'] = $this->getMediaImages($arr['title_id']); $arr['videos'] = $this->getVideos($arr['title_id']); } return $arr; } // Scan all Release Dates. private function getReleaseDates($html){ $releaseDates = array(); foreach($this->match_all('/
(.*?)<\/td>/ms', $r, 1))); $date = trim(strip_tags($this->match('/ | (.*?)<\/td>/ms', $r, 1))); array_push($releaseDates, $country . " = " . $date); } return array_filter($releaseDates); } // Scan all AKA Titles. private function getAkaTitles($html){ $akaTitles = array(); foreach($this->match_all('/ |
(.*?)<\/td>/ms', $m, 1);
$akaCountry = trim($akaTitleMatch[0]);
$akaTitle = trim($akaTitleMatch[1]);
array_push($akaTitles, $akaTitle . " = " . $akaCountry);
}
return array_filter($akaTitles);
}
// Collect all Media Images.
private function getMediaImages($titleId){
$url = "http://www.imdb.com/title/" . $titleId . "/mediaindex";
$html = $this->geturl($url);
$media = array();
$media = array_merge($media, $this->scanMediaImages($html));
foreach($this->match_all('/ (.*?)<\/div>/msi', $html, 1), 1) as $i) {
array_push($pics, preg_replace('/_V1\..*?.jpg/ms', "_V1._SY0.jpg", $i));
}
return array_filter($pics);
}
// Get recommended titles by IMDb title id.
public function getRecommendedTitles($titleId){
$json = $this->geturl("http://www.imdb.com/widget/recommendations/_ajax/get_more_recs?specs=p13nsims%3A${titleId}");
$resp = json_decode($json, true);
$arr = array();
if(isset($resp["recommendations"])) {
foreach($resp["recommendations"] as $val) {
$name = $this->match('/title="(.*?)"/msi', $val['content'], 1);
$arr[$val['tconst']] = $name;
}
}
return array_filter($arr);
}
// Get all Videos and Trailers
public function getVideos($titleId){
$html = $this->geturl("http://www.imdb.com/title/${titleId}/videogallery");
$videos = array();
foreach ($this->match_all('/ .*?match('/ | .*? | .*?\((.*?)\)<\/span>/msi', $m, 1);
$rating = $this->match('/ | .*?$id, "rank"=>$rank, "title"=>$title, "year"=>$year, "rating"=>$rating, "poster"=>$poster, "url"=>$url);
$rank++;
}
return $top250;
}
//************************[ Extra Functions ]******************************
// Movie title search on Google, Bing or Ask. If search fails, return FALSE.
private function getIMDbIdFromSearch($title, $engine = "google"){
switch ($engine) {
case "google": $nextEngine = "bing"; break;
case "bing": $nextEngine = "ask"; break;
case "ask": $nextEngine = FALSE; break;
case FALSE: return NULL;
default: return NULL;
}
$url = "http://www.${engine}.com/search?q=imdb+" . rawurlencode($title);
$ids = $this->match_all('/ | |