/Spotify-Headless

Experimental wrapper for Spotify API to search songs and control the web player using the cli (Feat. Puppeteer)

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

Spotify-Headless

A CLI tool using puppeteer to intercept your own validated spotify OAuth token alongside of the session cookies, then reinject them to mimic an authorized, user-like traffic.

How it works

  1. Establish a session by authenticating to Spotify within a headless browser. (Puppeteer)
  2. Export the session cookies and store them locally, specifically the refresh token that will refresh the JWT every time it expires. (valid for one year)
  3. The access token allows you to perform special actions on behalf of a user.

Installation and configuration

git clone https://github.com/BelkaDev/Spotify-Headless ~/Spotify-Headless
cd ~/Spotify-Headless && npm install

To provide your credentials you need to set them as environement variables within your bashrc (or your default shell rc)

export SPOTIFY_USER=""
export SPOTIFY_PWD=""

Running

Manually grab your access token: node token.js
Other commands are found under /lib folder, they are examples of commands from the API with extra features (search, play/resume etc..)

Use case

The sole purpose is to combine aliases into automated and complex tasks, this can offer a lot of flexibility as shown below:

example 1 (Basic): : Browse Spotify catalog, filter items, feed STDOUT to queue.

example 1

example 2 (Advanced) : Store to a local playlist, shuffle songs, set a timer, transfer ongoing stream to your mobile device.

example 2

example 3 (Expert): : Convert Youtube playlist to a Spotify playlist.

example 1

Notes:

  • play.js reads input from stdin only, it works in pair with the search command.
  • transfer.js takes phone/mobile,computer/pc,browser as parameters, if the suggested device isn't opened, it sends the signal to the actual active device.
  • search.js will lookup for tracks by default, unlike other items (albums,playlists etc..), tracks can be stacked and enqueued at once, more details here. It takes album,artist,playlist as arguments.
  • snippets used in the examples can be found here

Todo:

  • Allow creating online playlists.
  • Refactor/clean code
  • Catch random/annoying error messages.