Location: PHPKode > projects > Library Accounting System > library/movie_module/m_autoinfo.php
<?
if ($search != ""){

$search = str_replace(' ','%20', $search);
$medium = $_REQUEST['medium'];
if($medium == "7"){
// for amazon
$data = file_get_contents("http://www.amazon.com/exec/obidos/search-handle-url/?platform=gurupa&url=index=dvd&field-keywords=$search");
$start = strpos($data, '</form></table>');
$end = strrpos($data, '<td width=1 bgcolor="666666">') - $start;
$datas = substr($data, $start , $end );

$datas = preg_replace(array('/\/exec.*keywords=/', '/\n/', '/Avg. Customer Rating:.*?<\/span><\/span>/', '/<span class=tiny>.*?<\/span><\/span>/','/\/exec.*?-/' ), array('m_autoinfo.php?search=', '', '</span></td></tr></table><br><br></span></span>', '</span></td></tr></table><br><br></span></span>', './index.php?mode=madd&url=http://amazon.com/gp/product'),$datas);

}else{
// for imdb
$data = file_get_contents("http://www.imdb.com/find?q=$search;s=tt");

$start = strpos($data, 'A search for');
$end = strrpos($data, 'Suggestions For Improving Your Results') - $start;
$datas = substr($data, $start , $end );
$datas = preg_replace(array('/\/title/', '/\n/','/<script.*?<\/script>/', '/onclick=.*?\)"/'), array('./index.php?mode=madd&url=http://imdb.com/title'),$datas);
}
if(strlen($datas) == 0){ $url = "http://www.imdb.com/find?q=$search;s=tt";}else{
echo "Please select the correct movie: <br>".$datas;
exit;
}
}

if($url != "" && strpos($url, "amazon") > 0 ){
$data = file_get_contents("$url");
$start = strpos($data, '<b class="h1">Movies Summary</b>');
if ($start !== false){
$end = strrpos($data, '</table></div></div>') - $start;
$extra = substr($data, $start, $end);
$data = substr_replace($data, '', $start, $end);

}
preg_match('/Genres:<\/b> <a.*">.*<\/a>/', $data, $matches);
$genres = $matches[0];

preg_match('/<b class=\"sans\">.*?<\/b>/', $data, $matches);
$title = trim (strip_tags(preg_replace('/\(.*?\)/','',$matches[0])));

 preg_match('/Actors:<\/b>.*/', $data, $matches);
 $actors = trim (strip_tags(str_replace(array ('Actors:',','), array ('',' & '), preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', '', $matches[0]))), " &");

   
if($actors == ""){
 preg_match('/Starring:<\/b>.*/', $data, $matches);
 $actors = trim (strip_tags(str_replace(array ('Starring:',','), array ('',' & '), preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', '', $matches[0]))), " &");

 }

preg_match('/Director.:.*<\/b> <a.*">.*<\/a>/', $data, $matches);
$director = trim (str_replace(array (',','Directors:','Director:'), array (' & ','',), strip_tags(preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', '', $matches[0]), "<br>")));

preg_match('/discs:.*[0-9].*/', $data, $matches);
$discnum = trim (strip_tags(str_replace('discs: ','',$matches[0])));

preg_match('/Production Company:<\/b>.*/', $data, $matches);
$prodcomp = trim (strip_tags(str_replace('Production Company:','', $matches[0])));

preg_match('/Studio:<\/b>.*/', $data, $matches);
$studio = trim (strip_tags(str_replace('Studio:','', $matches[0])));

preg_match('/Plot Synopsis:<\/b> .*/', $data, $matches);
$synopsis = trim (strip_tags($matches[0]));

preg_match('/Plot Outline:<\/b> .*/', $data, $matches);
$outline = trim (strip_tags($matches[0]));

preg_match('/Format:<\/b>.*?<\/li>/', $data, $matches);
$format = trim (strip_tags(preg_replace(array('/Format:/', '/\(.*?\)/'),'', $matches[0])));
  
preg_match('/Release Date:<\/b>.*/', $data, $matches);
$release = trim (strip_tags(str_replace('Release Date:','', $matches[0])));

preg_match('/Available Subtitles:.*<\/li>/', $data, $matches);
$subtitles = trim (strip_tags(str_replace('Available Subtitles:','', $matches[0])));

preg_match('/Available Audio Tracks:.*<\/li>/', $data, $matches);
$audio = trim (strip_tags(str_replace('Available Audio Tracks:','', $matches[0])));


preg_match('/Region: <\/b>.*<f/', $data, $matches);
$encoding = trim (strip_tags(str_replace(array('Region:','Region','('),'', $matches[0])));
if($encoding == ""){
preg_match('/Encoding:<\/b>\n*.*<font/', $data, $matches);
$encoding = trim (strip_tags(str_replace('Encoding:','', $matches[0])));
}


preg_match('/Time:<\/b>.*/', $data, $matches);
$length = trim (strip_tags(preg_replace(array('/Time:/', '/\(.*\)/'),'', $matches[0])));
  
preg_match('/Rated:.*<\/li>/', $data, $matches);
$rating = $matches[0];
if(strpos($rating, "pg.") > 0 ){
$rating = "PG";
}elseif(strpos($rating, "g.gif") > 0 ){
$rating = "G";
}elseif(strpos($rating, "r.gif") > 0 ){
$rating = "R";
}elseif(strpos($rating, "pg-13") > 0 ){
$rating = "PG-13";
}elseif(strpos($rating, "tv-pg") > 0 ){
$rating = "TV-PG";
}elseif(strpos($rating, "tv-14") > 0 ){
$rating = "TY-14";
}elseif(strpos($rating, "nc-17") > 0 ){
$rating = "NC-17";
}elseif(strpos($rating, "ao") > 0 ){
$rating = "AO";
}else{$rating = "NR";}

preg_match('/ASIN:.*/', $data, $matches);
$asin = trim (strip_tags(str_replace('ASIN:','', $matches[0])));

//just incase this was a collection, we can get the details from each movie.
If ($extra != ""){
preg_match_all('/Plot Outline:<\/b>.*?<br \/>/', $extra, $matches);
$outline = trim(strip_tags(implode(chr(13), $matches[0])));

preg_match_all('/Genres:<\/b>.*?<br \/>/', $extra, $matches);
$genres = implode(' ', $matches[0]);

// this one is a little large... first it finds all the actors, puts them into an array
// then removes the duplicates then turns them back into a string.
 preg_match_all('/Stars:<\/b>.*?<br \/>/', $extra, $matches);
 $actors_temp = trim (strip_tags(str_replace(array ('Stars:',',', '  '), array ('','&'), preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', '', implode('&', $matches[0])))), " &");
$actors_temp = explode('&', $actors_temp);
$actors_temp =array_unique($actors_temp);
$actors = implode(' &', $actors_temp);

preg_match_all('/Directors:.*?<br \/>/', $extra, $matches);
$director_temp = trim (str_replace(array (',','Directors:', '  '), array ('&',''), strip_tags(implode('&', $matches[0]))), " &");
$director_temp = explode('&', $director_temp);
$director_temp =array_unique($director_temp);
$director = implode('&', $director_temp);
}



        //
        //Get image from amazon if allowed.
        //
    $config = mysql_fetch_array(mysql_query("SELECT Option1 FROM config WHERE config = 'images'"));
    if($config['Option1'] == 1){
    $image = addslashes(file_get_contents("http://images.amazon.com/images/P/".strtoupper($asin).".01._SCMZZZZZZZ_.jpg"));
    $image_url = "http://images.amazon.com/images/P/".strtoupper($asin).".01._SCMZZZZZZZ_.jpg";
}




}else if($url != ""){
if (strlen($data) == 0){
$data = file_get_contents("$url");
}

preg_match('/<strong class=\"title\">.*?<small>/', $data, $matches);
$title = trim (strip_tags($matches[0]));

preg_match('/Cast.*?<\/table>/', $data, $matches);
$actors = trim (strip_tags(preg_replace(array ('/Cast.*?:/','/\.\.\.\./', '/\(.*?\)/'), array ('',' as ', ''), preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', ' & ', $matches[0]))), " &");

preg_match('/Directed.*\n*<a.*">.*<\/a>/', $data, $matches);
$director = trim (str_replace(array ('Directed by'), array (''), strip_tags(preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', '', $matches[0]))));

preg_match('/Writ.*\n*.*\n*.*\n*<a.*">.*<\/a>/', $data, $matches);
$writer = trim (preg_replace(array ( '/\(.*?\)/','/and/','/Writ.*\n*/', '/\.\.\./', '/&nbsp;/'), array (''), strip_tags(preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', '& ', $matches[0]))), " & ");

preg_match('/Genre:.*\n*\n*.*\n*.*> </', $data, $matches);
$genres = trim (str_replace(array ('Genre:','/'), array ('',' & '), strip_tags(preg_replace('/<a\s+.*?href=\"([^\"]+)\"[^>]*>/', '', $matches[0]))), " &");

preg_match('/Plot Summary:<\/b> .*/', $data, $matches);
$outline = trim (strip_tags(preg_replace('/\(.*\)/','',$matches[0])));

preg_match('/\/Sections\/Years\/.*?">/', $data, $matches);
$release = trim (strip_tags(str_replace(array('/Sections/Years/','">'),'', $matches[0])));

preg_match('/Runtime:.*\n*.*/', $data, $matches);
$length = trim (strip_tags(preg_replace(array('/Runtime:/', '/\(.*\)/'),'', $matches[0])));
  
preg_match('/Rated.*for/', $data, $matches);
$rating = trim (strip_tags(str_replace(array('Rated','for'),'', $matches[0])));

$discnum = "Unknown";
$prodcomp = "Unknown";
$studio = "Unknown";
$synopsis = "Unknown";
$format = "Unknown";
$subtitles = "Unknown";
$audio = "Unknown";
$encoding = "Unknown";

//
//Get image if allowed.
//
$config = mysql_fetch_array(mysql_query("SELECT Option1 FROM config WHERE config = 'images'"));
if($config['Option1'] == 1){
preg_match('/http.*?imdb.com\/media.*jpg/', $data, $matches);
$image = addslashes(file_get_contents("$matches[0]"));
$image_url = $matches[0];
}
}
Return current item: Library Accounting System