0

I am trying to retrieve a particular playlist thumbnail of user but here I stuck - it is not getting the views and description of the video. I want to allow the video within my website only.

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>

<script type='text/javascript'>//<![CDATA[ 


   $(window).load(function() {
   function LoadVids(startindex) {
     if (typeof startindex === "undefined" || startindex === null) startindex = 1;
     var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/PL3B8939169E1256C0?orderby=published&v=2&alt=json&&start-index=' + startindex;
     var videoURL = 'http://www.youtube.com/watch?v=';
     $.getJSON(playListURL, function(data) {
       var list_data = "";
       $.each(data.feed.entry, function(i, item) {
         var feedTitle = item.title.$t;
         var feedURL = item.link[1].href;
         var fragments = feedURL.split("/");
         var videoID = fragments[fragments.length - 2];
         var vid = item.media$group.yt$videoid.$t;
         var url = videoURL + videoID;
         var vidtitle = item.title.$t;
         var thumb = "http://img.youtube.com/vi/" + videoID + "/default.jpg";
         list_data += ' < img alt = "'+ feedTitle+'"
         src = "'+ thumb +'"
         ' + ' - ' + vidtitle + '
         ';
       });
       $(list_data).appendTo(".cont");
     });
   }

   //
   $(document).ready(function() {
     LoadVids(1); // call on load more click
   });
 }); //
</script>   

</head>
<body>   
</body>
</html>
halfer
  • 19,824
  • 17
  • 99
  • 186
AizaMInd
  • 31
  • 1
  • 8
  • hi, welcome to stackoverflow! Read this [How to ask a good question](http://stackoverflow.com/help/how-to-ask) – Mivaweb Dec 24 '14 at 07:07

1 Answers1

0

Your ajax seems to be ok. But i can't find any "play function" in your code. For that, i suggest you jquery.tubeplayer:

http://www.tikku.com/jquery-youtube-tubeplayer-plugin

Little example:

 playVideo: function (events) {
        var self = this;
        var that = $(events.currentTarget);
        var videoId = that.parents('.videopreview').find('.youtubeimage').attr('data-link');
        that.parents('.videopreview').find('.youtubeimage').hide();
        that.parents('.videopreview').find('.playicon').css({
            "z-index": -20,
        });

        that.parents('.videopreview').find('.playvideo').tubeplayer({
            width: 279, // the width of the player
            height: 200, // the height of the player
            allowFullScreen: "true", // true by default, allow user to go full screen
            initialVideo: videoId, // the video that is loaded into the player
            autoPlay: true,
            preferredQuality: "default", // preferred quality: default, small, medium, large, hd720                  
        });
    },

Where "data-link" is the youtube video id: JavaScript REGEX: How do I get the YouTube video id from a URL?

In your script:

$.each(data.feed.entry, function(i, item) {
var feedTitle = item.title.$t;
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
var vid = item.media$group.yt$videoid.$t;
var url = videoURL + videoID;
var vidtitle = item.title.$t;
var description=item.media$group.media$description.$t;
var views=item.yt$statistics.viewCount;
var thumb = "http://img.youtube.com/vi/"+ videoID +"/default.jpg";
list_data += '
<img alt="'+ feedTitle+'" src="'+ thumb +'"' + ' - ' + vidtitle + '
';
});
$(list_data).appendTo(".cont"); 
});
Community
  • 1
  • 1
Fabian Lurz
  • 2,029
  • 6
  • 26
  • 52
  • Hii Fabian Everything is Working Fine But I am Not getting the Views and Description of the Videos with in the Playlist – AizaMInd Dec 25 '14 at 08:35
  • Ok i see. I entered the URL and i'm able to see the descriptions within the json. So i think your problem is, that the json file is confused. I suggest you to use the tool JSONView for chrome. Then you have a good overview of json and you can retrieve the descriptions. If that doesn't solve your problem just write again. – Fabian Lurz Dec 25 '14 at 10:41
  • Description: `item.media$group.media$description` Views: `item.yt$statistics.viewCount` – Fabian Lurz Dec 25 '14 at 11:35
  • No Its Not Working Sir Will You Please Where you inserted the strings in script please – AizaMInd Dec 25 '14 at 11:46
  • I forgot the .$t for the description. I edited my answer - hope this works. – Fabian Lurz Dec 25 '14 at 11:50
  • Fabian Lurz If you Dont Mine Will You Give your Fb Id to consult for doubts etc., – AizaMInd Dec 25 '14 at 11:55
  • Haha - thats fine. I give you my email: fabian@eese.com – Fabian Lurz Dec 25 '14 at 12:09