Get youtube playlist length

January 20, 2022

Sometimes i need to know how long a youtube playlist is. To do this i always end in some random website that will calculate it for me. Yesterday i decided to make a little bookmarklet to have this info without navigating away. As always, this could fail in the future, but for now it works. Another drawback it has is that you need to scroll to the bottom of the page to load all the videos.

You can always execute this snippet in the console devtools.

(function(window,document){
	function fmt(s){
		const dateObj = new Date(s * 1000);
		const hours = dateObj.getUTCHours();
		const minutes = dateObj.getUTCMinutes();
		const seconds = dateObj.getSeconds();
		return `${hours} hrs ${minutes} min ${seconds} sec`
	}

	const total = [...document.querySelector("ytd-playlist-video-list-renderer")?.querySelectorAll("ytd-playlist-video-renderer")]
		.map( i => i.querySelector("#text") )
		.map( t => t.textContent.trim().split(":")
			.map( e => parseInt(e,10) )
			.reverse()
			.map( (n,i) => n*Math.pow(60,i) )
			.reduce( (prev,curr) => prev + curr, 0)
		)
		.reduce( (prev,curr) => prev + curr, 0);

	alert(fmt(total));
})(window,document);

Another option is to add this YTPlaylistLength bookmarklet to your bookmarks and just click it.

Leave your comment on the github issue, sending me an email or DMing me on twitter