IMDb Search + Info,Poster cache

By zenx on Feb 24, 2011

Didnt really see any open source + easy to use projects for this so i choose to make one, it's not the best but does the job, it needs folder called "imdbi" for storing the IMDb posters. ( http://i.imgur.com/gAUbH.png )

EDIT: Added genre(s).
EDIT: Added check for input & made it to work with scene release names.. ( for usage with PreDB for example. )

<?php

function get_match($regex,$content) {
    preg_match($regex,$content,$matches);
    return $matches[1];
}

function savefile($image, $url) {
    $urlmd5 = md5($url);
    $stringData = file_get_contents("$image");
    if($stringData != "") {
            $myFile = "imdbi/" . $urlmd5 . ".jpg";
            $fh = fopen($myFile, 'w') or die("can't open file");
            fwrite($fh, $stringData);
            fclose($fh);
    }
}

if(!isset($_GET['f'])) { die("You need to search for a movie, for example: <a href=\"?f=Inception\">?f=Inception</a>"); }

$movie = str_replace(" ", "+", $_GET['f']);

// <scenecheck>
/*

matches:

Morning.Glory.FRENCH.DVDRip.XviD-NERD
Sanctum.FRENCH.R5.MD.XViD-SERUM
WWE.Superstars.2011.02.24.HDTV.XviD-W4F
Ring.of.Death.2008.720p.BluRay.x264-MELiTE
See.What.Im.Saying.The.Deaf.Entertainers.Documentary.2010.NTSC.DVDR-NTX
See.What.Im.Saying.The.Deaf.Entertainers.Documentary.NTSC.DVDR-NTX
Ring.of.Death.720p.BluRay.x264-MELiTE

etc..

*/

$rlsname = $_GET['f'];

preg_match('/(.*).S[0-9][0-9]E[0-9][0-9]/', $rlsname, $result);
preg_match('/(.*).((720p|1080p)|[1-2][0-9][0-9][0-9])/', $rlsname, $result1);
preg_match('/(.*)(.(German|SPANiSH|FiNNiSH|SWEDiSH|iTA|iTALY|DANiSH|POLiSH|FRENCH|NLSUBBED|DUTCH)).((NTSC|PAL)|DVDRip|DVDSCR|TS|TELESYNC|CAM|TELECINE|TC|R5|HDTV|PDTV|DSR)/', $rlsname, $result2);

if(isset($result[1])) { $result[1] = str_replace(".", "+", $result[1]); }
if(isset($result1[1])) { $result1[1] = str_replace(".", "+", $result1[1]); }
if(isset($result2[1])) { $result2[1] = str_replace(".", "+", $result2[1]); }

if (isset($result[1])) {
    $movie = $result[1];
} elseif (isset($result1[1])) {
        $movie = $result1[1];
} elseif (isset($result2[1])) {
        $movie = $result2[1];
} else {

}

// </scenecheck>

$searchurl = file_get_contents("http://www.imdb.com/find?q=" . $movie . "");

preg_match('/<b>(.*)<\/b>/',$searchurl,$notfound);

if($notfound[1] == "No Matches.") {

    echo("Nothing found.");

} else {

    preg_match('/tt[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/', $searchurl, $value);

    $urlx = "http://www.imdb.com/title/" . $value[0] . "/combined";

    $imdb_content = file_get_contents("$urlx");

    $md5d = md5($urlx);

    $name = get_match('/<title>(.*)<\/title>/isU',$imdb_content);
    $director = strip_tags(get_match('/<h5[^>]*>Director:<\/h5>(.*)<\/div>/isU',$imdb_content));
    $plot = get_match('/<h5[^>]*>Plot:<\/h5>(.*)<\/div>/isU',$imdb_content);
    $release_date = get_match('/<h5[^>]*>Release Date:<\/h5>(.*)<\/div>/isU',$imdb_content);
    $mpaa = get_match('/<a href="\/mpaa">MPAA<\/a>:<\/h5>(.*)<\/div>/isU',$imdb_content);
    $run_time = get_match('/Runtime:<\/h5>(.*)<\/div>/isU',$imdb_content);
    preg_match('/<a href="\/Sections\/Genres\/(.*)\/">(.*)<\/a>/', $imdb_content, $genre);
    preg_match('/" src="(.*)"/', $imdb_content, $poster);

    $filename = "imdbi/" . $md5d . ".jpg";

    if(isset($poster[1]) && !file_exists($filename)) {
        $save = savefile($poster[1], $urlx);
    }

    if(file_exists($filename)) { $content.= "<img src=" . $filename . " align=\"left\">"; }

    $content.= '<b>Film:</b> <a href="'.$urlx.'" targer="_blank">'.trim($name).'</a><br/>';
    if(isset($director)) { $content.= '<b>Director:</b> '.trim($director).'<br/>'; }
    if(isset($plot)) { $content.= '<b>Plot:</b> '.trim(substr($plot,0,strpos($plot,'<a'))).'<br/>'; }
    if(isset($release_date)) { $content.= '<b>Release Date:</b> '.trim(substr($release_date,0,strpos($release_date,'<a'))).'<br/>'; }
    if(isset($genre[0])) { $content.= '<b>Genre(s):</b> '.str_replace(" See more", "", strip_tags($genre[0])).'<br/>'; }
    if(isset($mpaa)) { $content.= '<b>MPAA:</b> '.trim($mpaa).'<br/>'; }
    if(isset($run_time)) { $content.= '<b>Run Time:</b> '.trim($run_time).'<br/>'; }
    $content = str_replace("<div class=\"info-content\">","",$content);

    echo $content;

}

?>

Comments

Sign in to comment.
zenx   -  Feb 25, 2011

You send a request to this script, for example script.php?f=Inception

 Respond  
joelp54   -  Feb 25, 2011

Hmm how does this work i'm a little confused ;-/

 Respond  
zenx   -  Feb 25, 2011

It's till in test level but i thought i'd share it with you guys since it's working

 Respond  
Hawkee   -  Feb 24, 2011

Not bad, but its better to use an HTML parser like PHP Simple HTML DOM Parser. That way you don't need to use all the regular expressions and backslashes. Your solution works well as a standalone snippet though.

 Respond  
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.