Socket
Book a DemoInstallSign in
Socket

simple-spotify

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-spotify

A simple spotify api for fetching songs and playlists

1.0.4
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

NPM downloads npm npm bundle size

A library for interacting with Spotify

Install

npm install simple-spotify

Usage

Require/ import

const { Spotify } = require('simple-spotify');
// or
import { Spotify } from 'simple-spotify';

// Create an instance of the Spotify class
const spotify = new Spotify();
// Specify special options
const spotify = new Spotify({
  /*
  * Here you can define the api endpoints which are used
  * Should only be necessary when Spotify changes it's API
  * and I neglect to update this package
  */
});

Playlist


// await can only be used in an async functions
const playlist = await spotify.playlist('https://open.spotify.com/playlist/0vvXsWCC9xrXsKd4FyS8kM?si=c809d19fc04440af');
// or
/* 
* The seconds argument is to fetch 'all' tracks from this playlist
* Spotify only returns 100 tracks as a maximum, so to get all tracks
* you will have to collect them by 'GET'-requesting more links
*/
const playlist = await spotify.playlist('0vvXsWCC9xrXsKd4FyS8kM', true);

// Use songs
for (const item of playlist.tracks.items) {
  const song = item.track;
  console.log(song.name);
  console.log(song.artists[0].name);
}

Album

const album = await spotify.album('https://open.spotify.com/album/3iTOoFTl3JWm4jZx9sK7R8');
// or
const album = await spotify.album('0vvXsWCC93iTOoFTl3JWm4jZx9sK7R8xrXsKd4FyS8kM');

// get songs
const songs = await album.tracks(true); // <- true for all tracks (default: true)
for (const song of songs) {
  console.log(song.name);
  console.log(song.artists[0].name);
}

Track

const track = await spotify.track('https://open.spotify.com/track/3KriJcc1OwpynDFQtzGNZN');
// or
const track = await spotify.track('3KriJcc1OwpynDFQtzGNZN');

console.log(track.name);
console.log(track.artists[0].name);

Keywords

spotify

FAQs

Package last updated on 30 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.