#!/bin/sh

# Create symlinks in $mp3dir that point into $fiddir with (hopefully) good names

fiddir=./fids/
mp3dir=./mp3/

if [ ! -d $mp3dir ];
then
	mkdir -p $mp3dir
fi

for fid in `find $fiddir -type f -name "*1" -print | sed -e 's/^\.\///'`
do
	type=`cat $fid | grep type= | cut -d= -f2`
	if [ "x$type" = "xtune" ];
	then
		dat=`echo $fid | sed -e 's/1$//'`0
		title=`cat $fid | grep title= | cut -d= -f2`
		filename="$title"
		artist=`cat $fid | grep artist= | cut -d= -f2`
		if [ "x$artist" != "x" ]
		then
			filename="$artist - $filename"
		fi
		filename=$mp3dir/`echo $filename | tr '/' '_'`.mp3
		echo "$fid - $title"
		if [ -h "$filename" ];
		then
			rm -f "$filename"
		fi
		ln -s ../$dat "$filename"
	else
		echo "skipping playlist $fid"
	fi
done
