Created
July 28, 2017 00:30
-
-
Save milankragujevic/cf0e503407104b1e444efa18f4108ce1 to your computer and use it in GitHub Desktop.
To extract all the video IDs from a YouTube playlist. Open the playlist page, scroll down to the bottom, click load more, repeat until the end, then open Console and paste this code. Output is a list of video IDs from the page.
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
var els = document.getElementsByClassName('pl-video'); | |
for(i = 0; i < els.length; i++) { | |
var el = els[i]; | |
if(el) { | |
var src = el.getElementsByClassName('yt-thumb-clip')[0].getElementsByTagName('img')[0].src; | |
if(!src.match(/\.com\/vi\//g)) { continue; } | |
var id = src.split('.com/vi/')[1].split('/')[0]; | |
console.log(id); | |
} | |
} |
Much appreciated! I modified it a bit for a playlist with Shorts:
var els = document.getElementsByClassName('reel-item-endpoint');
for(i = 0; i < els.length; i++) {
var el = els[i];
if(el) {
if (!el.href || !el.href.match(/shorts\/([a-zA-Z0-9_-]+)$/)) {
continue;
}
var id = el.href.split('/shorts/')[1].split('/')[0];
console.log(id);
}
}
Or if you want it as one comma-separated output
var els = document.getElementsByClassName('reel-item-endpoint');
var ids = [];
for(i = 0; i < els.length; i++) {
var el = els[i];
if(el) {
if (!el.href || !el.href.match(/shorts\/([a-zA-Z0-9_-]+)$/)) {
continue;
}
ids.push(el.href.split('/shorts/')[1].split('/')[0]);
}
}
console.log(ids.join(','));
why not use yt-dlp? In a console with yt-dlp installed, execute:
yt-dlp --flat-playlist --print "%(url)s" "PLAYLIST_URL" > playlist_urls.txt
replace PLAYLIST_URL
with the url and exec the cmd. This will give the entire urls in a txt file. Then in the file, simply find and replace https://www.youtube.com/watch?v=
with nothing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Work thanks