Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mehranattari/26df56119c8b5cbf74c3c4b53dfa4507 to your computer and use it in GitHub Desktop.
Save mehranattari/26df56119c8b5cbf74c3c4b53dfa4507 to your computer and use it in GitHub Desktop.
Youtube playlist duration
// Just copy this into console while on a playlist page (https://www.youtube.com/playlist?list=.....)
console.log(((document) => {
let seconds = Array.from(document.querySelectorAll('.ytd-thumbnail-overlay-time-status-renderer'))
.map((span) => {
let time = span.textContent.split(':');
return (Number(time[0]) * 60) + Number(time[1]);
})
.reduce((a,b) => {
return a + b;
});
let total = {
hours: Math.floor(seconds/(3600)),
minutes: Math.floor((seconds%3600)/60),
seconds: (seconds%60)
};
return 'Playlist duration: ' + total.hours + ' hours, ' + total.minutes + ' minutes, ' + total.seconds + ' seconds';
})(document));
// This above will print the result in console after this code, but if you want to get the duration in Alert box, just replace the console.log by alert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment