Created
December 27, 2020 07:53
-
-
Save ahmed-com/8ee062e605ca35e596dc1391c0002f5b to your computer and use it in GitHub Desktop.
a simple script to run in the browser console to get the total length of youtube playlist
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 elements = document.getElementsByClassName('style-scope ytd-thumbnail-overlay-time-status-renderer'); | |
let totalDuration = 0; | |
for(let el of elements){ | |
if(el.localName === 'span') { | |
const durationString = el.innerText; | |
const durationArr = durationString.split(':'); | |
let hours; | |
let mins; | |
let secs; | |
if(durationArr.length === 3){ | |
hours = +durationArr[0]; | |
mins = +durationArr[1]; | |
secs= +durationArr[2]; | |
}else if(durationArr.length === 2){ | |
hours = 0; | |
mins = +durationArr[0]; | |
secs = +durationArr[1]; | |
} | |
const duration = hours + (mins / 60) + (secs / 3600); | |
totalDuration += duration; | |
} | |
} | |
const totalHours = Math.floor(totalDuration); | |
const __totalMins__ = (totalDuration - totalHours) * 60; | |
const totalMins = Math.floor(__totalMins__); | |
const __totalSecs__ = (__totalMins__ - totalMins) * 60; | |
const totalSecs = Math.floor(__totalSecs__); | |
const totalDurationString = `${totalHours} hours, ${totalMins} minutes and ${totalSecs} seconds` | |
console.log(`duration of the whole playlist is ${totalDurationString}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice work