2.1.0 • Published 2 years ago
spotify-mini v2.1.0
spotify-mini
Simple Spotify client for nodejs exposing useful methods
I was using a basic version of this library on my website for a long time, which led me to transform it into a fully-fledged module.
Prerequisite
Make sure to create a refresh_token with atleast the following permissions enabled:
user-read-currently-playinguser-read-recently-playeduser-top-read
:bulb: You can use spotify-rtoken-cli to easily create a
refresh_tokenright from your terminal.
Installation
# Install with npm
npm install spotify-mini
# Install with yarn
yarn add spotify-mini
# Install with pnpm
pnpm add spotify-miniUsage
import { SpotifyClient } from 'spotify-mini'
const spotify = new SpotifyClient({
clientId: '<YOUR-SPOTIFY-CLIENT-ID>',
clientSecret: '<YOUR-SPOTIFY-CLIENT_SECRET>',
refreshToken: '<YOUR-SPOTIFY-REFRESH-TOKEN>'
})
// Get the currently playing track.
const currentlyPlayingTrack = await spotify.getCurrentTrack()
console.log(currentlyPlayingTrack)Example output:
{
isPlaying: true,
title: '<track title>',
artist: '<artist name>',
album: '<album name>',
}API
getCurrentTrack
Get the currently playing track.
| Options | Type | Description |
|---|---|---|
fallbackToLastPlayed | boolean | Returns the last played track, if there is no ongoing track atm. (default:true) |
getRecentTracks
Get the recently played tracks.
| Options | Type | Description |
|---|---|---|
limit | number (1 <= n <= 50) | Limit the number of recently played tracks to return. (default: 1) |
getTopTracks
Get the top tracks of the user.
| Options | Type | Description |
|---|---|---|
limit | number | Limit the number of recently played tracks to return. (Default: 10) |
timeRange | short, medium, long | Over what time range the top tracks should be calculated. (Default: short) |
Related
- spotify-rtoken-cli - Generate Spotify
refresh_tokenright from terminal
License
MIT License © Rocktim Saikia 2024