Last active
April 17, 2023 17:20
-
-
Save lorenzos/32eb1b6afdc3c70240b9b9b00148ae35 to your computer and use it in GitHub Desktop.
Dump YouTube playlist data from console to JSON
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
dump = () => { | |
const dump = Array.from(document.querySelectorAll('ytd-playlist-video-list-renderer ytd-playlist-video-renderer')).map(item => { | |
return { | |
id: item.querySelector('a').href.match(/v=([^&]+)&/)[1], | |
title: item.querySelector('h3')?.textContent?.trim() || null, | |
thumb: item.querySelector('ytd-thumbnail img')?.src || null, | |
by: item.querySelector('ytd-channel-name #text-container')?.textContent?.trim() || null, | |
length: item.querySelector('.ytd-thumbnail-overlay-time-status-renderer:not([hidden])')?.textContent?.trim() || null | |
}; | |
}); | |
const url = URL.createObjectURL(new Blob([JSON.stringify(dump)], { type: "application/json" })); | |
window.open(url); | |
console.log("Dumped", dump.length, "videos with", dump.filter(d => d.thumb != null && d.thumb != "").length, "thumbs"); | |
console.log(dump); | |
console.log(url); | |
}; | |
scrollLast = window.scrollY; | |
scroll = setInterval(() => window.scrollBy(0, 300), 50); | |
scrollEnd = setInterval(() => { | |
if (Math.abs(window.scrollY - window.scrollMaxY) < 1.1 && Math.abs(window.scrollY - scrollLast) < 1.1) { | |
clearInterval(scroll); | |
clearInterval(scrollEnd); | |
dump(); | |
} else { | |
console.log("Still scrolling...", document.querySelectorAll('ytd-playlist-video-list-renderer ytd-playlist-video-renderer').length); | |
} | |
scrollLast = window.scrollY; | |
}, 8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment