#!/bin/sh

if [ "$1" != "" ] ; then

suffix=${1##*.}

if [ "$suffix" = "mp3" ] ; then
	echo "it's a 'mp3' file"
	mpc add $1
else                        
	#Fake useragent
	alias wget='wget -U "Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7"'

	#Download parse and add to mpd
	#result=$(wget -q $1 -O-)
	#echo "$result"

	if [ "$suffix" = "pls" ] ; then
		echo "it's a 'pls' file"
		wget -q $1 -O- | grep "File1=" | sed -e 's/^File[1]*=//' | tr -d "\r" | mpc add
	elif [ "$suffix" = "m3u" ] ; then
		echo "it's a 'm3u' file"
		wget -q $1 -O- | cat | xargs -r mpc add
	else
		echo "file suffix not know, try it anyway"
		mpc add $1
	fi
fi

else
	echo "USAGE: mpc_add http://www.example.com/file.mp3"
	echo "USAGE: can add url to .mp3 .m3u .pls"
fi

