Created
September 15, 2020 12:51
-
-
Save tarcisiozf/061c4513749f331b58f405ed84f91121 to your computer and use it in GitHub Desktop.
calculate youtube playlist duration
This file contains 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
MINUTE = 60 | |
HOUR = 60 * MINUTE | |
DAY = 24 * HOUR | |
timeToSeconds = (time) => { | |
let base = 1 | |
return time.split(':') | |
.reverse() | |
.map(Number) | |
.reduce((acc, val) => | |
acc + (val * Math.pow(60, base++)) | |
) | |
} | |
sum = (acc, val) => acc + val | |
total = | |
Array.from(document.querySelectorAll('span.ytd-thumbnail-overlay-time-status-renderer')) | |
.map(span => span.textContent.trim()) | |
.filter(time => time !== 'LIVE') | |
.map(timeToSeconds) | |
.reduce(sum) | |
console.log('d', total / DAY) | |
console.log('h', total / HOUR) | |
console.log('m', total / MINUTE) | |
console.log('s', total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment