Fixed typos.

Co-author worked on creating this url parser.

Co-Authored-By: Giacomo Rossetto <jackyman_cs4@live.it>
This commit is contained in:
Ajay Ramachandran
2019-08-10 19:51:08 -04:00
parent b964d93ea9
commit ccafbf663c

View File

@@ -1,13 +1,15 @@
function getYouTubeVideoID(url) { function getYouTubeVideoID(url) {
try { // Attempt to parse url //Attempt to parse url
try {
var obj = new URL(url); var obj = new URL(url);
} catch (e) { } catch (e) {
console.error("[SB] Unable to parser URL"); console.error("[SB] Unable to parser URL");
return false return false
} }
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(obj.host)) return false // Check if valid hostname //Check if valid hostname
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(obj.host)) return false;
if (obj.pathname == "/watch" && obj.searchParams.has("v")) { if (obj.pathname == "/watch" && obj.searchParams.has("v")) {
id = obj.searchParams.get("v"); // Get ID from searchParam id = obj.searchParams.get("v"); // Get ID from searchParam
@@ -17,7 +19,7 @@ function getYouTubeVideoID(url) {
return obj.pathname.substr(7, 11); return obj.pathname.substr(7, 11);
} catch (e) { } catch (e) {
console.error("[SB] Video ID not valid"); console.error("[SB] Video ID not valid");
return false return false;
} }
} }
} }