Skip to content

Instantly share code, notes, and snippets.

@amenayach
Last active May 1, 2022 00:51
Show Gist options
  • Save amenayach/9bf537d14d3e31a66a39e5207573d7dc to your computer and use it in GitHub Desktop.
Save amenayach/9bf537d14d3e31a66a39e5207573d7dc to your computer and use it in GitHub Desktop.
A Javascript script to scrap Youtube playlist via browser console
let getSeconds = secondsText => {
let spl = secondsText.split(':');
return parseInt(spl[0]) * 60 + parseInt(spl[1]);
};
let getEmbedUrl = url => {
let vIndex = url.indexOf('?v=');
let lIndex = url.indexOf('&list=');
return 'https://www.youtube.com/embed/' + url.substring(vIndex + 3, lIndex);
};
JSON.stringify([...document.querySelectorAll('ytd-playlist-panel-video-renderer')]
.map(x => {
let title = x.querySelector('#video-title').innerText;
let secondsText =
x.querySelector('ytd-thumbnail-overlay-time-status-renderer')
.querySelector('span.ytd-thumbnail-overlay-time-status-renderer').innerText;
let seconds = getSeconds(secondsText);
let url = getEmbedUrl(x.querySelector('#thumbnail').getAttribute('href'));
return {title, seconds, url};
}), null, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment