EN
Youtube - print all video ids in browser console using JavaScript in channel video view (without saved time query parameter)
4 points
In this article we will see how to get youtube video id using JavaScript and browser console.
Quick solution:
xxxxxxxxxx
1
[document.querySelectorAll('a#video-title')]
2
.map(entry => {
3
const expression = /[?&]v=([^&]+)/i;
4
const matching = expression.exec(entry.href);
5
if (matching) {
6
return decodeURIComponent(matching[1]);
7
}
8
return link;
9
});
Or:
xxxxxxxxxx
1
[document.querySelectorAll('#video-title')]
2
.map(entry => {
3
let url = new URL(entry.href);
4
return url.searchParams.get('v');
5
});
Or:
xxxxxxxxxx
1
[document.querySelectorAll('#video-title')]
2
.map(entry => {
3
let link = entry.href.replace('https://www.youtube.com/watch?v=', '');
4
let timeIndex = link.indexOf('&');
5
if (timeIndex != -1) {
6
return link.substring(0, timeIndex);
7
}
8
return link;
9
});
10
11
// Sample output:
12
// 0: "lBPOEZLMdd4"
13
// 1: "2OoQMLXGiyw"
14
// 2: "l4qB24OSjx8"
15
// ...

Youtube video url analysis:
xxxxxxxxxx
1
// youtube video url with video ID and
2
https://www.youtube.com/watch?v=lBPOEZLMdd4
3
// Video ID: lBPOEZLMdd4
4
5
// youtube video url with video ID and time query parameter set to 22 seconds:
6
https://www.youtube.com/watch?v=lBPOEZLMdd4&t=22s
7
// Video ID: lBPOEZLMdd4
8
// Time where we stopped watching: 22s
Below in couple of steps we will see how to get video ids.
Go to youtube channel and enter videos, for example Dirask youtube channel - videos:
Open browser console (for this tutorial we've used Chrome Browser and Chrome DevTools)
Shortcuts:
- Press F12 - it will open DevTools
- Press Escape - it will open console
xxxxxxxxxx
1
[document.querySelectorAll('#video-title')].map(entry => entry.href);
Output:
xxxxxxxxxx
1
0: "https://www.youtube.com/watch?v=lBPOEZLMdd4&t=2s"
2
1: "https://www.youtube.com/watch?v=2OoQMLXGiyw"
3
2: "https://www.youtube.com/watch?v=l4qB24OSjx8&t=1s"
4
3: "https://www.youtube.com/watch?v=KiWdL16b-lw&t=25s"
5
4: "https://www.youtube.com/watch?v=SOGpvHun6vg"
6
5: "https://www.youtube.com/watch?v=v-UAkAWANmc"
7
6: "https://www.youtube.com/watch?v=UdZvo-xeQOw"
8
7: "https://www.youtube.com/watch?v=XaP9U_g5tgc"
9
8: "https://www.youtube.com/watch?v=5HVKzHyFpP0"
xxxxxxxxxx
1
[document.querySelectorAll('#video-title')]
2
.map(entry => {
3
let link = entry.href.replace('https://www.youtube.com/watch?v=', '');
4
return link;
5
});
Output:
xxxxxxxxxx
1
0: "lBPOEZLMdd4&t=2s"
2
1: "2OoQMLXGiyw"
3
2: "l4qB24OSjx8&t=1s"
4
3: "KiWdL16b-lw&t=25s"
5
4: "SOGpvHun6vg"
6
5: "v-UAkAWANmc"
7
6: "UdZvo-xeQOw"
8
7: "XaP9U_g5tgc"
9
8: "5HVKzHyFpP0"
xxxxxxxxxx
1
[document.querySelectorAll('#video-title')]
2
.map(entry => {
3
let link = entry.href.replace('https://www.youtube.com/watch?v=', '');
4
let timeIndex = link.indexOf('&');
5
if (timeIndex != -1) {
6
return link.substring(0, timeIndex);
7
}
8
return link;
9
});
Output:
xxxxxxxxxx
1
0: "lBPOEZLMdd4"
2
1: "2OoQMLXGiyw"
3
2: "l4qB24OSjx8"
4
3: "KiWdL16b-lw"
5
4: "SOGpvHun6vg"
6
5: "v-UAkAWANmc"
7
6: "UdZvo-xeQOw"
8
7: "XaP9U_g5tgc"
9
8: "5HVKzHyFpP0"