Skip to content

Commit

Permalink
Translate youtube channel and user URL into their feed (#612)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
s18alg authored and Grotax committed Jan 11, 2020
1 parent 3625283 commit ed59aee
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions js/controller/NavigationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit ed59aee

Please sign in to comment.