Fix full and short youtube urls not correctly being converted

This commit is contained in:
benji7425 2017-09-12 23:50:03 +01:00
parent e8d99e5691
commit e78b6539bb
1 changed files with 4 additions and 4 deletions

View File

@ -78,12 +78,12 @@ module.exports = class FeedData {
};
function normaliseUrl(url) {
url = url.replace("https://", "http://"); //cheaty way to get around http and https not matching
url = url.replace("https://", "http://"); //hacky way to treat http and https the same
if (Url.parse(url).host.includes("youtu")) //detect youtu.be and youtube.com - yes I know it's hacky
url = url.split("&")[0]; //quick way to chop off stuff like &feature=youtube
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/"); //turn full url into share url
url = url.replace(/(www.)?youtube.com\/watch\?v=/, "youtu.be/"); //convert youtube full url to short
return url;
}