Skip to content

Instantly share code, notes, and snippets.

@FdelMazo
Forked from jgamblin/slackspotify.sh
Last active April 17, 2020 12:08
Show Gist options
  • Save FdelMazo/6cb9d3c7c33212a675080c91d8b133f6 to your computer and use it in GitHub Desktop.
Save FdelMazo/6cb9d3c7c33212a675080c91d8b133f6 to your computer and use it in GitHub Desktop.
A Script For Ubuntu To Set Current Spotify Song As Slack Status
#!/bin/bash
APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens"
while true
# https://gist.github.com/derblub/823d9ba5876a011fc004
STATUS=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|egrep -A 1 "string"|cut -b 26-|cut -d '"' -f 1|egrep -v ^$)
ARTIST=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$)
SONG=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$)
URLSONG=$(echo "$SONG | $ARTIST" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
do
if [[ "$STATUS" != "Playing" ]]; then
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22%22%2C%22status_emoji%22%3A%22%22%7D" > /dev/null
else
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22"$URLSONG"%22%2C%22status_emoji%22%3A%22%3Amusical_note%3A%22%7D" > /dev/null
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment