Created
October 20, 2021 15:40
-
-
Save hhkaos/db450f272cd3bd6df9f81098d3c185bd to your computer and use it in GitHub Desktop.
Get titles and IDs from a YouTube
This file contains hidden or 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
// 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