Skip to content

Instantly share code, notes, and snippets.

@erseco
Created December 11, 2023 22:06
Show Gist options
  • Save erseco/21c0d8362648245c15cc02567ac27dd9 to your computer and use it in GitHub Desktop.
Save erseco/21c0d8362648245c15cc02567ac27dd9 to your computer and use it in GitHub Desktop.
YouTube Studio Playlist URL and Title Extractor
// YouTube Studio Playlist URL and Title Extractor
// This script is designed to run in the browser console while you're on the YouTube Studio playlist page.
// It extracts the URLs and titles of all playlists in the current view. The script is particularly useful
// for channel managers and content creators who need to quickly gather information about their playlists
// for cataloging, backup, or analysis purposes.
// How It Works:
// - The script queries the document for all anchor (<a>) elements that contain '/playlist/' in their href attribute.
// These elements are usually links to individual playlists.
// - It then iterates over each of these elements, extracting the URL (href attribute) and the title (text content of the element).
// - To ensure that the title is meaningful, the script checks if the title is not empty and is not a number.
// This is done to filter out any irrelevant or unintended items that might be present in the DOM.
// - The extracted titles and URLs are concatenated into a single string, output, which is then logged to the console.
// Usage:
// 1. Navigate to the playlist section of your YouTube Studio.
// 2. Open the browser's developer tools (usually F12 or right-click > "Inspect").
// 3. Go to the "Console" tab.
// 4. Copy and paste the script into the console and press Enter.
// 5. The output will be displayed in the console, which you can then copy for your use.
// Note:
// - This script works with the current layout of the YouTube Studio as of its writing. Changes in the web layout by YouTube
// may require adjustments to the script.
// - Ensure all the playlists you want to extract are loaded on the page. You may need to scroll down to load all items
// if you have a large number of playlists.
let links = document.querySelectorAll('a[href*="/playlist/"]');
let output = "";
for (let i = 0; i < links.length; i++) {
let url = links[i].href;
let title = links[i].textContent.trim();
if (title !== "" && isNaN(Number(title))) {
output += `Título: ${title}, URL: ${url}\n`;
}
}
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment