Created
September 26, 2019 04:35
-
-
Save BharatKalluri/fccc24ccddecedf67e69bae4d3e963b6 to your computer and use it in GitHub Desktop.
Get lyrics in bash
This file contains 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 | |
# Thanks @glutanimate ! | |
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 -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