blob: 555a0819084f3e0c6ea752035533525cdbbc89f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?php
$yturllarge = "www.youtube.com";
$yturlshort = 'youtu.be/';
if (strpos($url, $yturlshort) !== false || strpos($url, $yturllarge) !== false ){
$link = $url;
$id = substr($link, -11); //Extract the youtube video ID
$format = "video/webm"; //the MIME type of the video. e.g. video/webm, etc.
parse_str(file_get_contents("https://youtube.com/get_video_info?video_id=".$id),$info); //decode the data
$streams = $info['url_encoded_fmt_stream_map'];
$streams = explode(',',$streams);
foreach($streams as $stream){
parse_str($stream,$data); //decode the stream
if(stripos($data['type'],$format) !== false){ //We've found the right stream with the correct format
$videoyt = $data['url']; //the video
}
}
}
|