Skip to content

Instantly share code, notes, and snippets.

@feeedback
Created August 8, 2021 07:23
Show Gist options
  • Save feeedback/6d8f4afa2a4abdb7490f00cb5b3e2701 to your computer and use it in GitHub Desktop.
Save feeedback/6d8f4afa2a4abdb7490f00cb5b3e2701 to your computer and use it in GitHub Desktop.
{
const formatS = (s = 0) =>
`${Math.floor(s / 3600)}:${`${Math.floor(s / 60) % 60}`.padStart(2, 0)}:${`${s % 60}`.padStart(2, 0)}`;
const getPlaylistDuration = () => {
const videos = [
...document
.querySelector('ytd-playlist-video-list-renderer')
.parentElement.querySelectorAll('span.ytd-thumbnail-overlay-time-status-renderer'),
];
const videosDuration = videos.map((video) => {
const [s = 0, m = 0, h = 0] = video.textContent.split(':').map(Number).reverse();
return 3600 * h + 60 * m + s;
});
return formatS(videosDuration.reduce((a, b) => a + b, 0));
};
console.clear();
console.log(`Playlist duration: ${getPlaylistDuration()}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment