Skip to content

Instantly share code, notes, and snippets.

@Fanna1119
Created April 11, 2026 08:51
Show Gist options
  • Select an option

  • Save Fanna1119/b2283f3e5ed9c3d338ac66d769a6c17f to your computer and use it in GitHub Desktop.

Select an option

Save Fanna1119/b2283f3e5ed9c3d338ac66d769a6c17f to your computer and use it in GitHub Desktop.
youtube playlist json data
// Auto-scroll to load all videos in the playlist
let scrollInterval = setInterval(() => {
window.scrollBy(0, 1200);
if (window.scrollY + window.innerHeight >= document.body.scrollHeight - 800) {
clearInterval(scrollInterval);
console.log("✅ Scrolling finished – all videos should be loaded. Now run the extraction script.");
}
}, 700);
// Extract ALL videos from YouTube playlist (Watch Later etc.) with extra fields
const videos = Array.from(document.querySelectorAll('ytd-playlist-video-renderer'));
const result = videos.map((video, index) => {
// URL (clean version - just the video link)
const linkEl = video.querySelector('a#thumbnail, a#video-title');
let url = linkEl ? linkEl.href : '';
if (url.includes('&list=')) url = url.split('&list=')[0];
// Video title
const titleEl = video.querySelector('#video-title');
const videoName = titleEl ? titleEl.textContent.trim() : 'Unknown';
// Uploader / channel
const channelEl = video.querySelector('ytd-channel-name a, #channel-name a');
const uploader = channelEl ? channelEl.textContent.trim() : 'Unknown';
// Video length / duration
const durationEl = video.querySelector('ytd-thumbnail-overlay-time-status-renderer badge-shape, .yt-badge-shape__text, #time-status span');
const videoLength = durationEl ? durationEl.textContent.trim() : 'N/A';
// Views + Upload date (they are together in yt-formatted-string)
const infoEl = video.querySelector('yt-formatted-string#video-info');
let views = 'N/A';
let uploadDate = 'N/A';
if (infoEl) {
const infoText = infoEl.textContent.trim();
// Example: "218K views • 14 years ago"
const parts = infoText.split('•').map(p => p.trim());
if (parts.length >= 1) views = parts[0];
if (parts.length >= 2) uploadDate = parts[1];
}
return {
url: url,
uploader: uploader,
video_name: videoName,
video_length: videoLength,
views: views,
upload_date: uploadDate
};
});
// Pretty print in console
console.log(`✅ Extracted ${result.length} videos`);
console.log(JSON.stringify(result, null, 2));
// Copy to clipboard automatically
navigator.clipboard.writeText(JSON.stringify(result, null, 2)).then(() => {
console.log("📋 Copied to clipboard! Paste into a .json file or spreadsheet.");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment