Skip to content

Instantly share code, notes, and snippets.

@miyagui
Created September 27, 2016 17:06
Show Gist options
  • Save miyagui/943185a60af080739983bb51a65a0aec to your computer and use it in GitHub Desktop.
Save miyagui/943185a60af080739983bb51a65a0aec to your computer and use it in GitHub Desktop.
Spotify lyrics on linux (bash)
#!/bin/bash
SP_DEST="org.mpris.MediaPlayer2.spotify"
SP_PATH="/org/mpris/MediaPlayer2"
SP_MEMB="org.mpris.MediaPlayer2.Player"
LyricsAPI="https://makeitpersonal.co/lyrics/?artist=&title="
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}"
@yudhadimas
Copy link

How to implement this code into my Linux desktop? Thanks 👍

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