From f25dae8e93950b4bf5377bfa25ff70d4b37751c6 Mon Sep 17 00:00:00 2001 From: benji7425 Date: Wed, 20 Sep 2017 00:43:59 +0100 Subject: [PATCH] Fix (actually this time) youtube feature urls not being properly converted --- app/models/feed-data.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/feed-data.js b/app/models/feed-data.js index 0cd4338..9afe706 100644 --- a/app/models/feed-data.js +++ b/app/models/feed-data.js @@ -80,10 +80,14 @@ module.exports = class FeedData { function normaliseUrl(url) { url = url.replace("https://", "http://"); //hacky way to treat http and https the same - if (Url.parse(url).host.startsWith("http://youtu")) - url = url.split("?")[0]; //quick way to chop off stuff like ?feature=youtube - - url = url.replace(/(www.)?youtube.com\/watch\?v=/, "youtu.be/"); //convert youtube full url to short + const parsedUrl = Url.parse(url); + if (parsedUrl.host.includes("youtube.com")) { + const videoIDParam = parsedUrl.query.split("&").find(x => x.startsWith("v=")); + if (videoIDParam) { + const videoID = videoIDParam.substring(videoIDParam.indexOf("=") + 1, videoIDParam.length); + url = "http://youtu.be/" + videoID; + } + } return url; } \ No newline at end of file