Skip to content

Instantly share code, notes, and snippets.

@tarcisiozf
Created September 15, 2020 12:51
Show Gist options
  • Save tarcisiozf/061c4513749f331b58f405ed84f91121 to your computer and use it in GitHub Desktop.
Save tarcisiozf/061c4513749f331b58f405ed84f91121 to your computer and use it in GitHub Desktop.
calculate youtube playlist duration
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