title: Get video duration with YouTube Data API?
body: <p>Basically, I'm trying to get the video duration of each video that shows up in the results when they search. I have a neat little demo set up for you to mess with!</p>
  
  <p>ALSO - When I say duration I mean the length of the video in M/S format (0:00)..</p>
  
  <p><strong>DEMO</strong> <a href="http://codepen.io/mistkaes/pen/6b6a347c7d24edee15b3491420db4ecd" rel="nofollow noreferrer">http://codepen.io/mistkaes/pen/6b6a347c7d24edee15b3491420db4ecd</a></p>
  
  <p><strong>jQuery:</strong></p>
  
  <pre><code>var apikey = '&lt;API KEY&gt;';
  
  $(function() {
      var searchField = $('#search-input');
  
      $('#search-form').submit(function(e) {
          e.preventDefault();
      });
  });
  
  function search() {
      $('#results').html('');
  
      q = $('#search-input').val();
  
      $.get(
          "https://www.googleapis.com/youtube/v3/search", {
              part: 'snippet, id',
              q: q,
              maxResults: 50,
              type: 'video',
              key: apikey
          },
          function(data) {
              $.each(data.items, function(i, item) {
                  var output = getResults(item);
  
                  $('#results').append(output);
              });
          });
  }
  
  function getResults(item) {
      var videoID = item.id.videoId;
      var title = item.snippet.title;
      var thumb = item.snippet.thumbnails.high.url;
      var channelTitle = item.snippet.channelTitle;
  
      var output = '&lt;li&gt;' +
          '&lt;div class="list-left"&gt;' +
          '&lt;img src="' + thumb + '"&gt;' +
          '&lt;/div&gt;' +
          '&lt;div class="list-right"&gt;' +
          '&lt;h3&gt;&lt;a href="http://youtube.com/embed/' + videoID + '?rel=0"&gt;' + title + '&lt;/a&gt;&lt;/h3&gt;' +
          '&lt;p class="cTitle"&gt;' + channelTitle + '&lt;/p&gt;' +
          '&lt;/div&gt;' +
          '&lt;/li&gt;' +
          '&lt;div class="clearfix"&gt;&lt;/div&gt;' +
          '';
  
      return output;
  }
  </code></pre>