Never Perfectly Managed

    spotify-mini
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    spotify-mini

    GitHub Workflow Status (branch) npm

    Simple Spotify client for nodejs exposing useful methods

    I have been using a rough version of this lib in my portfolio from a long time. So decided to turn it into a proper module.


    Prerequisite

    Make sure to create a refresh token with atleast these permissions enabled user-read-currently-playing, user-read-recently-played, user-top-read. You can use spotify-rtoken-cli to easily create a refresh_token right from your terminal.


    Installation

    yarn add spotify-mini

    Usage

    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,(if there is no track playing, it will return the last played track)
    const currentlyPlayingTrack = await spotify.getCurrentTrack()
    /**
     {
        isPlaying: true,
        title: '<track title>',
        artist: '<artist name>',
        album: '<album name>',
     }
    */
    
    // Get the most recently played tracks in order, default return limit is 1
    const lastPlayedTracks = await spotify.getRecentTracks(2)
    /**
     [
       {
          title: '<track title>',
          artist: '<artist name>',
          album: '<album name>',
       },
       {
          title: '<track title>',
          artist: '<artist name>',
          album: '<album name>',
       }
     ]
    */
    
    // Get your most played tracks, see API doc below for available options
    const topRecentTracks = await spotify.getTopTracks()
    const topOverallTracks = await spotify.getTopTracks({ timeRange: 'long' })

    API

    getCurrentTrack

    Options Type Description
    fallbackToLastPlayed boolean Returns the last played track, if there is no ongoing track atm. (default:true)

    getRecentTracks

    Options Type Description
    limit number (1 <= n <= 50) Limit the number of recently played tracks to return. (default: 1)

    getTopTracks

    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

    License

    MIT License © Rocktim Saikia 2022

    Install

    npm i spotify-mini

    DownloadsWeekly Downloads

    1

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    12 kB

    Total Files

    7

    Last publish

    Collaborators

    • rocktimsaikia