Software Developer

Wednesday, March 25, 2009

my small last.fm script

it's a pity that lastfm is not going to be free anymore but still... here is my small script that i usually use to listen to last.fm:


#!/usr/bin/env bash
# shell-fm helper
#* lastfm://user/${user}/loved
#* lastfm://user/${user}/personal
#* lastfm://usertags/${user}/${usertag}
#* lastfm://artist/${artist}/similarartists
#* lastfm://artist/${artist}/fans
#* lastfm://globaltags/${globaltag}
killall -9 shell-fm

function usage() {
printf "Usage: %s: [-u username] [[-p(ersonal)] [-l(oved)]] [-g globaltag] [-a artist]\n" $(basename $0) >&2
}

command="lastfm:/"
artflag=
while getopts 'u:plg:a' OPTION

do
case $OPTION in
u) command="$command/user/$OPTARG"
;;
l) command="$command/loved"
break
;;
p) command="$command/personal"
break
;;
a) artflag=1
command="$command/artist/$artist"
break
;;
?) usage
exit 2
;;
esac
done


#printf "Remaining arguments are: %s\n" "$*"

shift $(($OPTIND - 1))
rest=""
if [ $artflag ]
then
while [ $# -ge 1 ]; do
if [ "$rest" != "" ]; then
rest="$rest+"
fi
rest="$rest${1}"
shift
done
fi

shell-fm -d $command$rest


(In order to use you need to install also a small "shell-fm" application.)

and now awesome ...

here it is: