Skip to content

Instantly share code, notes, and snippets.

@AhmedKamal20
Last active June 11, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhmedKamal20/a4db28bcb942cc40e047e0beaa16bb9a to your computer and use it in GitHub Desktop.
Save AhmedKamal20/a4db28bcb942cc40e047e0beaa16bb9a to your computer and use it in GitHub Desktop.
Get The Total Time of a Youtube Playlist
// Open You playlist
// Load all the videos in view
// Open The Console
var times = $x('//*[@id="pl-load-more-destination"]/tr/td[7]/div/div[1]/span');
var alltimes = new Array()
var timesec = new Array()
for (i = 0; i < times.length; i++) {
alltimes.push(times[i].innerHTML)
timesec.push(parseInt(alltimes[i].split(':')[0]*60) + parseInt(alltimes[i].split(':')[1]))
}
// http://stackoverflow.com/questions/1230233/how-to-find-the-sum-of-an-array-of-numbers
var sum = timesec.reduce(add, 0);
function add(a, b) {
return a + b;
}
// http://stackoverflow.com/questions/5539028/converting-seconds-into-hhmmss
function secondsToHms(d) {
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
return ((h > 0 ? h + ":" + (m < 10 ? "0" : "") : "") + m + ":" + (s < 10 ? "0" : "") + s); }
var sumInHours = secondsToHms(sum)
console.log("Time In Hours " + sumInHours)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment