diff --git a/js/plugins.js b/js/plugins.js index 18d92ce..4bdb710 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -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('') - .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; }); diff --git a/test/unit/plugins.js b/test/unit/plugins.js index 8842f05..c723a7e 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -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); }));