From 43fa5d8db85420159b9151e7d025f1eff9bb5242 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 6 Jun 2022 03:29:47 +0100 Subject: [PATCH] Update regex to include hyphens. Closes #861 --- src/components/SearchResults.vue | 4 ++-- src/components/WatchVideo.vue | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index 02f4d196..1a34bec8 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -127,8 +127,8 @@ export default { handleRedirect() { const query = this.$route.query.search_query; const url = - /(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&]*)/gm.exec(query)?.[1] ?? - /(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&]*)/gm + /(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&-]*)/gm.exec(query)?.[1] ?? + /(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&-]*)/gm .exec(query)?.[1] .replace(/^/, "/watch?v="); if (url) { diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 9f8cfd39..f3f1c4bc 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -319,9 +319,9 @@ export default { xmlDoc.querySelectorAll("a").forEach(elem => (elem.outerHTML = elem.getAttribute("href"))); xmlDoc.querySelectorAll("br").forEach(elem => (elem.outerHTML = "\n")); this.video.description = this.urlify(xmlDoc.querySelector("body").innerHTML) - .replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&]*)/gm, "$1") + .replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&-]*)/gm, "$1") .replaceAll( - /(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&]*)/gm, + /(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&-]*)/gm, "/watch?v=$1", ) .replaceAll("\n", "
");