# simple-spotify

> A simple spotify api for fetching songs and playlists

Latest version **1.0.4** (published 2021-06-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install simple-spotify
pnpm add simple-spotify
yarn add simple-spotify
bun add simple-spotify
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-06-30 |
| First published | 2021-06-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Hubble34 |
| Maintainers | hubble34 |
| Keywords | spotify, simple spotify, api, spotify api |

## Links

- npm: https://www.npmjs.com/package/simple-spotify
- Repository: https://github.com/hubble459/simple-spotify
- Homepage: https://github.com/hubble459/simple-spotify#readme
- Issues: https://github.com/hubble459/simple-spotify/issues
- npm.io page: https://npm.io/package/simple-spotify

## Dependencies (1)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1

## Recent versions

- 1.0.4 (latest) — 2021-06-30
- 1.0.3 — 2021-06-28
- 1.0.2 — 2021-06-23
- 1.0.1 — 2021-06-21
- 1.0.0 — 2021-06-21

## README

<div align="center">
  <br />
  <p>
    <a href="https://www.npmjs.com/package/simple-spotify"><img src="https://img.shields.io/npm/dt/simple-spotify.svg?maxAge=3600" alt="NPM downloads" /></a>
    <a href="https://www.npmjs.com/package/simple-spotify"><img alt="npm" src="https://img.shields.io/npm/v/simple-spotify"></a>
    <a href="https://www.npmjs.com/package/simple-spotify"><img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/simple-spotify"></a>
  </p>
</div>

# A library for interacting with [Spotify](https://spotify.com)
## Install
```
npm install simple-spotify
```
## Usage
### Require/ import
```js
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
```js

// 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
```js
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
```js
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);
```

---
_Source: https://npm.io/package/simple-spotify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
