showing results for - "javascript retrieve a youtube video title"
Laura
24 Mar 2020
1<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
2 <script type="text/javascript">
3 var vidid = "HSvoF8IfzRY";
4 function getYouTubeInfo() {
5 $.ajax({
6 url: "http://gdata.youtube.com/feeds/api/videos/"+vidid+"?v=2&alt=json&orderby=published&prettyprint=true",
7 dataType: "jsonp",
8 success: function (data) {parseresults(data)}
9 });
10 }
11 function parseresults(data) {
12 var ytvtit = data.entry.title.$t;
13 var ytvcat = data.entry.media$group.media$category[0].label;
14 var ytvpub = data.entry.published.$t.substr( 0, 10 );
15 var ytvath = data.entry.author[0].name.$t;
16 var ytvatl = data.entry.media$group.media$credit[0].$t;
17 var ytvdur = data.entry.media$group.yt$duration.seconds;
18 var ytvrta = data.entry.gd$rating.average.toFixed(1);
19 var ytvrtm = data.entry.gd$rating.max;
20 var ytvrtc = data.entry.gd$rating.numRaters;
21 var ytvlks = data.entry.yt$rating.numLikes;
22 var ytvdlk = data.entry.yt$rating.numDislikes;
23 var ytvvwc = data.entry.yt$statistics.viewCount;
24 var ytvfav = data.entry.yt$statistics.favoriteCount;
25 var ytvcmc = data.entry.gd$comments.gd$feedLink.countHint;
26 var ytvdes = data.entry.media$group.media$description.$t;
27 var ytvurl = 'https://www.youtube.com/watch?v='+vidid;
28 var ytvtmb0 = data.entry.media$group.media$thumbnail[0].url;
29 $('#ytvtitle').html(ytvtit);
30 $('#ytvcatgry').html(ytvcat);
31 $('#ytvpublish').html(ytvpub);
32 $('#ytvauthr').html('ytvath');
33 $('#ytvduration').html(ytvdur + ' Seconds' );
34 $('#ytvrtngavrg').html(ytvrta);
35 $('#ytvrtngmax').html(ytvrtm);
36 $('#ytvrtngcnt').html(ytvrtc);
37 $('#ytvlks').html(ytvlks);
38 $('#ytvdislks').html(ytvdlk);
39 $('#ytvviewcount').html(ytvvwc);
40 $('#ytvfavcount').html(ytvfav);
41 $('#ytvthumb').html('
42');
43 $('#ytvcomment').html(ytvcmc);
44 $('#ytvdescription').html(ytvdes);
45 $('#ytvurl').html('Watch on YouTube');
46 $('#ytvply').html('
47
48
49
50');
51 }
52 $(document).ready(function () {
53 getYouTubeInfo();
54 });
55 </script>