diff options
author | SuliacLEGUILLOU <suliac.leguillou@pm.me> | 2020-01-11 15:07:23 +0100 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-01-11 15:07:23 +0100 |
commit | ed59aeeeeb371d82b4619147c399015945a7fdee (patch) | |
tree | ce43f03351061f20905f9910a18adf96b4b39e99 | |
parent | 3625283de05b401e16280c010defee24aca58cd9 (diff) |
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 <s18alg@protonmail.com>
-rw-r--r-- | js/controller/NavigationController.js | 18 |
1 files changed, 18 insertions, 0 deletions
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=<username>` + */ + 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); |