-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
executable file
·173 lines (136 loc) · 4.16 KB
/
app.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
require_once('vendor/autoload.php');
if(isset($_GET['id'])){
$lectureId = $_GET['id'];
}
else{
die('Parameter missing');
}
use Seld\JsonLint\JsonParser;
$parser = new JsonParser();
$json = file_get_contents('./data/'.$lectureId.'.json');
$json = $str = str_replace("\xEF\xBB\xBF",'',$json);
$obj = json_decode($json);
if (is_null($obj)) {
echo '<h3>Invalid config!</h3><b>';
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
echo '</b><br />';
if($parser->lint($json) != NULL){
echo '<pre>' . $parser->lint($json)->getMessage() . '</pre>';
echo '<hr>';
}
die("");
}
//echo '<pre>' . print_r($obj, true) . '</pre>';
$course = $obj->courses[0];
$chapters = $course->chapters;
function getVimeoIdFromUrl($url){
if (filter_var($url, FILTER_VALIDATE_URL) == TRUE) {
$parsedUrl = parse_url($url, PHP_URL_PATH);
$id = filter_var($parsedUrl, FILTER_SANITIZE_NUMBER_INT);
}
else{
$id = $url;
}
if(is_numeric($id)){
return $id;
}
else{
die('Not found');
}
}
function callVimeoApiByVideoId($id){
$context = stream_context_create(array(
'http' => array('ignore_errors' => true),
));
$json = file_get_contents('https://player.vimeo.com/video/'.$id.'/config', false, $context);
//var_dump($http_response_header);
$obj = json_decode($json);
return $obj;
}
function getValuesFromVimeo($obj){
// Deprecated
// $url = $obj->request->files->h264->sd->url;
usort($obj->request->files->progressive, function($a, $b) {
return $a->profile > $b->profile ? -1 : 1;
});
//$arrProgressiveLength = count($obj->request->files->progressive);
$url = $obj->request->files->progressive[0]->url;
/* Deprecated
if($obj->video->allow_hd == 1 && isset($obj->request->files->h264->hd->url)){
$url_hd = $obj->request->files->h264->hd->url;
$height = $obj->request->files->h264->hd->height;
$width = $obj->request->files->h264->hd->width;
}
else{
$url_hd = "null";
$height = $obj->request->files->h264->sd->height;
$width = $obj->request->files->h264->sd->width;
}*/
if($obj->video->allow_hd == 1 && isset($obj->request->files->progressive[1])){
$url_hd = $obj->request->files->progressive[1]->url;
$height = $obj->request->files->progressive[1]->height;
$width = $obj->request->files->progressive[1]->width;
}
else{
$url_hd = "null";
$height = $obj->request->files->progressive[0]->height;
$width = $obj->request->files->progressive[0]->width;
}
$duration = $obj->video->duration;
$size = '1280';
if(isset($obj->video->thumbs->$size)){
}
else{
$size = 960;
}
$thumb = $obj->video->thumbs->$size;
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPad')) {
$video = array(
"url" => "$url",
"url_hd" => $url_hd,
"poster" => $thumb,
"width" => $width,
"height" => $height,
"duration" => $duration
);
} else {
$video = array_merge(
array("sd" => $url,
($url_hd == null ? array() : array('hd' => $url_hd)),
"poster" => $thumb,
"width" => $width,
"height" => $height,
"duration" => $duration)
);
}
if(phpversion() <= 5.4){
$json = str_replace('\\/', '/', json_encode($video));
}
else{
$json = json_encode($video, JSON_UNESCAPED_SLASHES);
}
return $json;
}