Skip to content

Instantly share code, notes, and snippets.

@richleland
Forked from tupton/eventcmd
Created June 10, 2011 14:47
Show Gist options
  • Save richleland/1018977 to your computer and use it in GitHub Desktop.
Save richleland/1018977 to your computer and use it in GitHub Desktop.
An example eventcmd script for posting pianobar events to Last.fm with Scrobbular.
#!/bin/bash
# create variables
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\)=' /dev/stdin) # don't overwrite $1...
username='<YOUR GOOGLE USERNAME>';
secret='<YOUR SCROBBULAR SECRET>';
case "$1" in
songfinish)
# scrobble if 75% of the song has been played but only if the song hasn't been banned
if [ -n "$songDuration" ] &&
[ $(echo "scale=4; ($songPlayed/$songDuration*100)>50" | bc) -eq 1 ] &&
[ "$rating" -ne 2 ]; then
curl -X POST --data-urlencode "username=$username" \
--data-urlencode "s=$secret" \
--data-urlencode "track=$title" \
--data-urlencode "artist=$artist" \
--data-urlencode "duration=$((songDuration/1000))" \
--data-urlencode "album=$album" \
http://scrobbular.appspot.com/scrobble
fi;
;;
songstart)
curl -X POST --data-urlencode "username=$username" \
--data-urlencode "s=$secret" \
--data-urlencode "track=$title" \
--data-urlencode "artist=$artist" \
--data-urlencode "album=$album" \
http://scrobbular.appspot.com/now_playing
;;
esac
@richleland
Copy link
Author

You also need to chmod +x the eventcmd file and add the following to your ~/.config/pianobar/config file:

event_command = /Users/rleland/.config/pianobar/eventcmd

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