title: signature issue when I want to get a direct URL from YouTube via PHP
body: <p>after research to how i get direct URL from YouTube videos like this one asking : <a href="https://stackoverflow.com/a/45652933/7511165">How to get direct URL of video from YouTube URL? [closed]</a></p>
  
  <p>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 </p>
  
  <p>it doesn't work with "signature" videos,</p>
  
  <p>this is my code:</p>
  
  <pre><code>if(isset($_GET['url']) &amp;&amp; $_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&amp;el=embedded&amp;ps=default&amp;eurl=&amp;gl=US&amp;hl=en");
      //var_dump(explode("&amp;",$dt));
      if (strpos($dt, 'status=fail') !== false) {
  
          $x=explode("&amp;",$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("&amp;",$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("&amp;",$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("&amp;",$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-&gt;error = true;
      $myObj-&gt;msg = "there is no youtube link";
  
      $myObj-&gt;madeBy = "El-zahaby";
      $myObj-&gt;instagram = "egy.js";
      $myJSON = json_encode($myObj,JSON_PRETTY_PRINT);
  
      echo $myJSON;
  
  }
  </code></pre>
  
  <p>example of issue : <a href="https://you-link.herokuapp.com/?url=yt.com?v=csy7cF1T2vk" rel="nofollow noreferrer">https://you-link.herokuapp.com/?url=yt.com?v=csy7cF1T2vk</a>
  <a href="https://i.stack.imgur.com/ehqYV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ehqYV.png" alt="signature error YouTube API "></a></p>
  
  <h2>update:</h2>
  
  <p>the code on : <a href="https://gist.github.com/el3zahaby/9e60f1ae3168c38cc0f0054c15cd6a83" rel="nofollow noreferrer">gist.github</a></p>
  
  <p>any solution ? thanks a lot </p>