Merge pull request #850 from lorenzhs/spotify-embeds

Spotify: also match other types of embeds (playlists and artists)
This commit is contained in:
Tor Hveem 2016-11-11 12:54:29 +01:00 committed by GitHub
commit 635f556510
2 changed files with 16 additions and 9 deletions

View file

@ -181,22 +181,25 @@ plugins.factory('userPlugins', function() {
*
*/
var spotifyPlugin = new Plugin('Spotify track', function(message) {
var spotifyPlugin = new Plugin('Spotify music', function(message) {
var content = [];
var addMatch = function(match) {
for (var i = 0; match && i < match.length; i++) {
var id = match[i].substr(match[i].length - 22, match[i].length);
var element = angular.element('<iframe></iframe>')
.attr('src', '//embed.spotify.com/?uri=spotify:track:' + id)
.attr('width', '300')
.attr('src', '//embed.spotify.com/?uri=' + match[i])
.attr('width', '350')
.attr('height', '80')
.attr('frameborder', '0')
.attr('allowtransparency', 'true');
content.push(element.prop('outerHTML'));
}
};
addMatch(message.match(/spotify:track:([a-zA-Z-0-9]{22})/g));
addMatch(message.match(/open\.spotify\.com\/track\/([a-zA-Z-0-9]{22})/g));
addMatch(message.match(/spotify:track:[a-zA-Z-0-9]{22}/g));
addMatch(message.match(/spotify:artist:[a-zA-Z-0-9]{22}/g));
addMatch(message.match(/spotify:user:\w+:playlist:[a-zA-Z-0-9]{22}/g));
addMatch(message.match(/open\.spotify\.com\/track\/[a-zA-Z-0-9]{22}/g));
addMatch(message.match(/open\.spotify\.com\/artist\/[a-zA-Z-0-9]{22}/g));
addMatch(message.match(/open\.spotify\.com\/user\/\w+\/playlist\/[a-zA-Z-0-9]{22}/g));
return content;
});

View file

@ -29,12 +29,16 @@ describe('filter', function() {
$provide.value('version', 'TEST_VER');
}));
it('should recognize spotify tracks', inject(function(plugins) {
it('should recognize spotify links', inject(function(plugins) {
expectTheseMessagesToContain([
'spotify:track:6JEK0CvvjDjjMUBFoXShNZ',
'https://open.spotify.com/track/6JEK0CvvjDjjMUBFoXShNZ'
'spotify:user:lorenzhs:playlist:18aXdzQ4Ar1p019OSICtu4',
'spotify:artist:0L5fC7Ogm2YwgqVCRcF1bT',
'https://open.spotify.com/track/6JEK0CvvjDjjMUBFoXShNZ',
'https://open.spotify.com/user/lorenzhs/playlist/18aXdzQ4Ar1p019OSICtu4',
'https://open.spotify.com/artist/0L5fC7Ogm2YwgqVCRcF1bT'
],
'Spotify track',
'Spotify music',
plugins);
}));