Skip to content

Instantly share code, notes, and snippets.

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 benedictchen/99d5ae73ac6210205bddf90912b51f26 to your computer and use it in GitHub Desktop.
Save benedictchen/99d5ae73ac6210205bddf90912b51f26 to your computer and use it in GitHub Desktop.
Calculate YouTube Playlist Total Duration
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