title: Get duration from a youtube url
body: <p>Im looking for a function that will pull the youtube duration of a video from the url. I read some tutorials but don't get it. I embed videos on my site using a url and I have a function that pulls the thumbnail and I just want something similar that gets the duration. Here's how I get the thumb...</p>
  
  <pre><code>function get_youtube_screen_link( $url = '', $type = 'default', $echo = true ) {
  if( empty( $url ) )
      return false;
  
  if( !isset( $type ) )
      $type = '';
  
  $url = esc_url( $url );
  
  preg_match("|[\\?&amp;]v=([^&amp;#]*)|",$url,$vid_id);
  
  if( !isset( $vid_id[1] ) )
      return false;
  
  $img_server_num =  'i'. rand(1,4);
  
  switch( $type ) {
      case 'large':
          $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/0.jpg";
          break;
      case 'first':
          // Thumbnail of the first frame
          $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/1.jpg";
          break;
      case 'small':
          // Thumbnail of a later frame(i'm not sure how they determine this)
          $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/2.jpg";
          break;
      case 'default':
      case '':
      default:
          $img_link = "http://{$img_server_num}.ytimg.com/vi/{$vid_id[1]}/default.jpg";
          break;
  }
  if( $echo )
      echo $img_link;
  else
      return $img_link;
  </code></pre>
  
  <p>}</p>