Forked from liaohuqiu/gist:4ee77b9b03afcdecc80252252378d367
Last active
September 8, 2021 17:26
-
-
Save omargoda/6c22db35554a2cf8082ae2e200ccd593 to your computer and use it in GitHub Desktop.
Find out the full duration time of a YouTube playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list = document.getElementsByClassName('ytd-thumbnail-overlay-time-status-renderer'); | |
var time = 0; | |
function toS(hms) { | |
var a = hms.split(':'); | |
while (a.length < 3) { | |
a.unshift(0); | |
} | |
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]); | |
return seconds; | |
} | |
function toHMS(seconds) { | |
seconds = Number(seconds); | |
var d = Math.floor(seconds / (3600*24)); | |
var h = Math.floor(seconds % (3600*24) / 3600); | |
var m = Math.floor(seconds % 3600 / 60); | |
var s = Math.floor(seconds % 60); | |
var result = (d < 10 ? "0" + d : d) + ":" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s); | |
return result; | |
} | |
function add(item) { | |
var timeString = (item.innerText || item.textContent); | |
time += toS(timeString); | |
} | |
for (var i = 0; i < list.length; i++) { | |
var item = list[i]; | |
add(item); | |
} | |
console.log("The full duration time is: " + toHMS(time)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment