$format_info['itag'], 'quality' => $quality, 'type' => $type, 'libretype' => $libretype, 'url' => $format_info['url'], 'size' => getSize($format_info['url']), ]; } return $available_formats; } function getSize($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $r = curl_exec($ch); foreach (explode("\n", $r) as $header) { if (strpos($header, 'Content-Length:') === 0) { return intval(intval(trim(substr($header, 16)))/ (1024*1024)) . " MB"; } } }