$name){
$instructions[] = array($functions[$name], $matches[3][$index]);
}
return $instructions;
}
}
}
return false;
}
// YouTube is capitalized twice because that's how youtube itself does it:
// https://developers.google.com/youtube/v3/code_samples/php
class YouTubeDownloader {
private $storage_dir;
private $cookie_dir;
private $itag_info = array(
18 => "MP4 360p",
22 => "MP4 720p (HD)",
37 => "MP4 1080",
38 => "MP4 3072p",
// questionable MP4s
59 => "MP4 480p",
78 => "MP4 480p",
43 => "WebM 360p",
17 => "3GP 144p"
);
function __construct(){
$this->storage_dir = sys_get_temp_dir();
$this->cookie_dir = sys_get_temp_dir();
}
function setStorageDir($dir){
$this->storage_dir = $dir;
}
// what identifies each request? user agent, cookies...
public function curl($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
//curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
public static function head($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_NOBODY, 1);
$result = curl_exec($ch);
curl_close($ch);
return http_parse_headers($result);
}
// html code of watch?v=aaa
private function getInstructions($html){
//
// check what player version that video is using
if(preg_match('@