Trilulilu and Youtube Downloader: Difference between revisions

From D3xt3r01.tk
Jump to navigationJump to search
Line 113: Line 113:
fwrite($h, " - ".$title.".mp3");
fwrite($h, " - ".$title.".mp3");
}else if(stristr($content, 'http://static.trilulilu.ro/flash/videoplayer')){
}else if(stristr($content, 'http://static.trilulilu.ro/flash/videoplayer')){
                         /* It's a flv/video file.
                         /* It's a flv/video file. */
if(is_file("stuff/".$title.".flv")){
if(is_file("stuff/".$title.".flv")){
continue;
continue;

Revision as of 10:22, 24 February 2010

WHY

THIS IS A PROOF OF CONCEPT ! NOT TO BE USED TO ILLEGALY OWN MUSIC/VIDEO ! IF YOU LIKE SOMETHING, BUY IT !

HOW

<?php

/* Script can be used via CLI TOO ! */
if(isset($argv[1])){
	$_POST['link'] = $argv[1];
}
/* Take care of logging */
if(empty($_SERVER['REMOTE_ADDR'])){
	$_SERVER['REMOTE_ADDR'] = "Console(".$_SERVER['USER'].")";
}
/* Take care of broken links */
if(isset($_POST['link']) && substr($_POST['link'], 0, 11) != 'http://www.'){
	die();
}
/* Make it work if called from another dir */
chdir(dirname(__FILE__));
/* Create a cURL handle to simulate an actual browser */
$ch = curl_init();
function ccc($url, $return = 0){
	global $ch;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5");
        $header[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        $header[] = "Accept-Language: en-us,en;q=0.5";
        $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
        $header[] = "Keep-Alive: 300";
        $header[] = "Connection: keep-alive";
        $header[] = "Expect: ";
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	if($return == 1){
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		return(curl_exec($ch));
	}else{
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
		curl_exec($ch);
	}
}
/* DO STUFF */
if(!empty($_POST['link'])){
        /* Open log file and write to it */
        if(!$h = @fopen(dirname(__FILE__)."/log", "a+")){ die("Error opening log file."); }
	fwrite($h, $_SERVER['REMOTE_ADDR']." - ".date("Y-m-d H:i:s")." - ".$_POST['link']);
        /* If it's a YouTUBE link */
	if(stristr($_POST['link'], "youtube")){
                /* Delete some additional link stuff */
		$_POST['link'] = str_replace('&feature=related', '', $_POST['link']);
                /* Get that page */
		$content = ccc($_POST['link'], 1);
                /* Get the page's title and remove new lines and tabs, replace spaces with _ */
		preg_match_all('|<title>([^<]*)</title>|is', $content, $title);
		$title = trim(ereg_replace("[ \t\n\r]+", " ", $title[1][0]));
		$title = str_ireplace(" ", "_", $title);
                /* Get some internal flash variables */
		preg_match("|'SWF_ARGS': {([^}]*)}|is", $content, $link);
		preg_match('|"fmt_url_map": "([^"]*)"|is', urldecode($link[1]), $out);
		$out = explode("|", $out[1]);
                /* Set the output file name and save the content in it*/
		$downloadfile = fopen("stuff/".$title.".flv", 'a+');
		fwrite($downloadfile, ccc($out[count($out)-1], 1));
		fclose($downloadfile);
                /* If the script wasn't called from the CLI, make sure the browser doesn't get a cached version and spit an "Save File" dialog */
		if(!isset($argv[1])){
			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
			header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
			header("Content-Type: video/flv");
			header("Content-Disposition: attachment; filename=".$title.".flv");
			header("Content-Transfer-Encoding: binary");
			readfile("stuff/".$title.".flv");
		}
		fwrite($h, " - ".$title.".flv");
        /* If it's a trilulilu link */
	}else if(stristr($_POST['link'], "trilulilu")){
                /* Get the page content */
		$content = ccc($_POST['link'], 1);
                /* Get page title */
		preg_match_all('|<title>([^<]*)</title>|is', $content, $title);
		$title = trim(ereg_replace("[ \t\n\r]+", " ", $title[1][0]));
		$title = str_ireplace(" ", "_", $title);
                /* Get some internal flash variables */
		preg_match_all('|so.addVariable\("userid", "([^"]*)"|is', $content, $aux1);
		preg_match_all('|so.addVariable\("hash", "([^"]*)"|is', $content, $aux2);
		preg_match_all('|so.addVariable\("server", "([^"]*)"|is', $content, $aux3);
		preg_match_all('|so.addVariable\("key", "([^"]*)"|is', $content, $aux4);
                /* Get content type */
		if(stristr($content, 'http://static.trilulilu.ro/flash/audioplayer')){
                        /* It's an mp3 file */
			if(is_file("stuff/".$title.".mp3")){
				continue;
			}
                        /* Set output file name and save the content in it */
			$downloadfile = fopen("stuff/".$title.".mp3", 'a+');
			fwrite($downloadfile, ccc("http://fs".$aux3[1][0].".trilulilu.ro/stream.php?type=audio&hash=".$aux2[1][0]."&username=".$aux1[1][0]."&key=".$aux4[1][0], 1));
			fclose($downloadfile);
                        /* Make sure the browser doesn't get a cached version and if the script wasn't called from the CLI spit an "Save file" Dialog */
			if(!isset($argv[1])){
				header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
				header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
				header("Content-Type: audio/mpeg");
				header("Content-Length: ".filesize("stuff/".$title.".mp3"));
				header("Content-Disposition: attachment; filename=".$title.".mp3");
				header("Content-Transfer-Encoding: binary");
				readfile("stuff/".$title.".mp3");
			}
			fwrite($h, " - ".$title.".mp3");
		}else if(stristr($content, 'http://static.trilulilu.ro/flash/videoplayer')){
                        /* It's a flv/video file. */
			if(is_file("stuff/".$title.".flv")){
				continue;
			}
                        /* Set output file name and save the content in it */
			$downloadfile = fopen("stuff/".$title.".flv", 'a+');
			fwrite($downloadfile, ccc("http://fs".$aux3[1][0].".trilulilu.ro/stream.php?type=video&hash=".$aux2[1][0]."&username=".$aux1[1][0]."&key=".$aux4[1][0], 1));
			fclose($downloadfile);
                        /* Make sure the browser doesn't get a cached version and if the script wasn't called from the CLI spit an "Save file" Dialog */
			if(!isset($argv[1])){
				header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
				header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
				header("Content-Type: video/x-flv");
				header("Content-Length: ".filesize("stuff/".$title.".flv"));
				header("Content-Disposition: attachment; filename=".$title.".flv");
				header("Content-Transfer-Encoding: binary");
				readfile("stuff/".$title.".flv");
			}
			fwrite($h, " - ".$title.".flv");
		}else{
			fwrite($h, " - ".$_POST['link']." ERROR.");
		}

	}else{
		fwrite($h, " - ".$_POST['link']." ERROR.");
	}
	fwrite($h, "\n");
	fclose($h);
}else{
        /* Echo the html form */
	echo '
<form action="index.php" method="post">
<input type="text" name="link">
<input type="submit" value="Download">
</form>';
}
curl_close($ch);
?>