-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo.php
More file actions
73 lines (67 loc) · 2.33 KB
/
Copy pathvideo.php
File metadata and controls
73 lines (67 loc) · 2.33 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
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<title>Video Stuffs</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,400italic,700' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Droid+Sans+Mono|Roboto:400,400italic,700|Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>
<style type="text/css">
body { background-color: #fff; color: #222; font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; }
pre { font-family: 'Droid Sans Mono', monospace; }
div.wrapper { font-size: 0.8rem; }
</style>
</head>
<body>
<div class="wrapper" id="wrapper">
<?php
//https://www.youtube.com/watch?v=fXH8wlK3aOc
$video_uri = 'https://vimeo.com/116090051';
$video = embedUrl($video_uri);
?>
<pre><?php print_r($video); ?></pre>
<p><img src="<?php echo $video->image; ?>" alt="" width="380"></p>
</div>
</body>
</html>
<?php
function embedUrl($uri)
{
if(stripos($uri, 'youtube.com'))
{
$type = 'youtube';
$video_arr = parse_url($uri);
parse_str($video_arr['query'], $query_str);
$video_id = $query_str['v'];
$video_image = 'https://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg';
$video_uri = 'https://www.youtube.com/embed/' . $video_id . '?controls=0&rel=0';
}
elseif(stripos($uri, 'youtu.be'))
{
$type = 'youtube';
$video_id = str_ireplace('http://youtu.be/', '', $uri);
$video_image = 'https://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg';
$video_uri = 'https://www.youtube.com/embed/' . $video_id . '?controls=0&rel=0';
}
elseif(stripos($uri, '//vimeo.com'))
{
$type = 'vimeo';
$video_id = preg_replace( '(https?://vimeo.com/)', '', $uri );
$vimeo = unserialize(@file_get_contents('https://vimeo.com/api/v2/video/' . $video_id . '.php'));
$video_image = $vimeo[0]['thumbnail_large'];
$video_uri = 'https://player.vimeo.com/video/' . $video_id;
}
else
{
$type = '';
$video_id = '';
$video_image = '';
$video_uri = $uri;
}
$placeholder = 'http://placehold.it/1200x680/ccc/333/&text=Thumbnail%20not%20available';
$result = new stdClass();
$result->type = $type;
$result->id = $video_id;
$result->image = !empty($video_image) ? $video_image : $placeholder;
$result->uri = $video_uri;
return $result;
}