๐ŸŽธ foolproof wrapper to stream what you're currently listening to

Overview

A lightweight Spotify API wrapper that allows you to display the music you're currently listening to ๐ŸŽธ ๐ŸŽบ

๐Ÿ–Š Getting started

โช Prerequisites

  1. Create an application in the Spotify Developer Dashboard
    • Click on the Edit settings button
    • Set the Redirect URIs to a convenient location (doesn't matter)
    • Save the given Client ID along with the Client Secret
  2. Retrieve the access code
    • Visit the following URL after replacing $CLIENT_ID, $SCOPE, and $REDIRECT_URI

        https://accounts.spotify.com/authorize?response_type=code&client_id=$CLIENT_ID&scope=$SCOPE&redirect_uri=$REDIRECT_URI 
    • You can choose scope(s) by visiting the Spotify API docs

  3. Note code from the URL you were redirected to
  4. Acquire your refresh token
    • Run the following CURL command

        curl -X POST https://accounts.spotify.com/api/token -d "client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&grant_type=authorization_code&code=$CODE&redirect_uri=$REDIRECT_URI"
    • Either replace or export the variables in your shell ($CILENT_ID, $CLIENT_SECRET, $CODE, and $REDIRECT_URI)

  5. Save refresh_token for later

๐Ÿ“š Installation

npm ๐Ÿป

npm i spotify-now-playing --save-dev

or yarn ๐Ÿงถ

yarn add spotify-now-playing --dev


๐Ÿ‘จโ€๐Ÿ’ป Usage

import { SpotifyService } from 'spotify-now-playing'

const Example = async () => {
    const spotify = new SpotifyService(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN)
    const song = await spotify.getCurrentSong()

    if(!song.isPlaying) {
        return console.log('not listening to anything')
    }
    
    console.log(`Listening to **${song.title}** by ${song.artist.name}`)
}

You can also use the library in frameworks such as Next or React ๐Ÿ‘‡

/api/spotify.ts

// Use of backend is strongly advised as it hides internal requests that include your access token.

import { NextApiRequest, NextApiResponse } from 'next'
import { SpotifyService } from 'spotify-now-playing'

export default async function(req: NextApiRequest, res: NextApiResponse) {
    const spotify = new SpotifyService(CLIENT_ID!, CLIENT_SECRET!, REFRESH_TOKEN!)
    const song = await spotify.getCurrentSong()

    res.json(song)
}

index.tsx

export default function() {
    var { data: song } = useSWR('/api/spotify', fetcher, {
        refreshInterval: 5 * 1000,
        fallbackData: 'loading',
    })

    if(song.title && !song.isPlaying) {
        return <p>Not listening to anything</p>
    }

    return(
        <div>
            <img src={ song.album?.image || 'https://cdn.albert.lol/964d7fc6' } width='150px' height='150px' />
            
            <p>Listening to <b>{ song.title }</b> by { song.artist?.name || 'unknown' }</p>

            <p>Album: { song.album?.name }</p>
            <p>Release: { song.album?.releaseDate }</p>
        </div>
    )
}

Implementation of the library in Next.js can be found by clicking here


You might also like...

Easiest medium to use buttons with any discord API wrapper

Easiest medium to use buttons with any discord API wrapper

Discord Buttons Plugin Easiest medium to use buttons with any discord API wrapper /* Generate 1st Button with "Yes" lable on it */ const button1

May 14, 2022

A wrapper for @discordjs/voice

ezvoice A lightweight package designed to make it just a bit easier to play and record sound with @discordjs/voice Discord: nab138#2035 Examples Conne

May 19, 2022

Springlink - โ™จ๏ธ springlink, a lightweight, fast, highly customizable and stable lavalink wrapper for Node.js ๐ŸŸฉ

SpringLink โ™จ๏ธ A lightweight, fast and stable lavalink wrapper for Node.js Features ๐ŸŒน Stable Feature-rich Customizable Lightweight Installation ๐Ÿฎ (No

Nov 17, 2022

A lavalink wrapper in Node.js

Vulkava A lavalink wrapper in Node.JS Documentation Common errors/Issues ๐Ÿ”Œ Installation You will need NodeJS v14+ and a running lavalink server. Offi

Dec 17, 2022

Featureful selfbot wrapper for its Discord selfbot

Featureful selfbot wrapper for its Discord selfbot

Featureful Selfbot wrapper for its Discord Selfbot. This library provides non-standard stuff such farming, intervals, and respect the ratelimit.

Nov 30, 2022

spotify.ts is an wrapper built around Spotify's Web API

spotify.ts About spotify.ts is an wrapper built around Spotify's Web API. Features Fast Object Oriented Typescript, ESM, CJS support Easy to Use Insta

Nov 17, 2022

Unofficial javascript wrapper to WhatsApp Cloud API.

heyooh Unofficial javascript wrapper to WhatsApp Cloud API. Its the javascript port for heyoo Features supported Sending messages Sending Media (image

Dec 30, 2022

The node.js v18 API wrapper for discordlist.gg

About This is an unofficial discordlist.gg package written for Typecript and JavaScript to interact with its public API. If you need help using this p

Dec 13, 2022

now-playing: A website to show what I'm currently listening to on Spotify Run on Repl.it

 now-playing: A website to show what I'm currently listening to on Spotify Run on Repl.it

now-playing: A website to show what I'm currently listening to on Spotify โ“ How does it work? This project is split into two parts - the frontend and

Apr 29, 2022

A group listening chat app that utilizes the spotify api to enable the users to queue, pause, change songs, as well as chat with each other

Next.js + Tailwind CSS Example This example shows how to use Tailwind CSS (v3.0) with Next.js. It follows the steps outlined in the official Tailwind

Dec 19, 2021

Project Cider. A new look into listening and enjoying Apple Music in style and performance. ๐Ÿš€

Project Cider. A new look into listening and enjoying Apple Music in style and performance. ๐Ÿš€

Links Wiki Request Feature Report Bug View The Releases Install Sources Compiling and Configuration For more information surrounding configuration, co

Jan 5, 2023

Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total contributions.

Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total contributions.

Remoklify - Gitlift Discord Bot Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total

Mar 20, 2022

A BetterDiscord plugin for showing what you're listening from Last.fm.

A BetterDiscord plugin for showing what you're listening from Last.fm.

LastFMRichPresence BetterDiscord Plugin This plugin allows you to show what you're listening via Last.fm. You can set it up for Soundcloud, Youtube Mu

Dec 16, 2022

A simple command line interface for listening to Quran.

Quran-CLI A simple command line interface for listening to Quran. Used API We are using the mp3quran api. Dependencies Install mpv as it is required f

Nov 18, 2022

App that leverages GPT-3 to facilitate new language listening and speaking practice.

App that leverages GPT-3 to facilitate new language listening and speaking practice.

Talk w/GPT-3 app: Getting started The Talk w/GPT-3 application was developed by James L. Weaver (the author of this document) to get more new language

Jan 1, 2023

Keep the type of storage value unchanged and change array and object directly. Supports listening to the changes and setting expires.

proxy-web-storage A more convenient way to use storage through proxy. try it on codesandbox. Install npm i proxy-web-storage Features Base Keep the ty

Dec 25, 2022

A tiny, SSR-friendly hook for listening to gamepad events.

useGamepadEvents useGamepadEvents is a tiny, SSR-friendly hook for listening to gamepad events. It's a wrapper around the Gamepad API designed for fir

Oct 2, 2022

Lightweight WebSocketServer wrapper lib using ws-wrapper to wrap connected WebSockets

ws-server-wrapper Lightweight WebSocketServer wrapper lib using ws-wrapper and ws to wrap connected WebSockets. The only dependency is ws-wrapper itse

May 9, 2022

A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.

SoundJS SoundJS is a library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers, inclu

Dec 31, 2022
Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total contributions.

Remoklify - Gitlift Discord Bot Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total

Remoklify 3 Mar 20, 2022
A BetterDiscord plugin for showing what you're listening from Last.fm.

LastFMRichPresence BetterDiscord Plugin This plugin allows you to show what you're listening via Last.fm. You can set it up for Soundcloud, Youtube Mu

dimden 9 Dec 16, 2022
A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.

SoundJS SoundJS is a library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers, inclu

CreateJS 4.3k Dec 31, 2022
update your twitter banner with the song you're currently playing on Spotify

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Dunsin 4 Oct 17, 2022
Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC technology

Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC technology

Alex X 742 Jan 4, 2023
Simple example script that receives the signal from one iptv channel and relays it via websocket to another server to replicate the stream to multiple players

Simple example script that receives the signal from one iptv channel and relays it via websocket to another server to replicate the stream to multiple players

Ericky Thierry 3 Feb 20, 2022
Swaps video ads for an ad-free stream.

VideoAdBlockForTwitch This video adblock for Twitch extension will swap Twitch video ads for an ad-free version of the stream at 480p and then automat

cleanlock 1.5k Jan 2, 2023
HTML5 fmp4 live stream (ll-fmp4) player written in TypeScript

umataste HTML5 fmp4 live stream (ll-fmp4) player written in TypeScript Feature Playback for fmp4 stream Extremely low latency of less than 0.1 second

ใ‚‚ใซใ‚‡๏ฝžใ‚“ 5 Oct 21, 2022
Automatically stream lo-fi hiphop at system startup on the Lofipi

Lofipi-mpv This runs as a system service on Raspberry Pi inside my "lofipi" speaker to automatically stream music from YouTube playlists on startup. F

Nicholas Sherlock 38 Nov 15, 2022
Audio visualizer library for javascript. Create dynamic animations that react to an audio file or audio stream.

Wave.js Audio visualizer library for javascript. Installation Install With CDN <script src="https://cdn.jsdelivr.net/gh/foobar404/wave.js/dist/bundle.

Austin Michaud ฮป 497 Dec 21, 2022