Calculate YouTube Playlist Total 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
const x = Array.prototype.map.call(document.querySelectorAll('iron-list#items .style-scope ytd-thumbnail-overlay-time-status-renderer'), ((node)=>node.textContent.trim())) | |
var seconds = x.map((item)=> { | |
let itemParts = item.split(':'); | |
let str = itemParts[itemParts.length - 1] || 0; | |
return parseInt(str); | |
}).reduce((prev, current) => prev + current); | |
var minutes = x.map((item)=> { | |
let itemParts = item.split(':'); | |
let str = itemParts[itemParts.length - 2] || 0; | |
return parseInt(str); | |
}).reduce((prev, current) => prev + current); | |
var hours = x.map((item)=> { | |
let itemParts = item.split(':'); | |
let str = itemParts[itemParts.length - 3] || 0; | |
return parseInt(str); | |
}).reduce((prev, current) => prev + current); | |
minutes += seconds / 60; | |
hours += minutes / 60; | |
console.log(`total time in hours: ${hours}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment