π΅ Go Spotify CLI
Go Spotify CLI is a command-line interface tool built with GoLang (v1.21) that interfaces with the Spotify Web API, allowing users to control playback, manage devices, and more.
π Prerequisites
- Spotify Account is required to obtain
ClientId
and ClientSecret
.
β¬οΈ Installation
π Mac
, π§ Linux
, πͺ Windows
Note: π Previous installation methods using Homebrew and Winget have been phased out in favor of the more direct go install
method.
To install go-spotify-cli
, follow these steps:
go install github.com/envoy49/go-spotify-cli@latest
After the installation is complete, open a new terminal and run any command.
Note π: go-spotify-cli --version
command is not available yet and will be added soon.
π§ Configuration
Before using the Go Spotify CLI:
-
Obtain Credentials:
- Visit the Spotify Developer Dashboard.
- Log in and create a new app.
- Once the app is created, you can retrieve the
ClientId
and ClientSecret
from the dashboard of the created application.
-
Input Credentials:
- Execute any command using the Go Spotify CLI.
- On first execution, there will be a prompt asking you to enter the
ClientId
and ClientSecret
.
- After entering these details, they will be saved in the
.go-spotify-cli
folder in the root directory for future use.
Note: π If secrets entered are wrong although validation is in place, flush-secrets
can be used to delete saved secrets.
π Authentication
π On the first run, Go Spotify CLI will initiate an authentication process through the Spotify interface.
A browser window will open, requesting access grant. Once access is granted, Spotify will issue a 1-hour auth token along with a refresh token.
The refresh token will be used to obtain a new token after the original token has expired.
This ensures that browser authentication is no longer required after initial access has been granted.
Note: π Tokens are stored in the .go-spotify-cli
folder of root directory.
π Commands usage
Type go-spotify-cli
+ <command>
βΆοΈ play
: Starts playback on the current device.
βΈοΈ pause
: Pauses playback on the current device.
β© next
: Skips to the next track.
βͺ previous
: Returns to the previous track.
π volume
: Adjusts volume (0-100). Usage: example: volume -v=80
.
π± device
: Activates a specific device from provided options. E.g. laptop, tablet, phone etc.
πΎ saved
: Prints a list of saved tracks and allows to play selected track.
π search
: Search any Tracks
and Episodes
. Searching Artists
, Albums
, Playlists
, Shows
are not available yet. Any selected song from search result will be added to the current queue.
π flush-tokens
: This command will delete all token saved in .go-spotify-cli
folder. Further commands will require a new browser authentication.
π flush-secrets
: This command will delete all secrets saved in .go-spotify-cli
folder.
Note: πTo make executing commands more convenient, aliases can be utilized.
π Endpoints
The CLI communicates with the following Spotify API Endpoints:
/v1/me/player/play
/v1/me/player/pause
/v1/me/player/next
/v1/me/player/previous
/v1/me/player/volume
/v1/me/player/devices
/v1/me/tracks
Note: π More endpoints and functionality will be added once this project gains 25 stars.
Repo gained more stars than expected, so adding new functionality will be prioritised.
π€ Contributing
Your contributions light up our world! π Feel free to submit pull requests or raise issues.
There are still a lot of endpoints which can be implemented and a lot of room for improvement.
π» Local Development
- Install Go version 1.21 or above https://go.dev/
- Clone repo
- Run
go mod tidy
- Follow
Configuration
steps mentioned above
- Now commands can be executed from root directory e.g.
go run main.go play
π TODO List
- Add search options for
Artists
, Albums
, Playlists
, Shows
.
- Add tests(use race flag to detect race conditions).
- Add more commands reflecting Spotify Api.
- Clean up global variables.
- Get rid of constants, common folders and refactor code.
π License
This project is under the MIT License. Dive into the LICENSE
file for more.