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.
Go Spotify CLI is a command-line interface tool built with GoLang (v1.21) that interfaces with the Spotify Web API, enabling users to control playback, manage devices, search for tracks, and more directly from the terminal.
Key Features:
Control playback commands such as play, pause, next, and previous.
Adjust volume levels within a range of 0-100.
Search for tracks and episodes to add to the current queue.
Activate specific devices for playback.
Flush tokens or secrets to reset authentication when needed.
Audience & Benefit:
Ideal for users who prefer command-line tools for hands-free operation, efficient workflow, and direct access to Spotify functionality. This tool provides a powerful way to interact with Spotify without relying on graphical interfaces, offering flexibility and ease of use for managing music playback and device control.
README
π΅ 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.
Contact π¬
For any questions, suggestions, or collaborations, feel free to reach out to me on Discord!
Discord: envoy49 π¬
π Prerequisites
Spotify Account is required to obtain ClientId and ClientSecret.
To install latest version run the following command
go install github.com/envoy49/go-spotify-cli@latest
To install a specific version of go-spotify-cli, first obtain the release number from the Releases page. Then, use the following command in the terminal, replacing with the release number you obtained:
go install github.com/envoy49/go-spotify-cli@
After the installation is complete, open a new terminal and run go-spotify-cli --version.
Using Homebrew for π Mac
Brew package manager is required to install Go Spotify CLI. More information on steps to download brew can be found here: https://brew.sh/
Once brew is installed, below steps are required for installation.
brew tap Envoy49/homebrew-go-spotify-cli
brew install go-spotify-cli
After the installation is complete, open a new terminal and run go-spotify-cli --version.
π Once the App is created, you'll find the 'Client ID' and 'Client Secret' on the app details page.
π 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.
π« Remember: Keep your 'Client Secret and Client Id' confidential. Never share it! They are a key to control your Spotify data.
>Note: π If secrets entered are wrong although validation is in place, go-spotify-cli flush-secrets command can be used to delete saved secrets to start process again.
π 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 + ``
βΆοΈ play: Starts playback on the current device.
βΈοΈ pause: Pauses playback on the current device.
π± 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.