Advertisement
Guest User

print json items in order??

a guest
Jun 2nd, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function searchVideos(user_search){
  2.     try{
  3.         $('#items_container').empty();
  4.         youtube.feeds.videos({
  5.                 q:              ''+user_search+'',
  6.                 'start-index' : ''+current_start_index+'',
  7.                 'max-results':  25,
  8.                 orderby:        'relevance'
  9.             },
  10.             function( err, data ) {
  11.             if( err instanceof Error ) {
  12.                 console.log( err )
  13.             } else {
  14.                 items=data.items
  15.                 current_prev_start_index=current_start_index;
  16.                 if (current_page == 1){
  17.                     $('.back').css({'display':'None'});
  18.                 } else {
  19.                     $('.back').css({'display':'block'});
  20.                     $('.next').css({'display':'block'});
  21.                 }
  22.                 if (items.length < 25) {
  23.                     $('.next').css({'display':'None'});
  24.                 }
  25.                 for(var i=0; i<items.length; i++) {
  26.                     video_loaded = false;
  27.                     truc = function() { getVideoInfos('http://www.youtube.com/watch?v='+items[i].id) }(i);
  28.                 }
  29.             }
  30.         });
  31.     }catch(err){
  32.         console.log('searchVideos err: '+err)
  33.     }
  34. }
  35.  
  36. function getVideoInfos(video_link){
  37.     try {
  38.         ytdl.getInfo(video_link, function(err,info){
  39.             if(err) {
  40.                 console.log(err);
  41.             } else {
  42.                 printVideoInfos(info);
  43.             }
  44.         });
  45.     } catch(err) {
  46.         console.log('getVideoInfos err: '+ err);
  47.     }
  48. }
  49.  
  50. function printVideoInfos(infos){
  51.     try{
  52.         var title = infos.title;
  53.         var thumb = infos.thumbnail_url;
  54.         var vid = infos.video_id;
  55.         $('#items_container').append('<div class="youtube_item"><img src="'+thumb+'" style="float:left;"/><p><b>'+title+'</b></p><div id="youtube_entry_res_'+vid+'"></div></div>');
  56.         //console.log(infos);
  57.         var num=infos.formats.length;
  58.         if ( parseInt(num) == 0) {
  59.                 return;
  60.         }
  61.         var resolutions = new Array([]);
  62.         for(var i=0; i<num; i++) {
  63.             var vlink = infos.formats[i].url;
  64.             var resolution = infos.formats[i].resolution;
  65.             var resolution_full = infos.fmt_list[i][1];
  66.             var container = infos.formats[i].container;
  67.             // if resolution is alreay available in webm continue...
  68.             if ( $.inArray(resolution, resolutions) > -1 ) {
  69.                 continue;
  70.             }
  71.             resolutions.push(resolution);
  72.             if (container == 'flv' || container == '3gp') {
  73.                 continue;
  74.             }
  75.             var img='';
  76.             if (resolution == "720p" || resolution == "1080p") {
  77.                 img='images/hd.png';
  78.             } else {
  79.                 img='images/sd.png';
  80.             }
  81.             $('#youtube_entry_res_'+vid).append('<div class="resolutions_container"><a class="video_link" href="'+vlink+'" alt="'+resolution+'"><img src="'+img+'" class="resolution_img" /><span>'+ resolution+'</span></a><a href="'+vlink+'" title="'+title+'.'+container+'" class="download_file"><img src="images/down_arrow.png" /></a></div>');
  82.         }
  83.         if ($('#youtube_entry_res_'+vid+' div a.video_link').length == 0){
  84.             $('#youtube_entry_res_'+vid).parent().remove();
  85.         }
  86.     } catch(err){
  87.         console.log('printVideoInfos err: '+);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement