#!/bin/bash
shopt -s lastpipe;
grep $1 relative.m3u | while read line ;
do      # foreach file in playlist that matches dir
	echo $line | xargs -d'\n' ./title.sh | read title; # get title
	if [ -z "$title" ]; then
	  #echo "title was empty";
	  continue;
	fi
	title="${title// /_}.mp3"; # replace space with underscore, mp3
	# output resulting mv statement - directly running was too error prone
	if [ "$line" != "$1$title" ]; then
		echo "mv \"$line\" \"$1$title\""; # move from old name to same dir, but new title
	fi

done

