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.
For any questions, suggestions, or collaborations, feel free to reach out to me on Discord!
- Discord: envoy49 π¬
- Spotify Account is required to obtain
ClientId
andClientSecret
.
- Install Go version 1.21 or above https://go.dev/
- 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@<version>
After the installation is complete, open a new terminal and run go-spotify-cli --version
.
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
.
brew update
brew upgrade go-spotify-cli
brew uninstall go-spotify-cli
π§ͺ At the moment only go install
method is available although Homebrew can be tried.
More information can be found here: Winget CLI
Paste the following command into the PowerShell window to install Winget and press Enter:
winget install wingetcreate
Once Winget is installed, below steps are required for installation.
winget search go-spotify-cli
winget install Envoy49.go-spotify-cli
After the installation is complete, open a new terminal and run go-spotify-cli --version
.
winget upgrade Envoy49.go-spotify-cli
winget uninstall Envoy49.go-spotify-cli
Note π:
go-spotify-cli --version
command is hardcoded at this point until the issue with dynamic assignment is resolved.
To get started, you'll need a 'Client ID' and 'Client Secret' from Spotify's Developer Dashboard:
-
π Navigate to: Spotify Developer Dashboard
-
πͺ Sign in or create a Spotify account.
-
β Click on 'Create An App'.
-
π Fill in the app details.
-
β In the app settings, set your Redirect URIs. Ensure your CLI tool's callback URL is added. App won't work without redirect URLs.
-
π Authenticate with Spotify. In the Redirect URIs field of the app you created, please enter the following URLs:
- π
http://localhost:4949/user-modify-playback-state-auth-callback
- π
http://localhost:4949/user-read-playback-state-auth-callback
- π
http://localhost:4949/user-library-read-auth-callback
- π
-
π 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
andClientSecret
. - 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.
π 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.
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.
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.
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.
- 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
- 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.
This project is under the MIT License. Dive into the LICENSE
file for more.