If given the following link to a YouTube video:
https://youtu.be/PqkaBUmJpq8?list=PLmmPGQQTKzSZSPd3pa6q9UQ-PkeCx1fam
Is it possible to extract the video id
from it that gets used in the YouTube iFrame API ?
If given the following link to a YouTube video:
https://youtu.be/PqkaBUmJpq8?list=PLmmPGQQTKzSZSPd3pa6q9UQ-PkeCx1fam
Is it possible to extract the video id
from it that gets used in the YouTube iFrame API ?
Just ended up writing this function:
function extractVideoIdFromYouTubeUrl (url) {
var stepOne = url.split('?')[0];
var stepTwo = stepOne.split('/');
var videoId = stepTwo[stepTwo.length-1];
return videoId;
}
function extractVideoIdFromYouTubeUrl(url) {
let id = url.substring(url.lastIndexOf("v=")+2,url.length);
return id;
}
This solution assumes that the video ID is at the end of the URL. I would only advise using it for simple situations like where I needed it, where the user can't enter a URL, and the Youtube Player API creates a limited possible set of URLs.