Created
July 29, 2019 09:15
-
-
Save ntavish/08265ff1baf5808240d1e2da65028fd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SP_DEST="org.mpris.MediaPlayer2.spotify" | |
SP_PATH="/org/mpris/MediaPlayer2" | |
SP_MEMB="org.mpris.MediaPlayer2.Player" | |
LyricsAPI="http://makeitpersonal.co/lyrics/" | |
SPOTIFY_METADATA="$(dbus-send \ | |
--print-reply `# We need the reply.` \ | |
--dest=$SP_DEST \ | |
$SP_PATH \ | |
org.freedesktop.DBus.Properties.Get \ | |
string:"$SP_MEMB" string:'Metadata' \ | |
| grep -Ev "^method" `# Ignore the first line.` \ | |
| grep -Eo '("(.*)")|(\b[0-9][a-zA-Z0-9.]*\b)' `# Filter interesting fiels.`\ | |
| sed -E '2~2 a|' `# Mark odd fields.` \ | |
| tr -d '\n' `# Remove all newlines.` \ | |
| sed -E 's/\|/\n/g' `# Restore newlines.` \ | |
| sed -E 's/(xesam:)|(mpris:)//' `# Remove ns prefixes.` \ | |
| sed -E 's/^"//' `# Strip leading...` \ | |
| sed -E 's/"$//' `# ...and trailing quotes.` \ | |
| sed -E 's/\"+/|/' `# Regard "" as seperator.` \ | |
| sed -E 's/ +/ /g' `# Merge consecutive spaces.`\ | |
)" | |
TrackArtist=$(echo "$SPOTIFY_METADATA" | sed -n 's/artist|//p') | |
TrackTitle=$(echo "$SPOTIFY_METADATA" | sed -n 's/title|//p') | |
curl -L -s --get "$LyricsAPI" --data-urlencode "artist=${TrackArtist}" --data-urlencode "title=${TrackTitle}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment