Location: PHPKode > scripts > IMDB Grabber > imdb-grabber/imdb.class.php
<?php
/*
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-=		IMDb Grabber	    -=
-=	File: imdb.class.php        -=
-=	Created by CarcaBot	    -=
-=	hide@address.com	    -=
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
// Functii in general
function extrage($content,$start,$end){
        $r = explode($start, $content);
        if (isset($r[1])){
            $r = explode($end, $r[1]);
            return $r[0];
        }
        return '';
    }    
function rcast($continut) {
   global $export;
   $cauta  = array ('(Cast overview, first billed only)','<td class="hs">','<td class="nm">','</td>','<td class="ddd">','<td class="char">');
   $inlocuieste = array ('','','<br>','','','');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rusercomments($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rcountry($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   $export = spatiu($export);
   return $export;
}
function rlanguage($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   $export = spatiu($export);
   return $export;
}
function rsoundmix($continut) {
   global $export;
   $cauta  = array ('|');
   $inlocuieste = array (' | ');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function raspect($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function raka($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rawards($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rplot($continut) {
   global $export;
   $cauta  = array ('full summary','|','full synopsis');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rtagline($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rwriters($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rgenre($continut) {
   global $export;
   $cauta  = array ('more');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rdirector($continut) {
   global $export;
   $cauta  = array ('');
   $inlocuieste = array ('');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function rscore($continut) {
   global $export;
   $cauta  = array ('&nbsp;','votes');
   $inlocuieste = array ('',' votes');
   $export    = str_replace($cauta, $inlocuieste, $continut);
   $export = strip_tags($export);
   return $export;
}
function spatiu($continut) {
$continut = preg_replace('/\s+/', '', $continut);
return $continut;
}
// Class
class IMDbGrabber {
	//
	var $adresa;
	var $id;
	var $name;
	var $score;
	var $director;
	var $released;
	var $writers;
	var $genre;
	var $tagline;
	var $plot;
	var $awards;
	var $aka;
	var $runtime;
	var $country;
	var $language;
	var $aspect;
	var $soundmix;
	var $usercomments;
	var $cast;
	var $poster_image;
	var $poster_image_link;
	var $trailer;
	var $nfo;
// Functii in clasa

	function IMDbGrabber($link) {
		//
		if(empty($link)) {
			$this->adresa = "http://imdb.com/title/tt0327597/";
		}
		else {
			if (substr($link, strlen($link)-1, 1) != '/') {
				$link = $link.'/';
			}
			$this->adresa = $link;
		}

		$continut = fopen($this->adresa, "rb");
		$continut = stream_get_contents($continut);
    /*
    ** id
    */
		$imdbid = extrage($this->adresa, "title/tt", "/");
		$this->id = $imdbid;
    /*
    ** Movie Name
    */

		$this->name = extrage($continut, "<title>", "</title>");
		$this->name = ltrim($this->name);
		$this->name = rtrim($this->name);		
		if ($this->name === false) {
			$this->name = '- no name available -';
		}
		
    /*
    ** score
    */

		$this->score = extrage($continut, "<div class=\"meta\">", "</div>");
		$this->score = rscore($this->score);
		$this->score = rtrim($this->score);
		$this->score = ltrim($this->score);
		if ($this->score === false) {
			$this->score = '- no score available -';
		}
    /*
    ** director
    */

		$this->director = extrage($continut, "<h5>Director:</h5>", "</div>");
		$this->director = rdirector($this->director);
		$this->director = ltrim($this->director);
		$this->director = rtrim($this->director);

		if ($this->director === false) {
			$this->director = '- no director available -';
		}

    /*
    ** writers
    */

		$this->writers = extrage($continut, "<h5>Writer", "</div>");
		$this->writers = rwriters($this->writers);
		$this->writers = ltrim($this->writers);
		$this->writers = rtrim($this->writers);
		
		if ($this->writers === false) {
			$this->writers = '- no writers available -';
		}
    /*
    ** released
    */

		$this->released = extrage($continut, "<h5>Release Date:</h5>", "<a class=\"");
		$this->released = ltrim($this->released);
		$this->released = rtrim($this->released);

		if ($this->released === false) {
			$this->released = '- no released available -';
		}
    /*
    ** genre
    */

		$this->genre = extrage($continut, "<h5>Genre:</h5>", "</div>");
		$this->genre = rgenre($this->genre);
		$this->genre = ltrim($this->genre);
		$this->genre = rtrim($this->genre);

		if ($this->genre === false) {
			$this->genre = '- no genre available -';
		}
    /*
    ** tagline
    */

		$this->tagline = extrage($continut, "<h5>Tagline:</h5>", "</div>");
		$this->tagline = rtagline($this->tagline);
		$this->tagline = ltrim($this->tagline);
		$this->tagline = rtrim($this->tagline);		
		if ($this->tagline === false) {
			$this->tagline = '- no tagline available -';
		}
    /*
    ** Plot
    */

		$this->plot = extrage($continut, "<h5>Plot:</h5>", "</div>");
		$this->plot = rplot($this->plot);
		$this->plot = rtrim($this->plot);
		$this->plot = ltrim($this->plot);
		if ($this->plot === false) {
			$this->plot = '- no plot available -';
		}
    /*
    ** Awards
    */

		$this->awards = extrage($continut, "<h5>Awards:</h5>", "</div>");
		$this->awards = rawards($this->awards);
		$this->awards = ltrim($this->awards);
		$this->awards = rtrim($this->awards);
		if ($this->awards === false) {
			$this->awards = '- no awards available -';
		}
    /*
    ** Also known as
    */

		$this->aka = extrage($continut, "<h5>Also Known As:</h5>", "</div>");
		$this->aka = raka($this->aka);
		$this->aka = ltrim($this->aka);
		$this->aka = rtrim($this->aka);
		if ($this->aka === false) {
			$this->aka = '- no aka available -';
		}
    /*
    ** RunTime
    */

		$this->runtime = extrage($continut, "<h5>Runtime:</h5>", "</div>");
		$this->runtime = ltrim($this->runtime);
		$this->runtime = rtrim($this->runtime);
		if ($this->runtime === false) {
			$this->runtime = '- no runtime available -';
		}
    /*
    ** Country
    */

		$this->country = extrage($continut, "<h5>Country:</h5>", "</div>");
		$this->country = rcountry($this->country);
		$this->country = ltrim($this->country);
		$this->country = rtrim($this->country);
		if ($this->country === false) {
			$this->country = '- no Country available -';
		}
    /*
    ** Language
    */

		$this->language = extrage($continut, "<h5>Language:</h5>", "</div>");
		$this->language = rlanguage($this->country);
		$this->language = ltrim($this->country);
		$this->language = rtrim($this->country);
		if ($this->language === false) {
			$this->language = '- no language available -';
		}
    /*
    ** Aspect
    */

		$this->aspect = extrage($continut, "<h5>Aspect Ratio:</h5>", "</div>");
		$this->aspect = raspect($this->aspect);
		$this->aspect = rtrim($this->aspect);
		$this->aspect = ltrim($this->aspect);
		if ($this->aspect === false) {
			$this->aspect = '- no aspect available -';
		}
    /*
    ** SoundMix
    */

		$this->soundmix = extrage($continut, "<h5>Sound Mix:</h5>", "</div>");
		$this->soundmix = spatiu($this->soundmix);
		$this->soundmix = rsoundmix($this->soundmix);
		$this->soundmix = ltrim($this->soundmix);
		$this->soundmix = rtrim($this->soundmix);
		if ($this->soundmix === false) {
			$this->soundmix = '- no soundmix available -';
		}
    /*
    ** User Comments
    */

		$this->usercomments = extrage($continut, "<h5>User Comments:</h5>", "</div>");
		$this->usercomments = rusercomments($this->usercomments);
		$this->usercomments = rtrim($this->usercomments);
		$this->usercomments = ltrim($this->usercomments);
		if ($this->usercomments === false) {
			$this->usercomments = '- no User Comments available -';
		}

    /*
    ** Poster
    */
    
    		$this->poster = extrage($continut, "<a name=\"poster\" href=\"","\" title=\"");
    		if($this->poster === false) {
    		$this->poster = '- no poster available -';
    		} else {
    		
    		$poster = "http://us.imdb.com" . $this->poster;
		$handleposter1 = fopen($poster, "rb");
		$poster = stream_get_contents($handleposter1);
		$this->poster =  extrage($poster, "onmousemove=\"return false;\" src=\"","\"></td>");
		fclose($handleposter1);
		}
}
	/*
	** Display Poster
	*/
	function displayposter() {
	$poster = $this->poster;
	if(!empty($poster)) {	
	$html = "<img src='".$poster."' border='0' />";
} else { 
$html = "- no poster available -";

}
	return $html;
	}

    /*
    ** Display Cast
    */
    function showcast() {
		$continut = fopen($this->adresa . "fullcredits", "rb");
		$continut = stream_get_contents($continut);
		$this->cast = extrage($continut, "<table class=\"cast\">", "</table>");
		$this->castx = explode('<td class="nm">',$this->cast);
		#$this->cast = rcast($this->cast);	
		$this->cast = array();
		for ($i=1; $i<count($this->castx); $i++) {
			$character = strip_tags(extrage($this->castx[$i], '<td class="char">', '</td>'));
			$cast = array('character'=>$character);
			array_push($this->cast, $cast);
		}
	return $this->cast;
}	
    /*
    ** Display Trailer
    */
	function trailer() {
	$continut = fopen($this->adresa . "trailers", "rb");
	$continut = stream_get_contents($continut);
if(strstr($continut, "alltrailers.net")) {
	$trailer = extrage($continut, '<a href="http://alltrailers.net/', '">');
	$trailer = "http://alltrailers.net/" . $trailer;
	$trailerlink = $trailer;
	$continut = fopen($trailer, "rb");
	$continut = stream_get_contents($continut);
	$trailer = extrage($continut, '<div id="video">', '</div>');
	$trailer = str_replace('src="mediaplayer/','src="http://alltrailers.net/mediaplayer/',$trailer);
} else { $trailer = "- no trailer available -";}
	
	$html = $trailer;
	return $html;
	}
	
    /*
    ** Create NFO File
    */	
	function nfo($filename) {
if(empty($filename)) {
$filename = $this->id . '.nfo';
}
$name1 = str_replace(' ','+',$this->name);
$nfocreated = date("d/m/Y H:i:s");
$nfo = '
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   		          www.RENSLT.org
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
		'.$this->name.'

MOVIE INFORMATION
-=-=-=-=-=-=-=-=-=-
IMDb Link	: '.$this->adresa.'
DOWNLOAD Movie	: http://renslt.org/search.php?do=process&query='.$name1.'
IMDb Score	: '.$this->score.'
Director	: '.$this->director.'
Released Date	: '.$this->released.'
Writers:	: '.$this->writers.'
Genre		: '.$this->genre.'
Tag Line	: '.$this->tagline.'
Plot		: '.$this->plot.'
Awards		: '.$this->awards.'
Also Known As	: '.$this->aka.'
Runtime		: '.$this->runtime.'
Country		: '.$this->country.'
Language	: '.$this->language.'
Aspect		: '.$this->aspect.'
SoundMix	: '.$this->soundmix.'
User Comments	: '.$this->usercomments.'


nfo created	: '.$nfocreated.'
';


$i=1;

$nfo .= '
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Romanian Electronic Network Security Lab Team

		We\'re not the only ones, but we\'re the best !
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
			 		  nf0 by RENSLT - www.RENSLT.org
';

$file = fopen($filename,"w");
fwrite($file, $nfo);
fclose($file);


}
}

?>
Return current item: IMDB Grabber