~cadence/tube-devel

cloudtube: Properly rewrite URL params for youtu.be links in converters.rewriteVideoDescription() v1 APPLIED

~lomanic
~lomanic: 1
 Properly rewrite URL params for youtu.be links in converters.rewriteVideoDescription()

 1 files changed, 7 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~cadence/tube-devel/patches/23507/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH cloudtube] Properly rewrite URL params for youtu.be links in converters.rewriteVideoDescription() Export this patch

~lomanic
From: Lomanic <lomanic@hotmail.fr>

---
 utils/converters.js | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/utils/converters.js b/utils/converters.js
index 6e17567..b5e6404 100644
--- a/utils/converters.js
+++ b/utils/converters.js
@@ -66,8 +66,14 @@ function rewriteVideoDescription(descriptionHtml, id) {
	// https://www.youtube.com/watch?v=fhum63fAwrI www.youtube.com/watch?v=<videoid>
	// https://www.youtube.com/watch?v=i-szWOrc3Mo www.youtube.com/<channelname> (unsupported by cloudtube currently)
	// https://www.youtube.com/watch?v=LSG71wbKpbQ www.youtube.com/channel/<id>
	// https://www.youtube.com/watch?v=RiEkOKFOG3s youtu.be/<videoid> with params

	descriptionHtml = descriptionHtml.replace(new RegExp(`<a href="https?://(?:www\\.)?youtu\\.be/(${constants.regex.video_id})([^"]*)">([^<]+)</a>`, "g"), `<a href="/watch?v=$1$2">$3</a>`)
	descriptionHtml = descriptionHtml.replace(new RegExp(`<a href="https?://(?:www\\.)?youtu\\.be/(${constants.regex.video_id})[?]?([^"]*)">([^<]+)</a>`, "g"), (_, id, params, innerText) => {
		if (params != "") {
			return `<a href="/watch?v=${id}&${params}">${innerText}</a>`
		}
		return `<a href="/watch?v=${id}">${innerText}</a>`
	})
	descriptionHtml = descriptionHtml.replace(new RegExp(`<a href="https?://(?:www\\.)?youtu(?:\\.be|be\\.com)/([^"]*)">([^<]+)<\/a>`, "g"), `<a href="/$1">$2</a>`)
	descriptionHtml = descriptionHtml.replace(new RegExp(`(?:([0-9]*):)?([0-5]?[0-9]):([0-5][0-9])`, "g"), (_, hours, minutes, seconds) => {
		let timeURL, timeDisplay, timeSeconds
-- 
2.30.2
Could you give an example of a video fixed by this?
Thanks, patch applied. I like your implementation.