Bay East Video Counts
A tool for Eric and Joe to report on the video views.
by psyne
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.7.3/build/cssreset/cssreset-min.css">
<link rel="stylesheet" href="http://yui.yahooapis.com/3.7.3/build/cssfonts/cssfonts-min.css">
<link rel="stylesheet" href="http://yui.yahooapis.com/3.7.3/build/cssbase/cssbase-min.css">
<h1>Bay East Video Stats</h1>
<table id="video">
<thead>
<tr>
<th>Count</th>
<th>Title</th>
<th>Duration</th>
<th>Views</th>
</tr>
</thead>
<tbody></tbody>
</table>
JavaScript
var count = 0;
function getYouTubeAllInfo(perpage, page, recursive) {
$.getJSON('http://gdata.youtube.com/feeds/users/bayeastvideo/uploads?alt=json-in-script&callback=?&start-index=' + (((page - 1) * perpage) + 1) + '&max-results=' + perpage, function(data) {
$.each(data.feed.entry, function(i, item) {
var title = item['title']['$t'],
id = item['title']['$t'],
duration = secondsToTime(item.media$group.yt$duration.seconds),
views = item['yt$statistics']['viewCount'];
count++;
id = id.replace("http://gdata.youtube.com/feeds/videos/", "");
$("#video tbody").append('<tr id="' + id + '"><td>' +count+'</td><td>' + title + '</td><td> ' + duration + ' </td><td> ' + views + '</td> </tr>');
//alert(page+perpage-2);
if (i == perpage - 2 && recursive) {
getYouTubeAllInfo(perpage, page + 1, recursive);
}
});
});
}
getYouTubeAllInfo(49, 1, true);
function secondsToTime( seconds ){
var date = new Date(null);
date.setSeconds( seconds );
return date.toTimeString().substr(3, 5);
}