Browse Source

Fix (actually this time) youtube feature urls not being properly converted

master
benji7425 4 years ago
parent
commit
f25dae8e93
  1. 12
      app/models/feed-data.js

12
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;
}
Loading…
Cancel
Save