Spotify: also match other types of embeds (playlists and artists)
This commit is contained in:
parent
71d2cefce1
commit
7ba8ba202e
2 changed files with 16 additions and 9 deletions
|
@ -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 content = [];
|
||||||
var addMatch = function(match) {
|
var addMatch = function(match) {
|
||||||
for (var i = 0; match && i < match.length; i++) {
|
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>')
|
var element = angular.element('<iframe></iframe>')
|
||||||
.attr('src', '//embed.spotify.com/?uri=spotify:track:' + id)
|
.attr('src', '//embed.spotify.com/?uri=' + match[i])
|
||||||
.attr('width', '300')
|
.attr('width', '350')
|
||||||
.attr('height', '80')
|
.attr('height', '80')
|
||||||
.attr('frameborder', '0')
|
.attr('frameborder', '0')
|
||||||
.attr('allowtransparency', 'true');
|
.attr('allowtransparency', 'true');
|
||||||
content.push(element.prop('outerHTML'));
|
content.push(element.prop('outerHTML'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
addMatch(message.match(/spotify:track:([a-zA-Z-0-9]{22})/g));
|
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: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;
|
return content;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,16 @@ describe('filter', function() {
|
||||||
$provide.value('version', 'TEST_VER');
|
$provide.value('version', 'TEST_VER');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should recognize spotify tracks', inject(function(plugins) {
|
it('should recognize spotify links', inject(function(plugins) {
|
||||||
expectTheseMessagesToContain([
|
expectTheseMessagesToContain([
|
||||||
'spotify:track:6JEK0CvvjDjjMUBFoXShNZ',
|
'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);
|
plugins);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue