Merge pull request #214 from OfficialNoob/patch-26

getYouTubeVideoID ~ TV support
This commit is contained in:
Ajay Ramachandran 2019-12-29 16:56:36 -05:00 committed by GitHub
commit 9cb4fd6f79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,21 +19,24 @@ async function wait(condition, timeout = 5000, check = 100) {
}
function getYouTubeVideoID(url) {
// For YouTube TV support
if(document.URL.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", "");
//Attempt to parse url
let urlObject = null;
try {
urlObject = new URL(url);
urlObject = new URL(url);
} catch (e) {
console.error("[SB] Unable to parse URL: " + url);
return false;
console.error("[SB] Unable to parse URL: " + url);
return false;
}
//Check if valid hostname
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false;
//Get ID from searchParam
if ((urlObject.pathname == "/watch" || urlObject.pathname == "/watch/") && urlObject.searchParams.has("v")) {
id = urlObject.searchParams.get("v");
if (urlObject.searchParams.has("v") && ["/watch", "/watch/"].includes(urlObject.pathname) || urlObject.pathname.startsWith("/tv/watch")) {
id = urlObject.searchParams.get("v");
return id.length == 11 ? id : false;
} else if (urlObject.pathname.startsWith("/embed/")) {
try {
@ -42,8 +45,7 @@ function getYouTubeVideoID(url) {
console.error("[SB] Video ID not valid for " + url);
return false;
}
}
}
return false;
}
@ -104,4 +106,4 @@ function getErrorMessage(statusCode) {
}
return errorMessage;
}
}