Pengen download video dari youtube? ngapain susah. nih gue kasih demo nya buat elo2 pada pake php.
DEMO dan download script dapat dilihat di sini.
<?php
/*
* youtube url downloader v0.2 - after youtube upgrade 29 agustus 2009
*
* by lemonade <firman@maxindo.net>
* donation is very appreciated, paypal: cool01@indosat.net.id
*
*
* ChangeLog
*
* v0.2
* 27/10/2009 - new parsing for youtube.
*
* v0.1
* 25/09/2009 - small fix for FLV url.
*
*/if(!empty($_REQUEST['yid'])) {
$yid = trim($_REQUEST['yid']);
$yid = urldecode(rawurldecode($yid));
if (preg_match('%http://www.youtube.com/watch?v=(.*)%s', $yid, $regs)) {
$yid = $regs[1];
}$url = 'http://www.youtube.com/watch?v=';
$url = $url.$yid;
$content = ambildari($url);
$hasil = lemonade_parse_youtube($content);if(count($hasil) == 2) {
//$hasil[0] <-- link mp4
//$hasil[1] <-- link flv//print_r($hasil);
$thumb = get_thumb_link($yid);
$output .= "Youtube URL: ".$url."n";
if($thumb) {
$output .= '<img src="'.$thumb.'"></img><br />';
}$output .= "<a href="".$hasil[0]."">MP4</a> | <a href="".$hasil[1]."">FLV</a>n";
echo nl2br($output);
}else {
$output = "Gak dapet resultnya boss!! maap2n";
nl2br($output);}
}
///////////////////////////////////////////////////////////////////// do not edit;
function ambildari($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$res = curl_exec($ch);curl_close($ch);
return $res;
}function lemonade_parse_youtube($string) {
if (preg_match('/SWF_ARGS': {(?:.*?) "fmt_url_map": "(.*?)"/s', $string, $regs)) {
$str = $regs[1];
$str = urldecode(rawurldecode($str));
$tes = explode("|",$str);
//print_r($tes);$fixme = strrchr($tes[1],",");
$tes[1] = str_replace($fixme,'',$tes[1]);$tes[2] = preg_replace('/id=(.*)(,.*)/', 'id=$1', $tes[2]);
return array($tes[1],$tes[2]);
}
else {
return 0;
}}
function get_thumb_link($yid) {
$thumburl = 'http://i' . mt_rand(1,4) .'.ytimg.com/vi/[YID]/default.jpg';
return str_replace('[YID]',$yid,$thumburl);
}?>