Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var list=document.querySelector("ytd-section-list-renderer").querySelectorAll("a");
var youtubeVideos = [];
for (i=0;i<list.length;i++){
var url = list[i].getAttribute("href");
if(url && url.indexOf("/watch?v=")>-1){
var videoTitle = list[i].getAttribute("title");
var videoID = list[i].getAttribute("href").replace(/https:\/\/www\.youtube\.com|\/watch\?v=|&t=.+s|&list=.*/gi,"");
if (youtubeVideos.indexOf(videoID) == -1 && videoTitle) {
youtubeVideos.push("https://www.youtube.com" + url + "\t" + videoID + "\t" + videoTitle);
}
}
}
youtubeVideos.sort();
console.log("videoURL\tvideoID\tvideoTitle\n" + youtubeVideos.join("\n"));
var tempHolder = document.createElement("textarea");
document.body.appendChild(tempHolder);
tempHolder.value = "videoURL\tvideoID\tvideoTitle\n" + youtubeVideos.join("\n");
tempHolder.select();
document.execCommand("copy");
document.body.removeChild(tempHolder);
console.log("A total of " + youtubeVideos.length + " videoIDs were added to the clipboard.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment