Skip to content

Instantly share code, notes, and snippets.

@Who23
Last active November 25, 2022 00:40
Show Gist options
  • Save Who23/9e1a74c0291cc5179d45dabae4814d18 to your computer and use it in GitHub Desktop.
Save Who23/9e1a74c0291cc5179d45dabae4814d18 to your computer and use it in GitHub Desktop.
statify: a status script for spotify showing art and track info in the terminal
#!/bin/bash
# Who23 Github
# A script to display current spotify track info in a small terminal window
# this includes art, track name, and artist. All art/text centered
# BUILT TO WORK WITH MACOS, iTERM, & SPA (https://gist.github.com/Who23/8ff45f0f2c2c3ae8a95582178a5c92ec)
# for linux:
# iTerm is needed for the image display protocol, can work with another terminal if you change the image protocol to one
# supported by that terminal
#
# statify can use sp, but the commands will need to be swapped from spa -> relevent sp commands
# Copyright 2020 Aditya Shrivastava
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# width in columns of the terminal window
WIDTH=27
prev_info="\n"
# shhh
printf "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
while true;
do
# polls spa every 10 secs to see if the track has changed
if [[ $prev_info != $(spa info) ]]
then
# move the cursor and draw the track art
printf "\033[200D\033[8A"
b=$(curl -s $(spa art) | base64)
printf "\033[$((WIDTH / 4))C\033]1337;File=inline=1;width=auto;height=7"
printf ":$b"
printf "\a\n\033[23D"
# get the track/artist & get how many spaces needed to center the text
track_name="$(spa name | cut -c -$((WIDTH - 2)))"
artist_name="$(spa artist | cut -c -$((WIDTH - 2)))"
track=${#track_name}
artist=${#artist_name}
track=$((WIDTH - track))
artist=$((WIDTH - artist))
track=$((track / 2))
artist=$((artist / 2))
# print the centered track name
printf "\033[2K"
for i in $(eval echo "{1..$track}"); do printf ' '; done
printf "$track_name\n"
# print the centered artist name
printf "\033[2K"
for j in $(eval echo "{1..$artist}"); do printf ' '; done
printf "$artist_name"
prev_info=$(spa info)
fi
sleep 10
done
@MegatronNX123
Copy link

MegatronNX123 commented Jun 15, 2021

So if i have the Spotify app on my macOS it will display what song i am currently listening to where? The terminal?

@Who23
Copy link
Author

Who23 commented Jun 18, 2021

yup! this script requires iterm2 for displaying the song cover art. just execute the script and you'll get a little 'now playing' thing in your terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment