#! /bin/sh
# Shell script to get informations about the current song playing in Audacious

#Audacious is launched ?
STATUS=$(audtool playback-status)
VERSION=$(audtool get-version)

# if that fails, then check for the new audacious 1.5.0 way
if [ $? -ne 0 ]
then
	VERSION=$(audtool version)
fi
	
if [ $? = 0 ]
then
	echo $STATUS
	MAJ=`expr substr ${VERSION#A*\ } 1 1`
	MIN=`expr substr ${VERSION#A*\ } 3 1`

	if [  "$MAJ" -eq "1" -a "$MIN" -ge "4" ] || [ "$MAJ" -gt "1" ] 
	then
		#To force \n when there isn't any information
		#echo $(audtool current-song-tuple-data title)
		#echo $(audtool current-song-tuple-data artist) 
		title=$(audtool current-song-tuple-data title)
		artist=$(audtool current-song-tuple-data artist) 
	else
		#To force \n when there isn't any information
		title=$(audtool current-song-tuple-data track_name)
		title=$(audtool current-song-tuple-data performer)
	fi
	file=$(audtool current-song-filename)

	# oops, 'seems that the file doesn't have ID3 data, falling back to the song name
	if [ -z "$title" -o -z "$artist" ]
	then
		title=$(audtool current-song)
	fi
	echo $title
	# $artist returns nothing if ID3 data is missing
	echo $artist
	echo $file
else
	echo 0
fi

exit 0
