From ed59aeeeeb371d82b4619147c399015945a7fdee Mon Sep 17 00:00:00 2001 From: SuliacLEGUILLOU Date: Sat, 11 Jan 2020 15:07:23 +0100 Subject: Translate youtube channel and user URL into their feed (#612) Youtube rss system is hiden inside their api to encourage account creation. I have added a step to transform automaticaly a user or a channel url like `https://www.youtube.com/user/scilabus` into its feed url: `https://www.youtube.com/feeds/videos.xml?user=scilabus` Signed-off-by: s18alg --- js/controller/NavigationController.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/controller/NavigationController.js b/js/controller/NavigationController.js index e4306c9a8..1c66422d2 100644 --- a/js/controller/NavigationController.js +++ b/js/controller/NavigationController.js @@ -19,6 +19,7 @@ app.controller('NavigationController', function ($route, FEED_TYPE, FeedResource this.folderError = ''; this.renameError = ''; this.feed = {}; + this.youtubeDetectorRegex = new RegExp(/youtube\.[a-z\.]{2,}\/(user|channel)\/(.*?)(\/|\?|$)/); var getRouteId = function () { return parseInt($route.current.params.id, 10); @@ -187,6 +188,23 @@ app.controller('NavigationController', function ($route, FEED_TYPE, FeedResource // is closed or has no unread articles existingFolder.getsFeed = true; + /** + * Transform youtube channel and user URL into their RSS feed + * (09/01/2020): Youtube feed url work as `https://www.youtube.com/feeds/videos.xml?user=` + */ + var regResult = this.youtubeDetectorRegex.exec(feed.url); + /** + * At this point: + * regResult[0] contain the match + * regResult[1] contain the type of youtube entity (channel or user) + * regResult[2] contain either the username or the channel id + */ + if (regResult && regResult[0] && regResult[1] && regResult[2]) { + feed.url = 'https://www.youtube.com/feeds/videos.xml?'; + feed.url += (regResult[1] === 'user') ? 'user=' : 'channel_id='; + feed.url += regResult[2]; + } + FeedResource.create(feed.url, existingFolder.id, undefined, feed.user, feed.password).then(function (data) { Publisher.publishAll(data); -- cgit v1.2.3