hnarayanan/shpotify

Status command to return the player status

anomitra opened this issue · 7 comments

This is pretty self-explanatory - it'd be nice if I had something like spotify status player which returns either PLAYING, PAUSED or STOPPED. Think of it as mirroring the play button's status on a music player.

The motivation behind this is that I'm using shpotify to display the player status on my terminal prompt. I'm okay with taking a stab at implementing this if the maintainers are on-board.

Please try implementing it.

spotify status already outputs that information (playing or paused), in addition to artist, album, track, and position. So you could pull playing or paused from the current spotify status command output. For example:

$ spotify status
Spotify is currently playing.
Artist: The White Stripes
Album: Elephant
Track: Ball And Biscuit
Position: 3:30 / 7:19

and grabbing just the part we're interested in:

$ spotify status | grep -o 'paused\|playing'
playing

As a side note, I would be careful about adding too much to the prompt only because it can slow things down if your prompt is constantly trying to pull extraneous information. There's a noticeable difference when I'm in a folder and my prompt provides the git branch info...

That is a possible way to go about it, but as you mentioned it would slow down the prompt considering it retrieves a lot of data that I won't really use. I added a command in #127 which is around 5x faster than doing spotify status - good enough for using in a prompt.

Yes, it's definitely possible for me to add that line of code to my prompt. But I still think it's a good-to-have functionality for the library. A lot of Oh-My-Zsh users (like me) use shpotify and it'd be cool if they can leverage this feature for their own prompts.

This turned out to be extremely easy to implement!

Oh wait - @anomitra already did it. But have a look: there's a bit of DRYing that can be done, since a number of different functions are checking the player state.