-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
52 lines (49 loc) · 1.47 KB
/
test.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
<?php
function getDurationSeconds($duration){
preg_match_all('/[0-9]+[HMS]/',$duration,$matches);
$duration=0;
foreach($matches as $match){
//echo '<br> ========= <br>';
//print_r($match);
foreach($match as $portion){
$unite=substr($portion,strlen($portion)-1);
switch($unite){
case 'H':{
$duration += substr($portion,0,strlen($portion)-1)*60*60;
}break;
case 'M':{
$duration +=substr($portion,0,strlen($portion)-1)*60;
}break;
case 'S':{
$duration += substr($portion,0,strlen($portion)-1);
}break;
}
}
}
return $duration;
}
$youtube_id = "jadvt7CbH1o";
$api_key = "AIzaSyD_lT8RkN6KffGEfJ3xBcBgn2VZga-a05I";
$url = "https://www.googleapis.com/youtube/v3/videos?id=" . $youtube_id . "&key=" . $api_key . "%20&part=snippet,contentDetails,statistics,status";
$json = file_get_contents($url);
$data = json_decode($json);
$public = $data->items;
if (! $public)
{
echo 'Private';
}
else
{
$status = $data->items[0]->status;
$embeddable = $data->items[0]->status->embeddable;
if (!$embeddable)
{
echo 'Not allowed';
}
else
{
$duration = $data->items[0]->contentDetails->duration;
$duration = getDurationSeconds($duration);
}
}
?>