Added sanity check

This commit is contained in:
Official Noob
2019-08-06 14:08:46 +01:00
committed by GitHub
parent 7ad5e426fb
commit 2b5402fa57

View File

@@ -1,11 +1,8 @@
function getYouTubeVideoID(url) { // Returns with video id else returns false
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
var id = new URL(url).searchParams.get("v");
if (url.includes("/embed/")) { //it is an embed, don't search for v
id = match[7];
}
return (match) ? id : false;
var id = url.includes("/embed/") ? match[7] : new URL(url).searchParams.get("v");
return (match && id.length === 11) ? id : false;
}
//returns the start time of the video if there was one specified (ex. ?t=5s)