Support shorts

This commit is contained in:
Ajay Ramachandran
2021-10-03 13:07:47 -04:00
parent 1a0ac27e49
commit 66f0cc8883

View File

@@ -851,7 +851,7 @@ function getYouTubeVideoID(url: string): string | boolean {
if(url.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", ""); if(url.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", "");
//Attempt to parse url //Attempt to parse url
let urlObject = null; let urlObject: URL = null;
try { try {
urlObject = new URL(url); urlObject = new URL(url);
} catch (e) { } catch (e) {
@@ -877,9 +877,10 @@ function getYouTubeVideoID(url: string): string | boolean {
if (urlObject.searchParams.has("v") && ["/watch", "/watch/"].includes(urlObject.pathname) || urlObject.pathname.startsWith("/tv/watch")) { if (urlObject.searchParams.has("v") && ["/watch", "/watch/"].includes(urlObject.pathname) || urlObject.pathname.startsWith("/tv/watch")) {
const id = urlObject.searchParams.get("v"); const id = urlObject.searchParams.get("v");
return id.length == 11 ? id : false; return id.length == 11 ? id : false;
} else if (urlObject.pathname.startsWith("/embed/")) { } else if (urlObject.pathname.startsWith("/embed/") || urlObject.pathname.startsWith("/shorts/")) {
try { try {
return urlObject.pathname.substr(7, 11); const id = urlObject.pathname.split("/")[2];
if (id && id.length == 11) return id;
} catch (e) { } catch (e) {
console.error("[SB] Video ID not valid for " + url); console.error("[SB] Video ID not valid for " + url);
return false; return false;