🍿 Convert Youtube playlist to JSON
Snacks (🍿) are my collection of recipes for solving problems. Often recorded (and cleaned up) from actual discussions where I'm involved in helping others with technical problems. Not all solutions are mine but I started collecting them in one place because you never know when you need one.
Open a video playlist page, such as DjangoCon US 2023, open Developer Tools and Console and copy-paste this in.
Note: The index in the first line might require adjusting, I don't know how consistent it is.
playlist = document.querySelectorAll("#contents")[3]; // Index may need adjusting
titles = playlist.querySelectorAll("#video-title");
videos = Object.values(titles).map((title) => {
return { url: title.href, title: title.textContent.trim() };
});
JSON.stringify(videos);