Subscribe
Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Monday, 22 March 2010

YouTube Video Feed Slide-Show Gadget With JQuery Part 2

This is the second part in my ongoing series of posts which will show you how to get You-Tube video feed and build a simple carousel or slide-show for yourself. If you have not read the first part, please make sure you do so here Part1.
Target For The Post
A Javascript class which uses jquery and the youtube class designed earlier to create a slide show or carousel in any document or website.

Class To Design

  1. tubeslider
  2. SlideTimer
tubeslider methods
  1. initex(tube_data)
  2. start()
  3. stop()
tubeslider class variables

   1. this.timer_obj -----> stores the object of SlideTimer class
   2. this.timer_interval -> stores the user-defined speed in milliseconds
   3. this.divid ----------> stores the original div given by the user where this slider will be created
   4.  this.slider ---------> stores the new div created by the program used to slide the images or videos
   5.  this.master --------> stores the string to identify the main div given by the user, for jQuery it has a #                    infront of it

global variables

  1. var thumb_width -----> stores the thumb width
  2. var master_width -----> stores the mast_div width
  3. var thumb_height------> stores the thumb height

tubeslider constructor

   function(doc, divid, timer_interval) 
parameter doc is for future use and is not used anywhere at present
divid is the id of the div where you want your slider or gadget to reside
timer_interval is the speed in which you want the slider to move

remove any previous instance of the SlideTimer class and attach the CSS stylesheet to the document.

 if (this.timer_obj != null && this.timer_obj != undefined) {
        this.timer_obj.stop();
        delete this.timer_obj;
    }

    this.timer_obj = null;
    var slider_css = document.createElement('link');
    slider_css.rel = 'stylesheet'
    slider_css.type = 'text/css';
    slider_css.href = 'youtubeslider.css';
    document.getElementsByTagName('head')[0].appendChild(slider_css);
This function is the main function for this class, it receives the data in double dimension array called tube_data, then it initializes the thumb_width and height based on the data which is available and not the any random value, by default all the thumb size should be the same yet we search for the first legitimate thumb size and use it in our program.
var j = 0;
        while (j < tube_data.length && tube_data[j]["thumb_url"] == '#') {
            j++;
        }
        if (j >= tube_data.length)
            return -1;
        var k = 0;
        for (var i_loop = 0; i_loop < tube_data.length; i_loop++) {
            if (tube_data[i_loop]['thumb_url'] != '#')
                k++;
        }
        master_width = (parseInt(tube_data[j]["thumb_width"]) + 10) * (k);
        thumb_width = parseInt(tube_data[j]["thumb_width"]);
        thumb_height = parseInt(tube_data[j]["thumb_height"]);
Next we remove any previous divs inside the main div and create two divs one as the container for the slider and one for the player or the window where the video will be played when it is clicked. The div is also inside the main div thus it cannot be created outside the main div body. Inside the player div there are two divs first one has a link when clicked it will close the window and the other one will house the player. Then we create the slider div to house all the clickable thumbnails
var temp2 = temp + ' > div';
        $(temp2).remove();
        $(temp).css('position', 'absolute');
        $(temp).append("
"); $(temp).append("
" + "
"); var close_win = '#' + this.divid + '_close'; var temp_id2 = this.divid; $(close_win).click(function(event) { event.preventDefault(); if (temp_id2.charAt(0) != '#') temp_id2 = '#' + temp_id2 + '_player'; $(temp_id2).hide(); }); var master_id1 = '#' + this.divid + '_player'; var player_width1 = parseInt($(master_id1).css('width')); var player_height1 = parseInt($(master_id1).css('height')) - 17; //div to show the text temp2 += ":first"; this.master = temp + "master"; this.slider = this.divid + '_slider'; $(this.master).addClass('master'); $(this.master).append("
");
Next step is to create a image as link for the the videos which has been sent through tube_data, when we draw these images we must make sure that the url property has a valid url and not a # symbol, which signifies that the video has been blocked by the content provider.
 this.slider = '#' + this.slider;
        for (var i = 0; i < tube_data.length; i++) {
            if (tube_data[i]["thumb_url"] != '#') {
                var div_tag = "
"; var a_tag = ""; var img_tag = ""; var ending_tags = "" + tube_data[i]['thumb_title'] + "(vid " + tube_data[i]['vid'] + ")" + "
"; $(this.slider).append(div_tag + a_tag + img_tag + ending_tags); } }
After we have the slider ready to rumble the next thing is to create a timer object so that at a predefined interval the slider div is moved by a certain amount. If mouse is hovered over the images it must stop the slide or the timer until the mouse moves out of the div. In this we use jquery $.hover() function which gives us the opportunity to declare two functions one is fired when mouse is moved over and the second is fired when the mouse is moved out. For ease of programming we have used anonymous functions.
        var local_slider = this.slider;
        var local_master = this.master;
        var temp_del = this.slider + " > div"
        this.timer_obj = new SlideTimer(this.slider, this.master, this.timer_interval, this);
        var timer_obj_ref = this.timer_obj;

$(temp_del).hover(function() {
            timer_obj_ref.stop();
            var id_text = $(this).attr('id');
            if (id_text != undefined || id_text == '') {
                var i = id_text.length - 1;

                var chr_txt = id_text.charAt(i);
                while (!isNaN(parseInt(chr_txt))) {
                    i--;
                    var chr_txt = id_text.charAt(i);
                }
                id_text = id_text.substr(0, (i + 1));
                var txt_div = '#' + id_text + '_text';

                $(txt_div).css('display', 'block');
                $(txt_div).html("" + $(this).text() + "");



            }

        },
        function() {
            timer_obj_ref.start();
            var id_text = $(this).attr('id');
            if (id_text != undefined || id_text == '') {
                var i = id_text.length - 1;

                var chr_txt = id_text.charAt(i);
                while (!isNaN(parseInt(chr_txt))) {
                    i--;
                    var chr_txt = id_text.charAt(i);
                }
                id_text = id_text.substr(0, (i + 1));
                var txt_div = '#' + id_text + '_text';
                $(txt_div).css('display', 'none');
            }

        });

Lets say you want to watch some particular video, the logical thing will be to click on the image and it should play. To do so we must trap the click event and show the player div which we created earlier with the embedded player and the correct url.
var master_id = this.divid;
        $(temp_del).click(function(event) {
            timer_obj_ref.stop();
            event.preventDefault();
            var vid_text = $(this).text();

            if (vid_text != undefined || vid_text == '') {
                var i = vid_text.length - 1;
                var vid_mark1 = vid_text.indexOf('(vid');
                var vid_mark2 = -1;
                if (vid_mark1 != -1) {
                    vid_mark1 += 4;
                    vid_text = vid_text.substr(vid_mark1, ((vid_text.length - 1) - vid_mark1));
                }

                var playerid = '#' + master_id + '_player';
                vid_text = vid_text.replace(/^\s+|\s+$/g, "");

                var player_width = parseInt($(playerid).css('width'));
                var player_height = parseInt($(playerid).css('height'));

                var str_player = '<object style="position:relative;display:block;top:15px;left:1px;height' +
                (player_height - 17).toString() + 'px; width:' + (player_width - 2).toString() + 'px">' +
                '<param name="movie" value="http://www.youtube.com/v/' + vid_text +
                '?version=3&iv_load_police=3&autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&feature=player_embedded">' +
                '<param name="allowFullScreen" value="true">' +
                '<param name="allowScriptAccess" value="always">' +
                '<embed src="http://www.youtube.com/v/' + vid_text +
                '?version=3&iv_load_police=3&autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&feature=player_embedded" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="' +
                 (player_width - 2).toString() + '" height="' + (player_height - 17).toString() + '"></object>'

                $(playerid).css('display', 'block');

                var player_div = '#' + master_id + '_ytapiplayer';
                $(player_div).html(str_player);

            }
        });

The next two functions are trivial, they just start or stops the slide action for the user, actually it starts or stops the timer through the timer object declared earlier.
this.start = function() {
        if (this.timer_obj != null && this.timer_obj != undefined)
            this.timer_obj.start();
    }
    this.stop = function() {
        if (this.timer_obj != null && this.timer_obj != undefined)
            this.timer_obj.stop();
        delete (this.timer_obj);
        this.timer_obj = null;
    }
This is the complete code for our tubeslider class now comes the timer class which controls the timer object.

  SlideTimer Variables


 1. this.slider = slider; 
 2. this.master = master; 
 3. this.obj = slide_obj;
 4. this.timer_interval = timer_interval; 5. this.timerid = null;

SlideTimer Methods


1. start()
2. stop()
3. slideImages()

The first two methods are trivial they just initiate a setInterval function in the start method and clearInterval in the stop method. The only point to be noted is that setInterval creates an anonymous function which in turn calls the slideImages method.This is done in this way because a normal setInterval takes the function name only and does not allow you to prefix it with this to show a class method.
slideImages function uses the jQuery animate function to move the slider on the left by a fixed amount, if the whole slider has moved out of the screen i.e. it is no longer visible the start position is reintialized to the extreme left of the master div which we created in the earlier class as wrapper for the slider and player div.




SlideTimer = function(slider, master, timer_interval, slide_obj) {

    this.slider = slider;

    this.master = master;

    this.obj = slide_obj;

    this.timer_interval = timer_interval;

    this.timerid = null;

    this.start = function() {

       

        thisobject = this;

        this.timerid = setInterval(function() { thisobject.slideImages(); }, this.timer_interval); //"' + slider + '","' + master + '","' + obj + '")', 6000);



    }

    this.stop = function() {

        clearInterval(this.timerid);

    }





    this.slideImages = function() {

       

        var left_attr = parseInt($(this.slider).css('left'));

        var width_attr = parseInt($(this.master).css('width'));

        var slider_width = parseInt($(this.slider).css('width'));

        var animate_str = '-=' + thumb_width.toString();

        if (left_attr > (1 - (slider_width - Math.ceil((thumb_width ))))) {

            left_attr -= thumb_width;



        }

        else {

            left_attr = width_attr - (thumb_width * 2);

           

            $(this.slider).css('left', left_attr.toString() + 'px');

          

        }

     

        $(this.slider).animate({ left: animate_str }, 'slow');

       



    }

}





If you want to download the whole code please go to http://coolnerdblogger.com/mydownloads/YoutubeSlide/YouTubeSlide.php
If you want to test it out first then visit
http://coolnerdblogger.com/mydownloads/YoutubeSlide/jQueryAndYouTube.html
For more updates subscribe to my feed and checkout the videos of these posts, the video for the first part is already online check it out.

Thursday, 18 March 2010

YouTube Video Feed Slide-Show Gadget With JQuery Part 1

This is the first part in what is going to be a two or three part tutorial dealing with using the YouTube Feed API to create a slide show of videos which you prefer, not some random images but based on the search criteria or playlist or uploaded videos by the user of your choice.

Target For This Post
Part 1:
A java script class which can request a video feed from YouTube based on your selection criteria and then parse the feed returned to you. This will be done without any server-side script. The class can return an array which will have the following six attributes for each video.

thumb_title The title to be shown for the video
thumb_img The thumbnail which will represent the video
thumb_height The height of the thumbnail
thumb_width The width of the thumbnail
thumb_url The url of the video
vid Video Id used by youtube to identify a video uniquely
This class will have the following major methods
  • getUploadedVideos (username, format)
  • getSearchVideos(tag_txt, boolean_op, format)
  • getPlayListVideos(username, playlist, format)
  • startTubeSlideShow(player_div_id, seconds)
  • stopTubeSlideShow()
Technology Used
  1. Google Data API’s
  2. jQuery
  3. Javascript
  4. HTML
Google Data API has been used to request video RSS feed from the google or you-tube sever. The format which I have used is json-in-script format. For more details about this format please click here. The Google Data API has a very rich and fulfilling  structure. It can be modified in any way you want. If you are using proxies and are interested in getting an XML RSS feed no problem just add alt=rss to your request url and you will get in pure RSS 2.0 format. To learn more about this API you can visit here.
courtesy Google
Name Definition
alt The alt parameter specifies the format of the feed to be returned. Valid values for this parameter are atom, rss, json, json-in-script, and jsonc. The default value is atom and this document only explains the format of Atom responses. For more information about using API responses in JavaScript, please see Using JSON with Google Data APIs.
If you set the parameter value to json-in-script, then you must also set the
callback parameter value to identify the callback function to which the API response will be sent.
author In a search request, the author parameter restricts the search to videos uploaded by a particular YouTube user. Note that if you use this parameter when requesting a standard feed, then YouTube will retrieve the standard feed and then filter the response to only include videos uploaded by the specified author. For example, if you request the "Top Rated" feed for user GoogleDevelopers, the API will retrieve the top-rated feed and return a response containing videos in that feed uploaded by user GoogleDevelopers. The API will not return a list of that user's videos ordered by rating. 
In a request for a user activity feed, the author parameter contains a comma-separated list of up to 20 YouTube usernames. The API response will contain activities performed by any of those users.
callback The callback parameter identifies the callback function to which the API response will be sent. If the value of the alt parameter is jsonc or json-in-script, and you specify a value for the callback parameter, then the API response will be wrapped in a call to the specified function. This parameter is required if the value of the alt parameter is json-in-script.
max-results The max-results parameter specifies the maximum number of results that should be included in the result set. This parameter works in conjunction with the start-index parameter to determine which results to return. For example, to request the second set of 10 results – i.e. results 11-20 – set the max-results parameter to 10 and the start-index parameter to 11. The default value of this parameter is 25, and the maximum value is 50. However, for displaying lists of videos, we recommend that you set the max-results parameter to 10.
prettyprint The prettyprint parameter lets you request an XML response formatted with indentations and line breaks. Set the parameter's value to true to have the response formatted as such. The default parameter value is false.
start-index The start-index parameter specifies the index of the first matching result that should be included in the result set. This parameter uses a one-based index, meaning the first result is 1, the second result is 2 and so forth. This parameter works in conjunction with the max-results parameter to determine which results to return. For example, to request the second set of 10 results – i.e. results 11-20 – set the start-index parameter to11 and the max-results parameter to 10.
strict The strict parameter can be used to instruct YouTube to reject an API request if the request contains invalid request parameters. The default API behavior is to ignore invalid request parameters. If you want YouTube to reject API requests that contain invalid parameters, set the strictparameter value to true. For example, YouTube would reject the following request because "foo" is not a valid request parameter.
http://gdata.youtube.com/feeds/api/videos?foo=nonono&strict=true
v The v parameter specifies the version of the API that YouTube should use to handle the API request. Your request can specify the desired API version using either the v parameter or the GData-Version HTTP request header. All Google-provided client libraries always select a major API version. If your request does not specify an API version, YouTube will handle your request using API version 1. Please see the API versioningsection for more information about specifying an API version.

Say for instance you want to search for videos with a tag India the URL will be something like this
http://gdata.youtube.com/feeds/videos?alt=json-in-script&callback=?&q=India
In our case due to the use of jQuery which provides a call back for us we leave the callback value blank, but remember if you do not provide a question mark infront of the call back the computer will not make any request because of the strange way jQuery works.(I am not complaining).
jQuery has a method called . This method is wonderful and my new favourite because if any feed returns JSON then you can use getJSON to make a cross domain XMLHTTPRequest without those proxies and server side code. Yes it does take advantage of a security hole in the browser. However I believe very soon such requests will become a common place occurrence if it is not already so.
Essentially I ask jquery to brig some result and then I parse it using javascript. Because getJSON can work Asynchronously therefore my whole website is not blocked and I can assign a call back function which is fired when the server returns the data. Again the beauty of javascript is I can use anonymous functions as a call back instead of separate functions.
jQuery.getJSON( url, [ data ], [ callback(data, textStatus) ] )
urlA string containing the URL to which the request is sent.
dataA map or string that is sent to the server with the request.
callback(data, textStatus)A callback function that is executed if the request succeeds.


HTML has been used to create the front end and is inserted in the document as and when required by the various parts.

Short-coming
I have used few global variables to make my life easier, if you find any other method to overcome the problems please feel free to mail me.
The CSS is amateurish if not childish but the beauty of this code is you can change the CSS to suit your own fancies.


simpleTube.js
This file has the code which connects with Google to request anything that you require

SimpleTube this is the class which is has the functions dealing with playlist,search and uploaded videos.

getUploadedVideos Bring all the videos which are publicly available from a particular user


this.getUploadedVideos = function(username, format) {     
        var q = "http://gdata.youtube.com/feeds/api/users/" + username + "/uploads?alt=json-in-script&callback=?" ;
        if (format == '5') { 
            q += "&format=5";
        } 
        $.getJSON(q, function(json) {
            var htmlstr = ''; 
            tube_data = new Array(json.feed.entry.length);
            $.each(json.feed.entry, function(i, pl_item) {
                  tube_data[i] = new Array(6);
                if (pl_item['app$control'] != undefined && pl_item['app$control']['yt$state'] != undefined) {
  
                   var thumb = pl_item['app$control']['yt$state']['$t'];
                   var url = '#';
                   tube_data[i]["thumb_url"] = '#';
                   tube_data[i]["vid"] = pl_item['app$control']['yt$state']['$t'];
  
                } 
                else {
                    tube_data[i]["thumb_title"] = pl_item['title']['$t'];
                    tube_data[i]["thumb_img"] = pl_item['media$group']['media$thumbnail'][0]['url'];
                    tube_data[i]["thumb_width"] = pl_item['media$group']['media$thumbnail'][0]['width'];
                    tube_data[i]["thumb_height"] = pl_item['media$group']['media$thumbnail'][0]['height'];
                   tube_data[i]["thumb_url"] = pl_item['media$group']['media$player'][0]['url']
                  var vid_1 = tube_data[i]["thumb_url"].search('v=');
                  var vid_2 = tube_data[i]["thumb_url"].search('&feature');
                  var vid_len = vid_2 - (vid_1 + 2);
                 tube_data[i]["vid"] = tube_data[i]["thumb_url"].substr(vid_1 + 2, vid_len);
  
                } 

            }); 


        });

  
    }
This function is the easiest one as it accepts a username and the format(I will explain it later). The username is the user whose video you want to watch. As long as there is no restriction placed by the uploader you can easily get all the videos. Once we get the videos we parse the JSON in a double dimension array. for the first part we will not do anything with this array in the next part I will show you how to use this array. Format, if you place 5 as the format parameter then all the videos which cannot be embedded and are blocked or removed, are not included in the search, thus it brings only those videos which can be embedded.
$.getJSON(q, function(json) {
in this line I make a call to youtube for the videos and when the query returns with result the anonymous function gets called which has the result in the variable called json.

$.each(json.feed.entry, function(i, pl_item) {
for each entry of the feed an anonymous function is called which has a counter i, incremented automatically and that particular entry in the variable called pl_item.

if (pl_item['app$control'] != undefined && pl_item['app$control']['yt$state'] != undefined) {


checks to make sure that the video thus available can be used and is not blocked or removed. If the video has a problem then the thumb_url property is given a value of #. this will be used later to filter out the undesired content.

tube_data[i]["vid"] = pl_item['app$control']['yt$state']['$t'];


this stores the reason if any for the video being not available. If the video is usable then the five properties thumbnail width,height,and the src with video url and title are stored then we parse the url string for the VID or the video id used by youtube to uniquely identify a video and needed for loadind a video in a player.


getSearchVideos bring all the videos according to the tags and the boolean operator specified. Three operators are possible and or and random. If you say rand or random then the number of tags and the tags are chosen randomly thus each time the video might be a bit different.


this.getSearchVideos = function(tag_txt, boolean_op, format) {
        var tag_arr = tag_txt.split(',');
        var q = "http://gdata.youtube.com/feeds/videos?max-results=40&alt=json-in-script&callback=?&orderby=relevance&sortorder=descending&q=";

        var j = 0;

        var k = 0;

        var qstring = '';
        if (boolean_op == 'and') {

            qstring = "%22" + tag_arr[0];

            for (k = 1; k < tag_arr.length; k++) {

                qstring += "+" + tag_arr[k];

            }

            qstring += "%22";

        }

        if (boolean_op == 'or') {

            qstring = tag_arr[0];

            for (k = 1; k < tag_arr.length; k++) {

                qstring += "%7c" + tag_arr[k];

            }

        }

        if (boolean_op == 'rand') {
            var randomnumber = Math.floor(Math.random() * (tag_arr.length - 1)) + 1;
            qstring = tag_arr[randomnumber];
            for (k = 0; k <= randomnumber; k++) {
                randomnumber = Math.floor(Math.random() * tag_arr.length);
                qstring += "%7c" + tag_arr[randomnumber];

            }

        }


        q = q + qstring;

        if (format == '5')

            q += "&format=5";
        $.getJSON(q, function(data) {

            var htmlstr = '';

            tube_data = new Array(data.feed.entry.length);

            $.each(data.feed.entry, function(i, feed_item) {

                tube_data[i] = new Array(6);

                if (feed_item['app$control'] != undefined && feed_item['app$control']['yt$state'] != undefined) {

                    var thumb = feed_item['app$control']['yt$state']['$t'];

                    var url = '#';

                    tube_data[i]["thumb_url"] = '#';

                    tube_data[i]["vid"] = feed_item['app$control']['yt$state']['$t'];

                }

                else {

                    tube_data[i]["thumb_title"] = feed_item['title']['$t'];
                    tube_data[i]["thumb_img"] = feed_item['media$group']['media$thumbnail'][0]['url'];
                    tube_data[i]["thumb_width"] = feed_item['media$group']['media$thumbnail'][0]['width'];
                    tube_data[i]["thumb_height"] = feed_item['media$group']['media$thumbnail'][0]['height'];
                    tube_data[i]["thumb_url"] = feed_item['media$group']['media$player'][0]['url']
                    var vid_1 = tube_data[i]["thumb_url"].search('v=');

                    var vid_2 = tube_data[i]["thumb_url"].search('&feature');

                    var vid_len = vid_2 - (vid_1 + 2);

                    tube_data[i]["vid"] = tube_data[i]["thumb_url"].substr(vid_1 + 2, vid_len);

                }

            });
   
        });

    }


This function is a bit more involved because it combines all the tags depending on the user choice. User can ask all the tags to be compulsory(and), any of the tags(or). The user might like a sub-set of new tags to be used from the original tag each time the program is executed.

var randomnumber = Math.floor(Math.random() * (tag_arr.length - 1)) + 1;
            qstring = tag_arr[randomnumber];

            for (k = 0; k <= randomnumber; k++) {
                randomnumber = Math.floor(Math.random() * tag_arr.length);
                qstring += "%7c" + tag_arr[randomnumber];

            }


The Lines above just choose a random number which signifies the number of tags to be considered and then inside a loop each time a new random number is generated to signify the tag chosen.


getPlayListVideos This function gets a playlist depending on the user-name and the playlist name. Unfortunately only those play list are available which have been marked public by the creator, if any play-list is marked as private it will not be available through this function.


this.getPlayListVideos = function(username, playlist, format) {

        var q = "http://gdata.youtube.com/feeds/api/users/" + username + "/playlists?alt=json-in-script";

        q += "&callback=?";

        $.getJSON(q, function(data) {





            $.each(data.feed.entry, function(i, item) {

                var title = item['title']['$t'];

                if (title.toLowerCase() == playlist.toLowerCase())

                    q = item['gd$feedLink'][0]['href'];





            });

            if (format == '5')

                q += "?alt=json-in-script&callback=?&format=5";

            else

                q += "?alt=json-in-script&callback=?&format=5";

            $.getJSON(q, function(json) {

                var htmlstr = '';



                tube_data = new Array(json.feed.entry.length);

                $.each(json.feed.entry, function(i, pl_item) {

                    var title2 = pl_item['media$group']['media$title']['$t'];



                    tube_data[i] = new Array(6)

                    if (pl_item['app$control'] != undefined && pl_item['app$control']['yt$state'] != undefined) {

                        var thumb = pl_item['app$control']['yt$state']['$t'];

                        var url = '#';

                        tube_data[i]["thumb_url"] = '#';

                        tube_data[i]["vid"] = pl_item['app$control']['yt$state']['$t'];

                    }



                    else {

                        tube_data[i]["thumb_title"] = pl_item['title']['$t'];

                        tube_data[i]["thumb_img"] = pl_item['media$group']['media$thumbnail'][0]['url'];

                        tube_data[i]["thumb_width"] = pl_item['media$group']['media$thumbnail'][0]['width'];

                        tube_data[i]["thumb_height"] = pl_item['media$group']['media$thumbnail'][0]['height'];

                        tube_data[i]["thumb_url"] = pl_item['media$group']['media$player'][0]['url']

                        var vid_1 = tube_data[i]["thumb_url"].search('v=');

                        var vid_2 = tube_data[i]["thumb_url"].search('&feature');

                        var vid_len = vid_2 - (vid_1 + 2);

                        tube_data[i]["vid"] = tube_data[i]["thumb_url"].substr(vid_1 + 2, vid_len);

                    }





                });

            });

    });



    }


This function has two getJSON calls why because, the first call brings all the playlist of the user specified. Then the url for the playlist specified is parsed from the first feed result. After this we get the actual request URL for the playlist. this url is used to fire the second request.
The second request brings the videos and their data.
As mentioned earlier, I have not shown you how to use the parsed data because that is another post may be later in the week. I will put up a test page and a you tube video for the full code very soon. Please subscribe to my feed for further updates. If you want to watch a real-life example please click here or visit http://coolnerdblogger.com/mydownloads/YoutubeSlide/jQueryAndYouTube.html


 
EatonWeb Blog Directory