Skip to content

Instantly share code, notes, and snippets.

@hhkaos
Created October 20, 2021 15:40
Show Gist options
  • Save hhkaos/db450f272cd3bd6df9f81098d3c185bd to your computer and use it in GitHub Desktop.
Save hhkaos/db450f272cd3bd6df9f81098d3c185bd to your computer and use it in GitHub Desktop.
Get titles and IDs from a YouTube
// Script to get video titles and links from a YT playlist
// https://www.youtube.com/playlist?list=PLAYLIST_ID
data = []
function youtube_parser(url){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
var match = url.match(regExp);
return (match&&match[7].length==11)? match[7] : false;
}
document.querySelectorAll("a#video-title").forEach((el,i) => {
let videoId = youtube_parser(el.href)
data.push({title: el.innerText, id:videoId})
})
console.table(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment