Created
February 9, 2011 16:07
-
-
Save alampros/818717 to your computer and use it in GitHub Desktop.
Pieced together a bunch of scripts out there for improving pianobar.
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 | |
# 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\|coverArt\)=' /dev/stdin) | |
case "$1" in | |
# React when the song changes | |
songstart) | |
# Since $rating is a number, we translate it into a heart if the user likes the song or | |
# not. | |
if [ $rating -eq 1 ] | |
then | |
heart="<3" | |
else | |
heart="" | |
fi | |
# This makes sure the directory for storing the album art exists | |
if [ ! -d ~/.config/pianobar/art ] | |
then | |
mkdir ~/.config/pianobar/art | |
fi | |
if [ ! -d ~/.config/pianobar/art_archive ] | |
then | |
mkdir ~/.config/pianobar/art_archive | |
fi | |
# Change to the album art directory | |
cd ~/.config/pianobar/art | |
# Get rid of any existing album art, but don't complain if there isn't any | |
# ...actually i kinda want to accumulate it... | |
# rm * 2> /dev/null | |
mv * ~/.config/pianobar/art_archive 2> /dev/null | |
# $coverArt is a URL pointing to the album art, so download it | |
wget -q "$coverArt" | |
# Finally, show the notification with the title, artist, album name, heart icon, and | |
# album art image. We set the identifier (with the -d switch) to make all of the | |
# notifications show in one bubble. | |
echo "\"$title\" by \"$artist\" on \"$album\" $heart" | growlnotify -n "pianobar" --image * -d 12 pianobar | |
;; | |
songfinish) | |
# scrobble if 75% of song have 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 | |
# scrobbler-helper is part of the Audio::Scrobble package at cpan | |
# "pia" is the last.fm client identifier of "pianobar", don't use | |
# it for anything else, please | |
scrobbler-helper -P pia -V 1.0 "$title" "$artist" "$album" "" "" "" "$((songDuration/1000))" & | |
fi | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment