spotify-library

Get your Spotify library via CLI

Usage no npm install needed!

<script type="module">
  import spotifyLibrary from 'https://cdn.skypack.dev/spotify-library';
</script>

README

Spotify Library

npm GitHub Workflow Status (branch) codecov

Export your Spotify library to JSON

You will need an access token from Spotify. There are multiple ways to get a token:

  1. Go to http://spotify-starter.nougat.dev/ and login with Spotify. Then, copy the access token that is displayed. This is a demo Spotify app I made for a different project and is save to use - the data only lives in your browser and is not saved anywhere. The page is open-source.

  2. Create your own Spotify application for free and use it to get an access token. Create a new app on https://developer.spotify.com/dashboard/applications (or reuse one). Then, grab your Spotify app client secret and client id and get your token via CLI as described here. Note that you will need at least the authorization scopes "user-library-read".

Also be aware that Spotify authentication tokens expire after 1h.

CLI

npx spotify-library@latest --token <your-spotify-token>

This will download your Spotify library in a light format to the current working directory. Pass in different options to download the full library (all properties) and/or get the derived track genres and audio features as well.

Options

Flag (required?) Description, [opts?]
--token ✅ Spotify authentication token
--type ❌ Track format. Options: full | light. Defaults to light
--genres ❌ Appends derived artist genres to saved tracks. Not included by default
--features ❌ Appends audio features to saved tracks. Not included by default
--outDir ❌ Custom output directory relative to where the script is run

Usage

# light track output
npx spotify-library@latest --token 123token
# full track output
npx spotify-library@latest --type full --genres --features  --outDir spotify-data --token 123token

A light track has a reduced set of properties:

type TrackLight = {
  id: string;
  name: string;
  album: {
    name: string;
    id: string;
  };
  artists: {
    id: string;
    name: string;
  }[];
};

The full has all the track properties from the Spotify API.

Example outputs: