From 1db9d25f3ba928f18a17bb17cad1dae77005c2cb Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 29 Dec 2019 21:39:19 +0000 Subject: [PATCH 1/4] getYouTubeVideoID ~ TV support --- utils.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/utils.js b/utils.js index 838769a2..51a54cc3 100644 --- a/utils.js +++ b/utils.js @@ -19,6 +19,9 @@ async function wait(condition, timeout = 5000, check = 100) { } function getYouTubeVideoID(url) { + + if(document.URL.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", ""); + //Attempt to parse url let urlObject = null; try { @@ -32,7 +35,7 @@ function getYouTubeVideoID(url) { 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")) { + if (["/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/")) { @@ -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; -} \ No newline at end of file +} From f74e25a482263ed8c155461f237d91c8342e0b10 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 29 Dec 2019 21:42:43 +0000 Subject: [PATCH 2/4] Update utils.js --- utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/utils.js b/utils.js index 51a54cc3..e26bee1b 100644 --- a/utils.js +++ b/utils.js @@ -35,6 +35,7 @@ function getYouTubeVideoID(url) { if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false; //Get ID from searchParam + if(!urlObject.searchParams.has("v")) return false if (["/watch", "/watch/"].includes(urlObject.pathname) || urlObject.pathname.startsWith("/tv/watch")) { id = urlObject.searchParams.get("v"); return id.length == 11 ? id : false; From fe608b579e48f2622a2f460d52cc2681c9b91828 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 29 Dec 2019 16:48:10 -0500 Subject: [PATCH 3/4] Formatting --- utils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils.js b/utils.js index e26bee1b..bb2019c2 100644 --- a/utils.js +++ b/utils.js @@ -19,16 +19,16 @@ 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 From 87abcae2494ac74200e2e26a6500abffb36ceb7a Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 29 Dec 2019 21:51:11 +0000 Subject: [PATCH 4/4] fix embeds --- utils.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utils.js b/utils.js index bb2019c2..6fcfe0d0 100644 --- a/utils.js +++ b/utils.js @@ -35,9 +35,8 @@ function getYouTubeVideoID(url) { if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false; //Get ID from searchParam - if(!urlObject.searchParams.has("v")) return false - if (["/watch", "/watch/"].includes(urlObject.pathname) || urlObject.pathname.startsWith("/tv/watch")) { - 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 {