From f7045b862a5b7c3de8ee2ea3da67616b38a667cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Eduardo?= Date: Sun, 6 Aug 2017 20:43:24 -0500 Subject: first commit --- init.php | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 init.php (limited to 'init.php') diff --git a/init.php b/init.php new file mode 100644 index 0000000..0f20e67 --- /dev/null +++ b/init.php @@ -0,0 +1,89 @@ + $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"; + } + } +} -- cgit v1.2.3