Skip to content

Instantly share code, notes, and snippets.

@tupton
Created January 16, 2011 21:33
Show Gist options
  • Save tupton/782165 to your computer and use it in GitHub Desktop.
Save tupton/782165 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
@tupton
Copy link
Author

tupton commented Jan 16, 2011

An example eventcmd script for posting pianobar events to Last.fm with Scrobbular

Back up ~/.config/pianobar/eventcmd, then put this script in its place. Now playing and scrobbles will be posted to Last.fm through Scrobbular.

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