Skip to content

A simple Spotify CLI primarily made for monitoring what songs you're listening to and displaying that in your bar of choice like waybar or polybar.

License

Notifications You must be signed in to change notification settings

AndreasBackx/spotifatius

Repository files navigation

Spotifatius

Spotify + status + some Latin = Spotifatius.

A simple Spotify CLI primarily made for monitoring what songs you're listening to and displaying that in your bar of choice like waybar or polybar.

Usage

First make sure the RSPOTIFY_CLIENT_ID and RSPOTIFY_CLIENT_SECRET environment variables are available in your shell environment. They need to contain the Spotify developer Client ID and secret. Follow Spotify's Developer Documentation on how to set that up, make sure the redirect URI is set to http://localhost. Once done, run spotifatius monitor once to setup Spotify access tokens:

$ spotifatius monitor
Opened https://accounts.spotify.com/authorize?[...] in your browser.
Please enter the URL you were redirected to:
[INSERT URL HERE]
{"text":"Twenty One Pilots - Bounce Man","tooltip":"Scaled And Icy","class":["playing"]}

From then on, this step will no longer be required. You can then add spotifatius monitor to your favourite bar, see Bar Integration. The first invocation of this command will start a server that is required by other commands. If there is already a server running, it will mirror the output from said server, this is useful if you want the monitoring to show on multiple displays.

To toggle the liked state anywhere, use toggle-liked.

$ spotifatius toggle-liked
Added to library!

That will update the monitoring server/client:

{"text":"Added to library!","class":["added"]}
{"text":"Twenty One Pilots + Bounce Man","tooltip":"Scaled And Icy","class":["liked","playing"]}

Doing that again will remove the liked state:

$ spotifatius toggle-liked
Removed from library!
{"text":"Removed from library!","class":["removed"]}
{"text":"Twenty One Pilots - Bounce Man","tooltip":"Scaled And Icy","class":["playing"]}

By default, liked songs also have a + instead of a - between the artist and song title.

Bar Integration

Here are some configuration examples for the supported bars.

Waybar

Add the following to make it available as a module:

"custom/spotify": {
    "format": "{}",
    "return-type": "json",
    "on-click-right": "spotifatius toggle-liked",
    "exec": "spotifatius monitor"
}

The following classes are supported:

  • playing: the current song is playing.
  • paused: the current song is paused.
  • stopped: the current song is stopped.
  • liked: the current song is in your liked songs.
  • added: there's a message being displayed saying the song was just added to your liked songs.
  • removed: there's a message being displayed saying the song was just removed to your liked songs.

Polybar

[module/spotify]
type = custom/script
exec = spotifatius monitor --output-type polybar
tail = true
click-right = spotifatius toggle-liked

config.toml options

format

🗒 Note: These formatting options are not yet final and might change in upcoming versions. They won't be considered breaking changes as a result, though a minor version bump will be done if this changes. More info.

The JSON output can be formatted using the format var in config.toml:

Example 1:

format = "{status} {title} {separator} {artist}" # {"text":"  Bounce Man + Twenty One Pilots","tooltip":"Scaled And Icy","class":["liked", "playing"]}

Example 2:

format = "{artist} -- {title}" # {"text":"Twenty One Pilots -- Bounce Man","tooltip":"Scaled And Icy","class":["liked", "playing"]}

Default format is {artist} {separator} {title}

Available options:

Name Function
{status} Unicode symbol for playing/paused track
{title} Current track title
{artist} Current track artist
{separator} + if current track is a liked song, - if not

polybar

Polybar maps the classes from the waybar output to colors that you can define in your config file ~/.config/spotifatius/config.toml:

[polybar]
[polybar.colors]
# added = ""
# liked = ""
paused = "#6E6E6E"
playing = "#CECECE"
# removed = ""

By default there are no colors set for polybar.

Some example output:

$ spotifatius monitor --output-type polybar
# Output for playing unliked song.
%{F#CECECE}Twenty One Pilots - Bounce Man%{F-}
# Output for playing liked song.
%{F#CECECE}Twenty One Pilots + Bounce Man%{F-}
# Output for paused liked song.
%{F#6E6E6E}Twenty One Pilots + Bounce Man%{F-}

Server/Client via gRPC

Spotifatius' monitor command will be default because a gRPC server that is streaming monitor updates, see proto/service.proto. If a monitor instance detects the port is already used by another monitor instance, it will start listening over gRPC so all instances are in sync. As of writing, closing the server instance will also close the client.

Installation

If you would like spotifatius to be available on your distro's package manager, feel free to make an issue if you have some time to help.

Arch User Repository (AUR)

paru -S spotifatius

Cargo (crates.io)

cargo install spotifatius --locked

Manually

git clone git@github.com:AndreasBackx/spotifatius.git
cd spotifatius
cargo install --path . --locked

Logging

Pass RUST_LOG with either trace, debug, info, warn, or error to set the logging level, default is error. See tracing-subcriber documentation for more info.

About

A simple Spotify CLI primarily made for monitoring what songs you're listening to and displaying that in your bar of choice like waybar or polybar.

Topics

Resources

License

Stars

Watchers

Forks