npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-spotify-api

v1.1.1

Published

A javascript wrapper for Spotify's Web API

Downloads

5

Readme

JS Spotify API

docs travis build codecov coverage Maintainability downloads node version MIT Licence

NPM

A javascript wrapper for Spotify's Web API.

Browser Support

| Chrome | Firefox | Safari | Opera | Edge | IE | | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | | 67+ ✔ | 52+ ✔ | 16+ ✔ | 54+ ✔ | 16+ ✔ | 11 ✔ |

Table of Contents

Features

The library includes helper functions to do the following:

Note: Most of them are still in progress to make (sections marked with TODO)

Music metadata

  • Albums, artists, and tracks
  • Audio features and analysis for tracks (todo)
  • Albums for a specific artist todo
  • Top tracks for a specific artist todo
  • Artists similar to a specific artist todo

Profiles todo

  • User's emails, product type, display name, birthdate, image

Search

  • albums
  • artists, tracks, and playlists (todo)

Playlist manipulation (todo)

  • Get a user's playlists
  • Create playlists
  • Change playlist details
  • Add tracks to a playlist
  • Remove tracks from a playlist
  • Replace tracks in a playlist
  • Reorder tracks in a playlist

Your Music library (todo)

  • Add, remove, and get tracks and albums that are in the signed in user's Your Music library
  • Check if a track or album is in the signed in user's Your Music library

Personalization (todo)

  • Get a user’s top artists and tracks based on calculated affinity

Browse (todo)

  • Get New Releases
  • Get Featured Playlists
  • Get a List of Categories
  • Get a Category
  • Get a Category's Playlists
  • Get recommendations based on seeds
  • Get available genre seeds

Follow (todo)

  • Follow and unfollow users
  • Follow and unfollow artists
  • Check if the logged in user follows a user or artist
  • Follow a playlist
  • Unfollow a playlist
  • Get followed artists
  • Check if users are following a Playlist

Player (todo)

  • Get a user's available devices
  • Get information about the user's current playback
  • Get current user’s recently played tracks
  • Transfer a user's playback
  • Resume a user's playback
  • Skip a user's playback to next track
  • Skip a user's playback to previous track
  • Set a user's shuffle mode
  • Set a user's repeat mode
  • Set volume
  • Seek playback to a given position

All methods require authentication, which can be done using these flows:

Dependencies

  • To use this library you will need a node version >= 6.0.0.

  • Download one of the follows Node Version Managers to manage the node versions easily:

Installation

From npm

$ npm i -S js-spotify-api

From git

    $ git clone https://github.com/rubengomex/js-spotify-api.git
    $ cd js-spotify-api
    $ npm i

Tests

You can run the tests by running the follow command:

    $ npm t

Note: You only can run the tests if you clone the repository from github

Usage

ES6

// to import a specific method
import Spotify from 'js-spotify-api'

const spotify = new Spotify({
  token: 'YOUR_TOKEN_HERE'
})

// using  method
spotify.getArtists({ band: 'Incubus' }).then(artists => console.log(artists))

CommonJS

const Spotify = require('js-spotify-api')

const spotify = new Spotify({
  token: 'YOUR_TOKEN_HERE'
})

UMD in Browser

<!-- to import non-minified version -->
<script src="js-spotify-api.umd.js"></script>

<!-- to import minified version -->
<script src="js-spotify-api.umd.min.js"></script>

After that the library will be available to the Global as Spotify. Follow an example:

const spotify = new Spotify({
  token: 'YOUR_TOKEN_HERE'
})

let albums
spotify
  .getAlbums({ artist: 'Chosen artist' })
  .then(albumsFromArtists => (albums = albumsFromArtists))
  .catch(err => console.log(err))

console.log(albums)

// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
  try {
    const response = await spotify.getAlbums({ artists: 'Chosen artist' })
    console.log(response)
  } catch (error) {
    console.error(error)
  }
}

NOTE: async/await is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers, so use with caution.

API

Table of Contents

Spotify

Parameters

  • opts object Specifies the options for spotify class
    • opts.token string Specifies the spotify token to use

Meta

getAlbums

Gets albums info based on albums ids specified

Parameters
  • opts object Specifies the options object
    • opts.ids Array<string> Specifies the spotify albums ids
Examples
Albums
[{
   album_type: 'album',
   artists: [ [Object] ],
   available_markets: ['AD', 'EC', 'PT', ...],
   copyrights: [ [Object] ],
   external_ids: { upc: '886445352382' },
   external_urls: { spotify: 'https://open.spotify.com/album/{albumId}'}
   ...
}]

Returns Promise<Array<object>> The albums information

getAlbum

Gets album info based on the id of the album

Parameters
  • opts object Specifies the options object
    • opts.id string Specifies the spotify album id
Examples
Album
{
   album_type: 'album',
   artists: [ [Object] ],
   available_markets: ['AD', 'EC', 'PT', ...],
   copyrights: [ [Object] ],
   external_ids: { upc: '886445352382' },
   external_urls: { spotify: 'https://open.spotify.com/album/{albumId}'}
   ...
}

Returns Promise<object> The album information

getAlbumTracks

Gets the tracks of the album info based on the id of the album

Parameters
  • opts object Specifies the options object
    • opts.id string Specifies the spotify album id
    • opts.skip number Specifies the offset of the items to retrieve (optional, default 0)
    • opts.limit number Specifies the limit of items to retrieve (optional, default 20)
Examples
Tracks
[{
   artists: [ [Object] ],
   available_markets: ['AD', 'EC', 'PT', ...],
   copyrights: [ [Object] ],
   disc_number: 1,
   track_number: 1
   ...
}]

Returns Promise<Array<object>> The album tracks information

Development

See something you think can be improved? Please open an issue for that 😎