[Javascript newb] Quick Youtube API help needed - 90% there! THANKS!

Discussion in 'JavaScript' started by ZachF, Aug 12, 2010.

  1. #1
    Alright,

    I have this very basic script to grab a users uploaded video urls and titles.

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript">$(function() {
        $.getJSON('http://gdata.youtube.com/feeds/users/fristopher/uploads?alt=json-in-script&callback=?&max-results=50', function(data) { 
            $.each(data.feed.entry, function(i, item) {
    	    var title = item['title']['$t'];
    	    var video = item['id']['$t'];
    	    video = video.replace('http://gdata.youtube.com/feeds/videos/','http://www.youtube.com/watch?v=');
    	    $('#youtube').append('<li class="videos"><p class="videoTitle">' +title+ '<br><br>'+video+'<br></div></li>');
            });
        });
    });
    </script>
    
    </head>
    
    <body>
    
    <ul id="videolist">
    <div id="youtube"></div>
    </ul>
    
    </body>
    
    Code (markup):
    Can someone modify the above code to also get me the youtube thumbnail for that video? (small thumbnail?)

    It basically needs the video id extracted from the +video+ url, since the image urls are dynamic like

    http://img.youtube.com/vi/VIDEO_ID/0.jpg


    But im stumped.

    Thanks


    Also, if you can go the extra mile.... how can i make it line break after each say 5 results? (php i'd use $i = 0 $i++ etc)

    If someone can post the ready to go code i would be one very happy camper. thanks so much for your time, i am completely new to javascript for all i know this is a cake walk!
     
    ZachF, Aug 12, 2010 IP