1+ var videoViewCount = [ ] , videoCommentCount = [ ] ,
2+ videoLikeCount = [ ] , videoDislikeCount = [ ] , videoFavoriteCount = [ ] ;
3+
4+ function getNewVideo ( ) {
5+ document . getElementById ( 'display' ) . innerHTML = '' ;
6+ this . keyword = prompt ( 'Enter Video Id/Title/keyword' , 'Developers@Work' ) ;
7+ searchVideosCode ( this . keyword ) ;
8+ videosCountCode ( videoId [ 0 ] ) ;
9+ displayVideosCount ( ) ;
10+ }
11+
12+ function videosCountCode ( YouTubeVideoId , i = 0 ) {
13+ var API_KEY = API ( ) ;
14+ $ . ajax ( {
15+ url :'https://www.googleapis.com/youtube/v3/videos' ,
16+ data :{
17+ key :API_KEY ,
18+ part :'statistics' ,
19+ id :YouTubeVideoId
20+ } ,
21+ async :false ,
22+ success :function ( data ) {
23+ var temp = data . items [ 0 ] ;
24+ videoViewCount [ i ] = temp . statistics . viewCount ;
25+ videoCommentCount [ i ] = temp . statistics . commentCount ;
26+ videoLikeCount [ i ] = temp . statistics . likeCount ;
27+ videoDislikeCount [ i ] = temp . statistics . dislikeCount ;
28+ videoFavoriteCount [ i ] = temp . statistics . favoriteCount ;
29+ }
30+ } ) ;
31+ }
32+
33+ function displayVideosCount ( i = 0 ) {
34+ $ ( '#display' ) . append ( '\
35+ <div id="video' + videoId [ i ] + '">\
36+ <img src="' + videoThumbnail [ i ] + '">\
37+ <h1 id="' + videoTitle [ i ] + '" onClick="getNewVideo()">' + videoTitle [ i ] + '</h1>\
38+ <h2 id="' + videoId [ i ] + 'views">Video Views : ' + videoViewCount [ i ] + '</h2>\
39+ <h2 id="' + videoId [ i ] + 'likes">Likes: ' + videoLikeCount [ i ] + '</h2>\
40+ <h2 id="' + videoId [ i ] + 'comments">Comments : ' + videoCommentCount [ i ] + '</h2>\
41+ <h2 id="' + videoId [ i ] + 'dislikes">Dislikes : ' + videoDislikeCount [ i ] + '</h2>\
42+ </div>\
43+ ' ) ;
44+ }
0 commit comments