Last active
April 13, 2020 17:30
-
-
Save schoettker/e349af0a20ebb861e26851d564048536 to your computer and use it in GitHub Desktop.
Log the total length of a youtube playlist by pasting into console on a playlist overview page
This file contains hidden or 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 durationContainers = Array.from(document.querySelectorAll("#primary #contents .ytd-thumbnail-overlay-time-status-renderer")); | |
| var durations = durationContainers.map(__span => __span.innerText).map(duration => { | |
| if (duration) { | |
| const fragments = duration.split(":").reverse(); | |
| const fragmentsToSeconds = fragments.reduce((acc, current, idx) => acc + parseInt(current) * Math.pow(60, idx), 0); | |
| return fragmentsToSeconds | |
| } | |
| else { | |
| return 0; | |
| } | |
| }); | |
| const totalSeconds = durations.reduce((acc, current) => acc + current, 0) | |
| const hours = Math.floor(totalSeconds / 3600); | |
| const minutes = Math.floor(totalSeconds / 60) % 60; | |
| const seconds = totalSeconds % 60; | |
| const time = `${String(hours).padStart(2, 0)}h:${String(minutes).padStart(2,0)}m:${String(seconds).padStart(2,0)}s` | |
| console.log(time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment