Created
August 8, 2021 07:23
-
-
Save feeedback/6d8f4afa2a4abdb7490f00cb5b3e2701 to your computer and use it in GitHub Desktop.
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 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