Click to See Complete Forum and Search --> : What's wrong with this?


Fryguy8
10-22-2002, 10:31 AM
Hi guys, I'm trying to generate a file that follows the following template:

CD_DA

CD_TEXT
{
LANGUAGE_MAP
{
0 : EN
}

LANGUAGE 0
{
TITLE "CD TITLE"
PERFORMER "Performer"
}
}

TRACK AUDIO
CD_TEXT
{
LANGUAGE 0
{
TITLE "Track Title"
PERFORMER "Performer"
}
}
FILE "track1.wav"

TRACK AUDIO
CD_TEXT
{
LANGUAGE 0
{
TITLE "Track Title"
PERFORMER "Performer"
}
}
FILE "track2.wav"


With The TITLE, PERFORMER fields being changed.
Here is the script I've got going so far.

#/bin/sh

echo "CD_DA" &> cd.toc
echo "CD_TEXT{LANGUAGE_MAP{0 : EN}}" &> cd.toc

for I in *.mp3
do
$A=`mp3info -p "%t" $I`
$B=`mp3info -p "%s" $I`

#echo 'TRACK_AUDIO \n CD_TEXT{LANGUAGE 0{ TITLE "$A" \n PERFORMER "$B"}}\n FILE "$I"\n' &> cd.toc
done


I commented out the last echo line because I was having problems with $A and $B, which store the TITLE and PERFORMER Entries. Does anybody have any ideas that will work?

Also, after I get this working, I want to be able to check and see if all the mp3s that are going to be parsed have the same album name, and if they do to write that to the file in another CD_TEXT block (above all the TRACK_AUDIO blocks), and if they don't all match (if it's from a mix CD for instance), to prompt the user (me), for a Title for the CD.

uptimenotifier
10-22-2002, 01:41 PM
To get you started, see this code. Your main loop probably needs to read a directory listing and your variable assignments should be cleaned up. Also printf might be helpful here. Be sure to append your stdout when appropriate.

echo "CD_DA" > cd.toc
echo "CD_TEXT{LANGUAGE_MAP{0 : EN}}" >> cd.toc

for I in $(ls -1 *.mp3)
do
A=`mp3info -p "%t" $I`
B=`mp3info -p "%s" $I`
printf "TRACK_AUDIO \n CD_TEXT{LANGUAGE 0{ TITLE $A \n PERFORMER $B}}\n FILE $I\n" >> cd.toc
done

Fryguy8
10-22-2002, 02:02 PM
Ok I've got this working so far, and it's outputting how I want.

Next thing I want to do is to check to see if the files in the directory have a common Album Name, and to make sure that album name isn't null. If they don't share an album name, or if the album name is null, then I want to prompt the user (me), for another entry. How would I go about doing this?

edit: make the assumption that mp3info can determine the album name (it can), and also make the assumption that these id3 tags are kept in perfect order by me (easytag is a great program btw for doing this)

mingshun
10-22-2002, 02:36 PM
Originally posted by Fryguy8


Next thing I want to do is to check to see if the files in the directory have a common Album Name, and to make sure that album name isn't null.


Use awk.
(This is untested and prone to bugs.)

awk '{
/TITLE/ {
arr[$2]++
if (arr [$2] > 2) printf "%s is not unique\n", arr [2]
}
}'


If they don't share an album name, or if the album name is null, then I want to prompt the user (me), for another entry. How would I go about doing this?


I don't know what do you mean (coz its 2am here :p) but you can use the read command for stdin.

Fryguy8
10-22-2002, 02:49 PM
Actually I was thinking more along the lines of having a second loop go ahead of the current loop, read through all of the albums and compare them..