JSON
A Javascript snippet to convert a Youtube playlist page’s list of videos into a JSON:
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)
Markdown
I often use this to get a list of conference talks into my notes so I can watch them and turn them into notes.
let talks = $$('#contents ytd-playlist-video-renderer') // Using Firefox's shortcut $$. For other browsers, replace $$ with document.querySelectorAll
Object.values(talks).map(talk => {
let title = talk.querySelector('#video-title').textContent.trim();
let href = talk.querySelector('#video-title').href
let url = new URL(href);
let videoId = new URLSearchParams(url.search).get('v')
return `[${title}](${url.origin}${url.pathname}?v=${videoId})`
}).join('\n')