Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as PHP by YUNUS O. ( 14 years ago )
<?php
set_time_limit(0);
function source($vid){
$ch = curl_init();
curl_setopt($ch , CURLOPT_URL , 'http://www.youtube.com/watch?v='.$vid);
curl_setopt($ch , CURLOPT_RETURNTRANSFER , TRUE);
curl_setopt($ch , CURLOPT_COOKIEFILE , dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch , CURLOPT_COOKIEJAR , dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch , CURLOPT_USERAGENT , 'Firefox / 2.0.16');
curl_setopt($ch , CURLOPT_REFERER , 'http://www.youtube.com/watch?v=' . $vid);
$source = curl_exec($ch);
curl_close($ch);
return $source;
}
function downloadurl($source){
preg_match('/url_encoded_fmt_stream_map(.*?)\;/',$source,$preg);
$fmtmap = urldecode(urldecode(urldecode($preg[1])));
$fmtmaps = explode('url=',$fmtmap);
for($i = 0 , $c = count($fmtmaps) ; $i < $c ; $i++ )
{
if(
strpos($fmtmaps[$i],'quality=medium') !== FALSE &&
strpos($fmtmaps[$i],'video/x-flv') !== FALSE
)
{
$fmt = $fmtmaps[$i];
}
}
$fmt = explode('&fallback;_host',$fmt);
return $fmt[0];
}
function download($headers , $fileLocation, $fmturl){
if(array_key_exists('Location',$headers))
{
$url = parse_url($headers['Location']);
$dl = $headers['Location'];
}
else
{
$dl = $fmturl;
$url = parse_url($fmturl);
}
$fp = fopen($fileLocation , 'w+');
$ch = curl_init();
curl_setopt($ch , CURLOPT_URL , $dl);
curl_setopt($ch , CURLOPT_RETURNTRANSFER , TRUE);
curl_setopt($ch , CURLOPT_COOKIEFILE , dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch , CURLOPT_COOKIEJAR , dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch , CURLOPT_USERAGENT , 'Firefox / 2.0.16');
curl_setopt($ch , CURLOPT_REFERER , 'http://www.google.com/');
curl_setopt($ch , CURLOPT_FILE , $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
function cname($name){
$trk = array('ı','ğ','ü','ş','ö','ç','Ğ','Ü','Ş','İ','Ö','Ç',' ');
$eng = array('i','g','u','s','o','c','g','u','s','i','o','c','-');
$new = str_replace($trk,$eng,$name);
$new = preg_replace('/[^0-9A-Za-z-]/','',$new);
$new = preg_replace('/\-+/','-',$new);
$new = strtolower($new);
return $new;
}
$url = 'http://thenewboston.org/';
$watch = 'watch.php?cat=6&number;=';
$youtube = 'http://www.youtube.com/watch?w=';
$content = file_get_contents($url . 'list.php?cat=6');
preg_match_all('/href=\"watch.php\?cat=6\&number;=(.*?)\"/si',$content,$urls);
for($i = 0 ; $i < count($urls[1]); $i++){
$video = file_get_contents($url . $watch . $urls[1][$i]);
$video = explode('<a href="http://www.youtube.com/watch?v=',$video);
$video = explode('">Click here to watch this video on YouTube',$video[1]);
$videoID = $video[0];
$source = source($videoID);
$downloadURL = downloadurl($source);
$headers = get_headers($downloadURL);
$title = explode('<title>',$source);
$title = explode('</title>',$title[1]);
$title = $title[0];
download($headers,dirname(__FILE__) . '/video/' . cname($title) . '.flv',$downloadURL);
}
?>
Revise this Paste