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 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); | |
} | |
} |
var els = document.getElementsByClassName('pl-video');
var arr = []
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];
arr.push(id);
console.log(id);
}
}
console.log(arr);
I used this to combine it into an array to make it easier to pull out.
Update for 2022
var els = document.getElementsByClassName('yt-simple-endpoint inline-block style-scope ytd-thumbnail');
var ids = []
for (i=1; i < els.length; i++) {
ids.push(els[i].href.split('v=').pop().split('&list')[0])
}
var els = document.getElementsByClassName('yt-simple-endpoint style-scope ytd-playlist-video-renderer'); var show=""; for(i = 0;i<els.length;i++){ var el = els[i]; show += (el.href.split('?v=')[1].split('&list')[0] + "\n"); } console.log(show);
i used this
This works perfectly the others dont
Well if anyone is looking for getting the thumbnail and title also
var thumbnails = document.getElementsByClassName('yt-core-image--fill-parent-height yt-core-image--fill-parent-width yt-core-image yt-core-image--content-mode-scale-aspect-fill yt-core-image--loaded');
var id="";
var title="";
var thumbnail = "";
for(i = 0;i<els.length;i++){
var el = els[i];
var t = thumbnails[i];
id += (el.href.split('?v=')[1].split('&list')[0] + "\n");
title += (el.title + "\n");
thumbnail += (t.src + "\n");
}
console.log(id);
console.log(title);
console.log(thumbnail);```
Thanks all for this!
Building off all others here, if you want a comma separated version:
var els = document.getElementsByClassName('yt-simple-endpoint style-scope ytd-playlist-video-renderer');
var dataList = "title,id\n";
for(i = 0;i<els.length;i++){
var el = els[i];
var curId = el.href.split('?v=')[1].split('&list')[0];
dataList += (el.title + "," + curId + "\n");
}
console.log(dataList);
This will give you an output like:
Output:
From https://www.youtube.com/playlist?list=PLVsZgWtfYk4igOAAaP56JvuFuabPD29-d
Go to the browser's inspector, and paste the code in the console to get the following:
title,id,thumbnail
GW200220 124850 remnant,040tJW611Fg,https://i.ytimg.com/vi/040tJW611Fg/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAg94Ckstdeqq93JfrEnvPRPBx0Eg
GW190630 185205 remnant,22dP_a25CwE,https://i.ytimg.com/vi/22dP_a25CwE/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDm81H9mzrpk-fQJKnmTQb_mlw0-w
GW200220 061928 remnant,2x2PJx9m7lo,https://i.ytimg.com/vi/2x2PJx9m7lo/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBIeKzlZbembvG_t7jUoyGgPbIarw
GW200219 094415 remnant,7Io2GBX09DA,https://i.ytimg.com/vi/7Io2GBX09DA/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLA13Fqizsgqy8GpdFcQRfXhPnGhJQ
GW200129 065458 remnant,7RHpiUgnxgc,https://i.ytimg.com/vi/7RHpiUgnxgc/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAJO9TNFgAA3qvwI9EZ-ZbiTMm6Lg
GW200311 115853 remnant,96aGp2ZSiAQ,https://i.ytimg.com/vi/96aGp2ZSiAQ/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDu9Nuph4mJ_RX_h0ceUtgXqQ9_Yg
GW190620 030421 remnant,9WIAMI6s-Ck,https://i.ytimg.com/vi/9WIAMI6s-Ck/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAzbfSIsKmWxKbLg64e771dBTt_vA
GW190727 060333 remnant,BlnrxOX-iNQ,https://i.ytimg.com/vi/BlnrxOX-iNQ/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBvlR4Bvztxt7kNrsIQoFGKleIxLQ
GW190701 203306 remnant,Bz8mo_2URm8,https://i.ytimg.com/vi/Bz8mo_2URm8/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCyowakOcNmoKfwy3rbIaOXAaTHpw
GW170809 082821 remnant,EfP5TtYC76c,https://i.ytimg.com/vi/EfP5TtYC76c/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBSaiX5pA2iOeUv8n6tvUwaE5ey-A
GW200128 022011 remnant,FWMCXb37a8A,https://i.ytimg.com/vi/FWMCXb37a8A/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLA-SBQsvvqBqyYLjyFMaZJ2rVCR5w
GW190519 153544 remnant,FdGKwqNssTI,https://i.ytimg.com/vi/FdGKwqNssTI/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAgDXGVy8Kx6a1VMCWtAvGuuQFBlw
GW191222 033537 remnant,HUboUkUO4Vo,https://i.ytimg.com/vi/HUboUkUO4Vo/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAXv7o3vISTh860fs6rM6EWIXyp7w
GW200311 115853 remnant,ISeyrF6Im7M,https://i.ytimg.com/vi/ISeyrF6Im7M/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDiQVZ0EpKseIzfMIBW_BeZcCGegQ
GW190521 030229 remnant,ISzaj0pwggo,https://i.ytimg.com/vi/ISzaj0pwggo/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAH9kh-gFwy7760ftKBzkLC6LViIg
GW190916 200658 remnant,KArYIUMymdA,https://i.ytimg.com/vi/KArYIUMymdA/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDVkPLcRkpqFrWM9iFL0KmA8AY0zw
GW190413 052954 remnant,MCNRu86Zpr0,https://i.ytimg.com/vi/MCNRu86Zpr0/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCKUg0zhpt7JGJcTxk-IFkPj4ZpWQ
GW190926 050336 remnant,O29AaLTKlBs,https://i.ytimg.com/vi/O29AaLTKlBs/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLA8MI07HVZQMt5ktKPvdFSB43evLQ
GW190517 055101 remnant,QcPktYJ8vKQ,https://i.ytimg.com/vi/QcPktYJ8vKQ/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCQ_CkIs1mrDyoaIQFg92yLE65VcA
GW170823 131358 remnant,S30gUerJZFI,https://i.ytimg.com/vi/S30gUerJZFI/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCmwiunbXv9aRzWV0cHK7wOFiiGrg
GW200219_094415 remnant,UdQzXTiUn0M,https://i9.ytimg.com/vi_webp/UdQzXTiUn0M/mqdefault.webp?sqp=COTC1aYG&rs=AOn4CLAj-sTz23_MYJAfgz30K3DwjclSLg
GW190521 074359 remnant,UdTHbMs0m7E,https://i.ytimg.com/vi/UdTHbMs0m7E/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAHiwlTW4BLb194lA_j4OZ_9y7ALg
GW190514 065416 remnant,VZNGwBHa_uM,https://i.ytimg.com/vi/VZNGwBHa_uM/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAGcUEXNcnVSBd5OcMPs7OtQJrf1g
GW190915 235702 remnant,XCBQOo0wJSs,https://i.ytimg.com/vi/XCBQOo0wJSs/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBN6tr1l4P30pFXoXVUYfG9XHLbEA
GW170818_022509 remnant,XR8XeUBDgwg,https://i9.ytimg.com/vi_webp/XR8XeUBDgwg/mqdefault.webp?sqp=COTC1aYG&rs=AOn4CLAGsldumBNUjqCAL252KSPabXj__g
GW191230 180458 remnant,Y5kKHtN0FLc,https://i.ytimg.com/vi/Y5kKHtN0FLc/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCviwAEp9EL4fscHMxSUo99z2dOTw
GW170818 022509 remnant,Zb5fhdVrPxM,https://i.ytimg.com/vi/Zb5fhdVrPxM/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCdmc3kkCeGJXfEocwd79ah7xFIHg
GW200224 222234 remnant,_HULeQUbrp0,https://i.ytimg.com/vi/_HULeQUbrp0/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCnjivNrGn_POJgZXJTsQTzgYdmbQ
GW200302_015811 remnant,axxh-CGWo64,https://i9.ytimg.com/vi_webp/axxh-CGWo64/mqdefault.webp?sqp=COTC1aYG&rs=AOn4CLDz0czOGl-u6YCbFEBTbILlLd_6_A
GW190413_052954 remnant,evqUZ1RLOIM,https://i9.ytimg.com/vi_webp/evqUZ1RLOIM/mqdefault.webp?sqp=COTC1aYG&rs=AOn4CLCIBc24ImUOo4UhRfkNPF_RC2qXng
GW190910 112807 remnant,fhzsjCx2dms,https://i.ytimg.com/vi/fhzsjCx2dms/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAmuBQfBQFsMa72CsMZSWpiSB7yrg
GW200112 155838 remnant,gMAq31ktAKY,https://i.ytimg.com/vi/gMAq31ktAKY/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAz9mM-BwHTjnCs_AbdJ8VxIKtwCg
GW190805 211137 remnant,gZn4oRGkPp4,https://i.ytimg.com/vi/gZn4oRGkPp4/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCM8r8GKHSBTauHvpaG3dnXlK0CPA
GW190803 022701 remnant,kYLkocAP9eE,https://i.ytimg.com/vi/kYLkocAP9eE/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLA71PkgDV3IIMZ4Ygy9Q9Y10W0qHw
GW190828 063405 remnant,lZdNIcQ5e_c,https://i.ytimg.com/vi/lZdNIcQ5e_c/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCuMkGrvE7d32mxxQVzZ2XW_djcyg
GW190513 205428 remnant,myq6Qa5gBP8,https://i.ytimg.com/vi/myq6Qa5gBP8/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLASa7eFf7vCdjl1vLgrPG2wxTPhew
GW190706 222641 remnant,nzzvB9unTss,https://i.ytimg.com/vi/nzzvB9unTss/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDPzqWKbNnV-iKkc8USe971v4l-iA
GW190527 092055 remnant,pHhTpfXWKkw,https://i.ytimg.com/vi/pHhTpfXWKkw/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLACWfAsxlfj6qELOFiZuDfynH8QCg
GW190929 012149 remnant,rFXgN4GOyDA,https://i.ytimg.com/vi/040tJW611Fg/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCeJtlTUYk-MmUJ0HXhUuon6TwcZA
GW190602 175927 remnant,rtoLQAUuiLo,https://i.ytimg.com/vi/22dP_a25CwE/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDPGY2rEVVRoyvdDZH1Pe5sCSKO8Q
GW190929_012149 remnant,rx5cqozz8ek,https://i.ytimg.com/vi/2x2PJx9m7lo/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBoClj4kTCB8X1P8WctrYCuZMPpbA
GW200208 130117 remnant,rxxsoZE9Hlk,https://i.ytimg.com/vi/7Io2GBX09DA/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDNVjYYueCgZWw5UYbm2dqkJegMCg
GW200302 015811 remnant,s2V0cre-A-M,https://i.ytimg.com/vi/7RHpiUgnxgc/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBIzL2HuXIVVr7tGa4pf3K1zMWjGw
GW200209 085452 remnant,sPAaGUbsdBs,https://i.ytimg.com/vi/96aGp2ZSiAQ/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAfOr_ghowE1_5k6GH1NTacIjP8oQ
GW191109 010717 remnant,swAUlI2k1Vk,https://i.ytimg.com/vi/9WIAMI6s-Ck/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAtZfHEtEuMjeMr4mxSd8YxVA_WJA
GW190731 140936 remnant,wwNWWo45evw,https://i.ytimg.com/vi/BlnrxOX-iNQ/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLBinlSZUvCG88UyW770jf62R7clrQ
GW200216 220804 remnant,yNdCj0wXCQ4,https://i.ytimg.com/vi/Bz8mo_2URm8/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEU-jv5ZYcDjm3aq9IQRHXB1DNIg
Great currently using the official youtube data api to get the work done
var els = document.getElementsByClassName('yt-simple-endpoint style-scope ytd-playlist-video-renderer'); var show=""; for(i = 0;i<els.length;i++){ var el = els[i]; show += (el.href.split('?v=')[1].split('&list')[0] + "\n"); } console.log(show);
i used this
Work thanks
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(','));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i used this