after research to how i get direct URL from YouTube videos like this one asking : How to get direct URL of video from YouTube URL? [closed]
i finally made a simple script to generate a direct URL from YouTube video with php and it works just fine, but not with all videos
it doesn't work with "signature" videos,
this is my code:
if(isset($_GET['url']) && $_GET['url'] != ""){
parse_str( parse_url( $_GET['url'], PHP_URL_QUERY ), $vars );
$id=$vars['v'];
$dt=file_get_contents("https://www.youtube.com/get_video_info?video_id=$id&el=embedded&ps=default&eurl=&gl=US&hl=en");
//var_dump(explode("&",$dt));
if (strpos($dt, 'status=fail') !== false) {
$x=explode("&",$dt);
$t=array(); $g=array(); $h=array();
foreach($x as $r){
$c=explode("=",$r);
$n=$c[0]; $v=$c[1];
$y=urldecode($v);
$t[$n]=$v;
}
$x=explode("&",$dt);
foreach($x as $r){
$c=explode("=",$r);
$n=$c[0]; $v=$c[1];
$h[$n]=urldecode($v);
}
$g[]=$h;
$g[0]['error'] = true;
$g[0]['instagram'] = "egy.js";
$g[0]['apiMadeBy'] = 'El-zahaby';
echo json_encode($g,JSON_PRETTY_PRINT);
}else{
$x=explode("&",$dt);
$t=array(); $g=array(); $h=array();
foreach($x as $r){
$c=explode("=",$r);
$n=$c[0]; $v=$c[1];
$y=urldecode($v);
$t[$n]=$v;
}
$streams = explode(',',urldecode($t['url_encoded_fmt_stream_map']));
foreach($streams as $dt){
$x=explode("&",$dt);
foreach($x as $r){
$c=explode("=",$r);
$n=$c[0]; $v=$c[1];
$h[$n]=urldecode($v);
}
$g[]=$h;
}
echo json_encode($g,JSON_PRETTY_PRINT);
// var_dump( $g[1]["quality"],true);
}
}else{
@$myObj->error = true;
$myObj->msg = "there is no youtube link";
$myObj->madeBy = "El-zahaby";
$myObj->instagram = "egy.js";
$myJSON = json_encode($myObj,JSON_PRETTY_PRINT);
echo $myJSON;
}
example of issue : https://you-link.herokuapp.com/?url=yt.com?v=csy7cF1T2vk
update:
the code on : gist.github
any solution ? thanks a lot
This is my solution based on the latest Youtube Website Update (2019).
For the video quality you can get only the low, for the medium or the HD quality you get the video separated AUDIO-LINK / VIDEO-LINK.
This is another code to get each video qualities from youtube get_video_info
With this method you can't get some videos ID data, if not allowed by owner. this is two examples :
Output :
This is another video ID not allowed by his owner.
Output :