Please look at my earlier post for install and configuring Pianobar.
I’m going to setup mac osx notification center to get notification of now playing song which will include Title, Artist and Album. Let’s go back to the Pianobar config
file and add event_command as below. What we are doing here? get info from Pianobar of every event and run the specified script. In this case on every event it’s going launch the base script eventcommand.sh
event_command = /Users/yourusername/.config/pianobar/eventcommand.sh
Let’s create the file
touch ~/.config/pianobar/eventcommand.sh
nano ~/.config/pianobar/eventcommand.sh
Copy and the following in the editor and save it.
#!/bin/bash fold="$HOME/.config/pianobar" ctlf="$fold/ctl" nowplaying="$fold/lyrics.sh" while read L; do k="`echo "$L" | cut -d '=' -f 1`" v="`echo "$L" | cut -d '=' -f 2`" export "$k=$v" done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|songDuration\|songPlayed\|coverArt\|stationCount\|station[0-9]\+\)=' /dev/stdin) case "$1" in songstart) /usr/bin/terminal-notifier -subtitle "Artist: $artist" -message "Album: $album" -title "$title" ;; esac
Make it executable
cd ~/.config/pianobar && chmod +x eventcommand.sh && mkfifo ctl
We have configured to get the notification but not yet lyrics. Move on further if you need lyrics.
Get lyrics
It’s hard to get lyrics directly from Pandora as I think that their API doesn’t support lyrics, but people wrote HTML extractor to get lyrics which can be found here. But I’m going to use glyr to do this job.
I followed the wiki page to compile glyr
. I’ll walk the through steps that I worked well. You need to install libintl
from here then follow the steps below.
In my case MacPorts always works
sudo port install sqlite3
install cmake
brew install glib
or do with Homebrew.
brew install sqlite3
brew link --force sqlite
brew install cmake
brew install glib
Download glyr from here and extract it.
cd glyr
cmake -DCMAKE_INSTALL_PREFIX=/usr .
make && sudo make install
Now you can launch glyr with glyrc
and update eventcommand.sh
file with the following which includes the above notification.
#!/bin/bash
fold="$HOME/.config/pianobar" ctlf="$fold/ctl" nowplaying="$fold/lyrics.sh" while read L; do k="`echo "$L" | cut -d '=' -f 1`" v="`echo "$L" | cut -d '=' -f 2`" export "$k=$v" done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|songDuration\|songPlayed\|coverArt\|stationCount\|station[0-9]\+\)=' /dev/stdin) case "$1" in songstart) echo -e "glyrc lyrics -a \"$artist\" -t \"$title\" -b \"$album\" -w /tmp/" > "$nowplaying" /usr/bin/terminal-notifier -subtitle "Artist: $artist" -message "Album: $album" -title "$title" ;; esac
The above script writes out put as lyrics.sh on every event i.e., when ever new song plays. If you want to look at the lyrics of the “Now Playing Song” then open a new tap in your terminal and run the following.
sh ~/.config/pianobar/lyrics.sh
We all done.