diff --git a/lib/album.js b/lib/album.js index b530d0d..10ff0a3 100644 --- a/lib/album.js +++ b/lib/album.js @@ -25,6 +25,32 @@ Object.defineProperty(Album.prototype, 'uri', { configurable: true }); +/** + * Get an url for the cover image. + * + * @param {String} size image size + * @api public + */ + +Album.prototype.coverUrl = function (size) { + if (!size) { + size = 'DEFAULT'; + } + if (!this._spotify.sourceUrls[size]) { + throw new Error('Unknown cover size: ' + size); + } + if !(this.cover) { + return null; + } + var res = this.cover.filter(function (e) { + return (e.size === size); + }); + if (res.length > 0) { + return this._spotify.sourceUrls[size] + util.gid2id(res[0].fileId); + } + return null; +} + /** * Loads all the metadata for this Album instance. Useful for when you get an only * partially filled Album instance from an Album instance for example.