From 77d1f4fcde999dc5090c9e01ca2d2c25f1133fc3 Mon Sep 17 00:00:00 2001 From: Alicia Williams Date: Sat, 1 Apr 2023 15:38:12 -0700 Subject: [PATCH] Update Code.js Update to work with various YouTube URLs including youtu.be and new shorts URL format. --- solutions/automations/youtube-tracker/Code.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/solutions/automations/youtube-tracker/Code.js b/solutions/automations/youtube-tracker/Code.js index b99827d4d..13131e219 100644 --- a/solutions/automations/youtube-tracker/Code.js +++ b/solutions/automations/youtube-tracker/Code.js @@ -103,14 +103,10 @@ function getVideoDetails(videoId) { /** * Extracts YouTube video ID from url. - * (h/t https://stackoverflow.com/a/3452617) */ function extractVideoIdFromUrl(url) { - let videoId = url.split('v=')[1]; - let ampersandPosition = videoId.indexOf('&'); - if (ampersandPosition != -1) { - videoId = videoId.substring(0, ampersandPosition); - } + var regExp = '(?:v=|be/|shorts/)([a-zA-Z0-9_-]+)'; + var videoId = url.match(regExp)[1]; return videoId; } @@ -123,4 +119,4 @@ function sendEmailNotificationTemplate(content, emailAddress) { template.content = content; let msg = template.evaluate(); MailApp.sendEmail(emailAddress,'New comments or replies on YouTube',msg.getContent(),{htmlBody:msg.getContent()}); -} \ No newline at end of file +}