Created
August 2, 2020 15:03
-
-
Save O-Zone/9126e8a123fe84098ab6bab63515e89b to your computer and use it in GitHub Desktop.
Script to harvest all song/title/album from the music.youtube.com/library/songs/ and export them to a .csv file
This file contains 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
var waitForContentSeconds = 10; | |
var bottomTrials = 0; | |
var pageHeight = 0; | |
function grabYoutubeList() { | |
var AllNodes = [...document.getElementsByTagName('ytmusic-shelf-renderer')[0].getElementsByTagName('ytmusic-responsive-list-item-renderer')]; | |
AllNodes.shift(); // remove first "blend" element | |
var harvestedTunes = AllNodes.map(t => { | |
var items = [...t.children[3].getElementsByTagName('yt-formatted-string')].map(n => n.getAttribute('title').replace(/"/g,'”')); | |
return `"${items[0]}", "${items[1]}", "${items[2]}"<br>\n`; | |
}); | |
var resultWindow = window.open('', ''); | |
resultWindow.document.open(); | |
resultWindow.document.write('Title, Artist, Album<br>\n' + harvestedTunes.join('')); | |
resultWindow.document.close(); | |
} | |
function scrollToBottom() { | |
if (pageHeight !== document.body.scrollHeight) { | |
bottomTrials = 0; | |
window.scrollTo(0,document.body.scrollHeight); | |
pageHeight = document.body.scrollHeight; | |
setTimeout(scrollToBottom, 1000); | |
} else { | |
if (bottomTrials < waitForContentSeconds) { | |
bottomTrials++; | |
setTimeout(scrollToBottom, 1000); | |
} else { | |
// We are at the bottom | |
grabYoutubeList(); | |
} | |
} | |
} | |
scrollToBottom(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//Here is a script to get all your favorite artists from youtube too (the https://music.youtube.com/library/artists page). Does exactly the same thing, only with artists