Downloading all trailers from pages Opening,Coming Soon,Top 10,...

May 11, 2011 at 9:31 PM


Hi 
i love  HD-Trailers.NET. Only problem is that i dont watch so many trailers for fetching them every day and watching all.  I would like to download all trailers from page http://www.hd-trailers.net/TopMovies/ or from http://www.hd-trailers.net/ComingSoon/. So i created php script which can generate RSS feed from http://www.hd-trailers.net/ for program HD-Trailers.NET Downloader witch will download trailers from choosen page.  I want to share it with you maybe someone will consider it useful and will use it.

I am not sure if this is feature for implementing in program or generating feed is better solution?

<?
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
/*SCRIPT FOR PARSING PAGES LIKE 
	http://www.hd-trailers.net/OpeningThisWeek/
	http://www.hd-trailers.net/TopMovies/
	http://www.hd-trailers.net/ComingSoon/
	http://www.hd-trailers.net/BluRay/
AND GENERATING RSS FEED FOR THEIR BACH DOWNLOADING BY HD-Trailers.NET Downloader

Instruction
1. Upload to your server 
2. In setting for HD-Trailers.NET Downloader  set
FeedAddress = "http://some.yourpage.com/yourdir/name.php?adress=/ComingSoon/"
or FeedAddress = "http://some.yourpage.com/yourdir/name.php" for ComingSoon trailers

Choosing of witch trailer will be download is 1. Apple 2. Yahoo 3. Moviefone 4. others
Second criteria is that name of trailer first of alfabetical order so 
  "Trailer" < "Trailer 1" < "Trailer 2" < "Trailer Something"    

Created by Maty 11.5.2011 Feel free to modify it*/
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//

function orez($string, $start, $end){
	$string = " ".$string;
	$ini = strpos($string,$start);
	if ($ini == 0) return "";
	$ini += strlen($start);
	$len = strpos($string,$end,$ini) - $ini;
	return substr($string,$ini,$len);
}
function getArrayFirstIndex($arr)
{
	foreach ($arr as $key => $value)
	return $value;
}
function getArrayFirstKey($arr)
{
	foreach ($arr as $key => $value)
	return  $key;
}
function curPageBaseURL() {
	$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
	$host     = $_SERVER['HTTP_HOST'];
	$script   = $_SERVER['SCRIPT_NAME'];
	$params   = $_SERVER['QUERY_STRING'];
	$currentUrl = $protocol . '://' . $host . $script;
	echo $currentUrl ;
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
//CODE FOR DOWNLOAD,PARSE AND SHOW TRAILER INFO FOR MOVIE SETTED IN GET PARAMETER url					//
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
$movieurl = "".$_GET['url'];
if ($movieurl != "") 
{
	$url ='http://www.hd-trailers.net'.$movieurl;
	$contents = file_get_contents( $url);
	echo '<strong>Link to Catalog</strong>';
	echo orez($contents,'<span class="topTableImage">','</span>');
	echo "<br/>\n\n";
	echo "<strong>Download</strong>: ";
	$table = split('<tr>',orez($contents,'<table class="bottomTable">','</table>')); 
	$pole =  Array();
	$poley =  Array();
	foreach ($table as $onerow)
	{
		if (strpos($onerow,'standardTrailerName') !== false )
		{
			$name = orez($onerow,'<span class="standardTrailerName">','</span>');
			$year = orez($onerow,'<td class="bottomTableDate" rowspan="2">','</td>');
			if (strpos($name ,'Trailer') !== false )
			{
				$cells = split('</td>',$onerow);
				$obsah = '';
				foreach ($cells  as $onecell)
				  if ((strpos($onecell,'<a') !== false ) && (strpos($onecell,'lightbox') !== false ))
				  { 
					$res=orez($onecell,'lightbox[res',' ');
					$link=orez($onecell,'href="','"');
					$obsah = $obsah . '<a href="' . $link . '">' . $res . '</a>, ';
				  }
				$obsah = substr($obsah,0,strlen($obsah)-2 );
				$priority=chr(39);
				if (strpos($onerow ,'alt="Yahoo"') !== false) $priority=chr(27);
				if (strpos($onerow ,'alt="Apple"') !== false) $priority=chr(26);
				if (strpos($onerow ,'alt="Moviefone"') !== false) $priority=chr(28);
				if (strlen($obsah)>5)
				{
					$pole[$priority . $name]=$obsah;
					$poley[$priority . $name]=$year;
					//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
					//FOR USING DATE AS CRITERIA USE AS KEY YEAR $pole[$year]=$obsah;					//
					//IF YOU WANT TO CHOOSE NEWEST DATE AS FIRST YOU MUST UNCOMMENT array_reverse AFTER foreach	//
					//FOR USING SITE AND DATE AS CRITERIA USE $pole[$priority . $year]=$obsah;				//
					//AND CHANGE PRIOTIY NUMBER HIGHIEST FOR PRIMARY SITE AND UNCOMMENT array_reverse AFTER foreach	//
					//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
				}
			}
		}
	}
	ksort($pole);

	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
	//FOR USE OF NEWEST DATE ADD THIS LINE HERE $pole = array_reverse($pole);						//
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
	if (count($pole)>0)
		echo getArrayFirstIndex($pole);
	echo "<br/>";
	if (count($pole)>0)
	{
		$key=getArrayFirstKey($pole);
		echo '<b>What was chosen:</b>  ';
		if ($key[0]==chr(26))   echo '<img src="http://static.hd-trailers.net/images/apple.ico" alt="Apple" height="16px" width="16px"/>';
		if ($key[0]==chr(27))   echo '<img src="http://static.hd-trailers.net/images/yahoo.ico" alt="Yahoo" height="16px" width="16px"/>';
		if ($key[0]==chr(28))   echo '<img src="http://static.hd-trailers.net/images/moviefone.ico" alt="Moviefone" height="16px" width="16px"/>';
		echo "   " . $key . "        <b>From date:</b>  " . $poley[$key] .  " \n<br/>";
	}
	echo "<b>End</b>";
	exit();
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
//CODE FOR DOWNLOAD,PARSE AND SHOW RSS PAGE FOR MAIN HD-TRAILER.NET PAGES SPECIFIED IN GET PARAMETER address		//
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
header('Content-type: text/xml');
$url = "http://www.hd-trailers.net/".$_GET['address'];
if ($url == "") $url='http://www.hd-trailers.net/ComingSoon/';
$contents = file_get_contents($url);
$body = orez($contents,'<table class="indexTable">','</table>');
$trailers = split('<td class="indexTableTrailerImage">',$body);

//WRITING START INFO FOR RSS FEED
echo '<?xml version="1.0" encoding="windows-1250"?>';

?>
<rss version="2.0" xml:base="<? curPageBaseURL(); ?> " xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
<atom:link href=" <? curPageBaseURL(); ?>"  rel="self" type="application/rss+xml" />
<link> <? curPageBaseURL(); ?> </link>
<title>Trailers parsing</title>
<description>RSS feed for fetching trailers from hd-trailers.net</description>
<?
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
//WRITING INFO FOR EACH TRAILER													//
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
foreach ($trailers as $trailer)
{
	if (strpos($trailer,'href="') !== false )
	{
		$link= orez($trailer,'href="','"');
		$title=orez($trailer,'title="','"'). ' (Trailer)';
		$img ='<img src="' . orez(orez($trailer,'href="','</a>'),'src="','"') . '"/>';
		
		echo "<item>\n";
		echo "<title>$title</title>\n"; 
		echo "<link>" . curPageBaseURL() . "?url=$link</link>\n";
		echo "<guid>" . curPageBaseURL() . "?url=$link</guid>\n"; 
		echo "<description>" . htmlspecialchars ($img). "</description>\n";
		echo "<pubDate>" . date(DATE_RSS) . "</pubDate>\n";
		echo "</item>\n\n\n";
	}
}
?>
</channel>
</rss>

Coordinator
Jun 27, 2011 at 5:29 PM

Sorry for not replying earlier. Just not sure how to take advantage of this. If I could do this programatically, I would add it to HD-Trailers.Net Downloader. Jus tnot sure how to accomplish it.