exports.listAlbums = function(req, res) {

    var artistId = req.param('artistId');
    logger.info('Getting details of the album for artist id: ' + artistId);
    if (artistId) {

        logger.debug('On Page: ' + req.query.currentPage);
        // Search albums of artists
        var offsetCalculated = 0;
        var currentPage = 1;
        if (req.query.currentPage) {
            currentPage = req.query.currentPage;
        }
        if (Number(currentPage) !== 1) {
            offsetCalculated = ((currentPage - 1) * 10) + 1;
        }

        // Get albums by a certain artist
        spotifyApi.getArtistAlbums(artistId, {
                limit: 10,
                offset: offsetCalculated
            })
            .then(function(data) {
                logger.debug('Artist albums', data);
                res.jsonp(data);
            }, function(err) {
                logger.error(err);
            });

    }

};
示例#2
0
文件: index.js 项目: amarcher/cesura
async function main_p() {

    let artistAlbums = await spotifyApi.getArtistAlbums('0ybFZ2Ab08V8hueghSXm6E')

    console.log(artistAlbums.body.items.length)
    artistAlbums.body.items.forEach(function(albums) {
        console.log(albums.name)
    })

}
示例#3
0
          data.body.artists.items.forEach((artist, i) => {

              // if songkick name is spotify name
              if (Name == artist.name) {
                foundName = true
                const Artist = new ArtistModel();
                console.log(`${++Spotify_searchArtists} adding ${Name}`)


                Artist.songKickID = songKickID
                Artist.spotifyURL = artist.external_urls.spotify
                Artist.id = artist.id
                Artist.name = artist.name
                Artist.images = artist.images
                Artist.img = artist.images.length ? artist.images[1].url : "http://assets.audiomack.com/default-artist-image.jpg"
                Artist.popularity = artist.popularity
                Artist.followers = artist.followers.total

                // Add Top Tracks
                spotifyApi.getArtistTopTracks(artist.id, "US").then(data => {
                  Artist.topTracks = data.body.tracks.map(track => {
                    return {
                      preview_url: track.preview_url,
                      popularity: track.popularity,
                      name: track.name,
                      id: track.id
                    }
                  })

                }).catch(err => console.log(err))

                // Add Alubm cover images
                spotifyApi.getArtistAlbums(artist.id).then(data => {
                  Artist.albumsImages = data.body.items.map(album => {
                    return {
                      images: album.images,
                      name: album.name
                    }
                  })
                }).catch(err => console.log(err))

                // Add Bio
                lastFM.getInfo(Name.toString()).then(data => {
                  if (data && data.artist) {
                    Artist.lastFM_imgs = data.artist.image
                    Artist.summaryBio = data.artist.bio.summary
                    Artist.fullBio = data.artist.bio.content
                    Artist.onTour = data.artist.ontour
                    Artist.genre = data.artist.tags.tag
                    Artist.relatedArtists = data.artist.similar
                  }
                }).catch(err => console.log("ERROR: lastFM.getInfo"))

                // give API calls 2 secs
                setTimeout(function() {
                  Artist.save(function(err) {
                    if (err) return console.log(err);
                  });
                  //cachedArtists[songKickID] = Artist
                  resolve(Artist)
                }, 2000)
                //cachedArtists[songKickID] = Artist
              }
            })
示例#4
0
//wrapper.js

// Write cmd below in terminal to install node
//npm install spotify-web-api-node --save

var SpotifyWebApi = require('spotify-web-api-node');

// credentials are optional
var spotifyApi = new SpotifyWebApi({
  clientId : '93ba9aeed2e94c22a2c9a7cb4aff6fa8',
  clientSecret : '7b4ccf4a65e445e4b4aeb25f84c7b195',
  redirectUri : 'http://localhost:8888/callback'
});

// Access Token Authorization here
//spotifyApi.setAccessToken('<your_access_token>');

// Get Elvis' albums
spotifyApi.getArtistAlbums('43ZHCT0cAZBISjO8DG9PnE')
  .then(function(data) {
    console.log('Artist albums', data.body);
  }, function(err) {
    console.error(err);
  });