-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoutube.php
More file actions
80 lines (66 loc) · 2.12 KB
/
youtube.php
File metadata and controls
80 lines (66 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Gostrafx;
/**
* Class Youtube
* @package Gostrafx
*/
class Youtube
{
/**
* @var
*/
private $url_id;
/**
* @param $id_video
* @return array|string
*/
public function set_url($id_video)
{
$video = $this->url_id = $id_video;
if (empty($video)) {
return "URL:ERROR";
}
preg_match("/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/", $video, $id);
$link = file_get_contents("http://www.youtube.com/get_video_info?video_id=" . $id[1] . "&el=embedded&ps=default&eurl=&gl=US&hl=en");
parse_str($link);
if (isset($url_encoded_fmt_stream_map)) {
$my_formats_array = explode(',', $url_encoded_fmt_stream_map);
}
if (count($my_formats_array) == 0) {
return 'No format stream map found - was the video id correct?';
}
$list = array();
$snipt = array("title" => $title, "thumbnails" => $iurl);
foreach ($my_formats_array as $format) {
parse_str($format);
parse_str(urldecode($url));
$list[] = array("size" => $this->formatBytes($this->get_size(urldecode($url))), "quality" => $quality, "type" => $mime, "link" => urldecode($url) . "&title=" . $title);
}
$table = array("snippet" => array("info" => $snipt, "video" => $list));
return $table;
}
/**
* @param $url
* @return string
*/
private function get_size($url)
{
$get_headers = get_headers($url, 1);
$content_length = $get_headers['Content-Length'];
return isset($content_length) ? $content_length : null;
}
/**
* @param $bytes
* @param int $precision
* @return string
*/
private function formatBytes($bytes, $precision = 2)
{
$units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
}