Skip to content

Latest commit

 

History

History
596 lines (574 loc) · 13.5 KB

project.org

File metadata and controls

596 lines (574 loc) · 13.5 KB

cl-spotify

About

This is a library for connecting to the Spotify Web API.

It handles OAuth authentication/authorization (including automatic refresh), scope handling (right now only add-scope), JSON deserialization, and provides functions for making get, post, and put requests.

It also includes some higher level functions (play, pause, etc.) to show how the library can be used.

For more information, see project.org

License

ISC

Copyright (c) 2020 Jeremiah LaRocco <jeremiah_larocco@fastmail.com>

Using

Get The Code

This library is not in QuickLisp yet, and also depends on modifications I’ve made to st-json, and my own j-utils library. To get started, clone the following repos into your Lisp local projects directory:

git clone https://github.com/jl2/cl-spotify
git clone https://github.com/jl2/st-json
git clone https://github.com/jl2/j-utils

The modifications I’ve made to st-json require jq to be installed (for pretty printing):

sudo apt-get install jq

Attain a Client ID and secret

Connecting to the Spotify API requires a Client ID and secret from Spotify, which you can get from Spotify’s Developer Dashboard.

cl-spotify reads the client ID and secret from a file. The default location is (asdf:system-relative-pathname :cl-spotify “.spotify-client”), which is the file “.spotify-client” in the cl-spotify package directory. The file location can be changed by setting the special variable cl-spotify::*client-file*.

The .spotify-client file should have the following format:

{
    "client_id": "your client ID",
    "client_secret": "your client secret"
}

Connecting

Once the client ID and secret are configured, it’s time to connect:

(ql:quickload :cl-spotify)
(defparameter *spotify* (cls:connect :scope '(:user-modify-playback-state :user-read-playback-state)))

This should bring up a web browser asking you to allow the cl-spotify to access your Spotify account. If you accept the request, you will be redirected to a page asking you to close the browser window, and cl-spotify will receive the authorization information in the background.

After this, you can begin making requests to the Spotify API:

(ql:quickload :cl-spotify)
(defparameter *spotify* (cls:connect :scope '(:user-modify-playback-state :user-read-playback-state)))
(cls:pause *spotify*)
(cls:play *spotify*)
(cls:now-playing *spotify*)